0

I'm creating my custom Field extending the clasic JFormField like this:

class JFormFieldExtension extends JFormField {

protected $type = 'extension';

// Constructor
public function __construct(\Joomla\CMS\Form\Form $form = null) 
{
    parent::__construct($form);

    JLog::add('************** JFormFieldExtension *****************', JLog::INFO, 'my_comp');
    JLog::add('* CONSTRUCT ====>'.$this->element['name'].'<=====', JLog::INFO, 'my_comp');
}

public function getInput() 
{

    JLog::add('************** JFormFieldExtension *****************', JLog::INFO, 'my_comp');
    JLog::add('* getInput ====>'.$this->element['name'].'<=====', JLog::INFO, 'my_comp');
}

With this code above, I get the following output:

2021-12-27T20:53:48+00:00   INFO 172.18.0.1 my_comp ************** JFormFieldExtension *****************
2021-12-27T20:53:48+00:00   INFO 172.18.0.1 my_comp * CONSTRUCT ====><=====
2021-12-27T20:53:48+00:00   INFO 172.18.0.1 my_comp ************** JFormFieldExtension *****************
2021-12-27T20:53:48+00:00   INFO 172.18.0.1 my_comp * getInput ====>field_name<=====

Question is: Why I get the $this->element['name'] inside the getInput() function, but not inside the __construct() ?

1 Answer 1

1

element property is set in field's setup() method. It's normally called by the form. But if you're using the field as a standalone class, you can call it manually.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.