DirectorObjectForm: gracefully handle missing...

...data type implementations. Happens when fields have been configured
with data types provided by modules that have been disabled later on.
This commit is contained in:
Thomas Gelf 2015-09-29 18:47:49 +02:00
parent c1d6c368d7
commit 386a7ee90d
1 changed files with 11 additions and 3 deletions

View File

@ -271,10 +271,18 @@ abstract class DirectorObjectForm extends QuickForm
protected function addField($field, $value = null, $inherited = null, $inheritedFrom = null)
{
$datafield = DirectorDatafield::load($field->datafield_id, $this->getDb());
$datatype = new $datafield->datatype;
$datatype->setSettings($datafield->getSettings());
$name = 'var_' . $datafield->varname;
$className = $datafield->datatype;
if (! class_exists($className)) {
$this->addElement('text', $name, array('disabled' => 'disabled'));
$el = $this->getElement($name);
$el->addError(sprintf('Form element could not be created, %s is missing', $className));
return $el;
}
$datatype = new $className;
$datatype->setSettings($datafield->getSettings());
$el = $datatype->getFormElement($name, $this);
$el->setLabel($datafield->caption);