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];
}