FOF30\Model\DataModel::loadForm PHP Method

loadForm() protected method

Method to get a form object.
See also: Form
Since: 2.0
protected loadForm ( string $name, string $source, array $options = [], boolean $clear = false, boolean | string $xpath = false ) : Form | boolean
$name string The name of the form.
$source string The form filename (e.g. form.browse)
$options array Optional array of options for the form creation.
$clear boolean Optional argument to force load a new form.
$xpath boolean | string An optional xpath to search for the fields.
return FOF30\Form\Form | boolean Form object on success, False on error.
    protected function loadForm($name, $source, $options = array(), $clear = false, $xpath = false)
    {
        // Handle the optional arguments.
        $options['control'] = isset($options['control']) ? $options['control'] : false;
        // Create a signature hash.
        $hash = md5($source . serialize($options));
        if (!isset($this->_forms[$hash]) || $clear) {
            // Get the form.
            $form = $this->container->factory->form($name, $source, $this->name, $options, false, $xpath);
            if (!is_object($form)) {
                $this->_forms[$hash] = false;
                return false;
            }
            $data = array();
            if (isset($options['load_data']) && $options['load_data']) {
                // Get the data for the form.
                $data = $this->loadFormData();
            }
            // Allows data and form manipulation before preprocessing the form
            $this->triggerEvent('onBeforePreprocessForm', array(&$form, &$data));
            // Allow for additional modification of the form, and events to be triggered.
            // We pass the data because plugins may require it.
            $this->preprocessForm($form, $data);
            // Allows data and form manipulation After preprocessing the form
            $this->triggerEvent('onAfterPreprocessForm', array(&$form, &$data));
            // Load the data into the form after the plugins have operated.
            $form->bind($data);
            // Store the form for later.
            $this->_forms[$hash] = $form;
        }
        return $this->_forms[$hash];
    }