Back to FormController class

Method __construct

public
__construct
(mixed $config = array(), \Joomla\CMS\MVC\Factory\MVCFactoryInterface $factory = null, ?\Joomla\CMS\Application\CMSApplication $app = null, ?\Joomla\Input\Input $input = null, \Joomla\CMS\Form\FormFactoryInterface $formFactory = null)
Constructor.
Parameters
  • array $config An optional associative array of configuration settings. Recognized key values include 'name', 'default_task', 'model_path', and 'view_path' (this list is not meant to be comprehensive).
  • \Joomla\CMS\MVC\Factory\MVCFactoryInterface $factory The factory.
  • \Joomla\CMS\Application\CMSApplication $app The Application for the dispatcher
  • \Joomla\Input\Input $input Input
  • \Joomla\CMS\Form\FormFactoryInterface $formFactory The form factory.
Since
  • 3.0

Method __construct - Source code

/**
 * Constructor.
 *
 * @param   array                 $config       An optional associative array of configuration settings.
 *                                              Recognized key values include 'name', 'default_task', 'model_path', and
 *                                              'view_path' (this list is not meant to be comprehensive).
 * @param   MVCFactoryInterface   $factory      The factory.
 * @param   CMSApplication        $app          The Application for the dispatcher
 * @param   Input                 $input        Input
 * @param   FormFactoryInterface  $formFactory  The form factory.
 *
 * @since   3.0
 */
public function __construct($config = array(), MVCFactoryInterface $factory = null, ?CMSApplication $app = null, ?Input $input = null, FormFactoryInterface $formFactory = null)
{
    parent::__construct($config, $factory, $app, $input);
    // Guess the option as com_NameOfController
    if (empty($this->option)) {
        $this->option = ComponentHelper::getComponentName($this, $this->getName());
    }
    // Guess the \Text message prefix. Defaults to the option.
    if (empty($this->text_prefix)) {
        $this->text_prefix = strtoupper($this->option);
    }
    // Guess the context as the suffix, eg: OptionControllerContent.
    if (empty($this->context)) {
        $r = null;
        $match = 'Controller';
        // If there is a namespace append a backslash
        if (strpos(\get_class($this), '\\')) {
            $match .= '\\\\';
        }
        if (!preg_match('/(.*)' . $match . '(.*)/i', \get_class($this), $r)) {
            throw new \Exception(Text::sprintf('JLIB_APPLICATION_ERROR_GET_NAME', __METHOD__), 500);
        }
        // Remove the backslashes and the suffix controller
        $this->context = str_replace(array('\\', 'controller'), '', strtolower($r[2]));
    }
    // Guess the item view as the context.
    if (empty($this->view_item)) {
        $this->view_item = $this->context;
    }
    // Guess the list view as the plural of the item view.
    if (empty($this->view_list)) {
        $this->view_list = \Joomla\String\Inflector::getInstance()->toPlural($this->view_item);
    }
    $this->setFormFactory($formFactory);
    // Apply, Save & New, and Save As copy should be standard on forms.
    $this->registerTask('apply', 'save');
    $this->registerTask('save2menu', 'save');
    $this->registerTask('save2new', 'save');
    $this->registerTask('save2copy', 'save');
    $this->registerTask('editAssociations', 'save');
}