Jump to content

Edit History

sylvainlepetit

sylvainlepetit


translate french comment to english

I use this trick to insert my field exactly where I want:

public function hookAdditionalCustomerFormFields($params)
    {
        // your new field
        $rpps_field = (new FormField)
            ->setName('my_new_field')
            ->setType('text')
            //->setRequired(true) //Uncomment to set it mandatory
            ->setLabel($this->l('Label for the new field'));
		// insert the field into other fields, I choose to put it after teh birthday date
        $params['fields'] = $this->array_insert_after($params['fields'], 'birthday', ['rpps_id'=>$rpps_field]);
        // return empty array because the new field already added with current fields
        return [];
    }

    function array_insert_after( array $array, $key, array $new ) {
        $keys = array_keys( $array );
        $index = array_search( $key, $keys );
        $pos = false === $index ? count( $array ) : $index + 1;
    
        return array_merge( array_slice( $array, 0, $pos ), $new, array_slice( $array, $pos ) );
    }

 

sylvainlepetit

sylvainlepetit

I use this trick to insert my field exactly where I want:

public function hookAdditionalCustomerFormFields($params)
    {
        // your new field
        $rpps_field = (new FormField)
            ->setName('my_new_field')
            ->setType('text')
            ->setRequired(true) //Décommenter pour rendre obligatoire
            ->setLabel($this->l('Label for the new field'));
		// insert the field into other fields, I choose to put it after teh birthday date
        $params['fields'] = $this->array_insert_after($params['fields'], 'birthday', ['rpps_id'=>$rpps_field]);
        // return empty array because the new field already added with current fields
        return [];
    }

    function array_insert_after( array $array, $key, array $new ) {
        $keys = array_keys( $array );
        $index = array_search( $key, $keys );
        $pos = false === $index ? count( $array ) : $index + 1;
    
        return array_merge( array_slice( $array, 0, $pos ), $new, array_slice( $array, $pos ) );
    }

 

sylvainlepetit

sylvainlepetit

I use this trick to insert my field exactly where I want:

public function hookAdditionalCustomerFormFields($params)
    {
        // your new field
        $rpps_field = (new FormField)
            ->setName('my_new_field')
            ->setType('text')
            ->setRequired(true) //Décommenter pour rendre obligatoire
            ->setLabel($this->l('Label for the new field'));
		// insert the field into other fields
        $params['fields'] = $this->array_insert_after($params['fields'], 'birthday', ['rpps_id'=>$rpps_field]);
        // return empty array because the new field already added with current fields
        return [];
    }

    function array_insert_after( array $array, $key, array $new ) {
        $keys = array_keys( $array );
        $index = array_search( $key, $keys );
        $pos = false === $index ? count( $array ) : $index + 1;
    
        return array_merge( array_slice( $array, 0, $pos ), $new, array_slice( $array, $pos ) );
    }

 

×
×
  • Create New...