Skip to content
Snippets Groups Projects
Commit a2fce890 authored by Laurent's avatar Laurent
Browse files

dev #12992 #14706 custom fields

options set in a select custom fields are now usable
parent db5bf2e9
Branches
Tags
4 merge requests!321Dev#12992 custom fields,!302Dev#12992 Custom Fields,!235Dev#12992 Custom Fields,!228Dev#12992 Custom Fields
......@@ -109,6 +109,11 @@ class Class_CustomField extends Storm_Model_Abstract {
return $this->getMeta()->getOptionsList();
}
public function getOptionsListAsArray() {
return $this->getMeta()->getOptionsListAsArray();
}
public function toArray() {
return array_merge(parent::toArray(), ['label' => $this->getLabel(),
......
......@@ -35,9 +35,8 @@ class ZendAfi_Form_Admin_CustomFields_ModelValues extends ZendAfi_Form {
foreach($this->_model_values->getFields() as $item) {
$field_name = 'field_'.$item->getId();
$field_names []= $field_name;
$this->addElement($item->getFieldType(),
$field_name,
['label' => $item->getLabel()]);
$field_strategy = 'Field_Strategy_'.$item->getFieldType();
(new $field_strategy($this))->addElement($item, $field_name);
}
$this->addDisplayGroup($field_names,
......@@ -46,4 +45,54 @@ class ZendAfi_Form_Admin_CustomFields_ModelValues extends ZendAfi_Form {
}
}
class Field_Strategy {
protected $_form,
$_field;
public function __construct($form) {
$this->_form = $form;
}
public function addElement($field, $label) {
$this->_field = $field;
$this->_form->addElement($field->getFieldType(),
$label,
array_merge(['label' => $field->getLabel()],
$this->getOptions()));
}
protected function getOptions() {
return [];
}
}
class Field_Strategy_text extends Field_Strategy {
protected function getOptions() {
return ['size' => 35];
}
}
class Field_Strategy_textarea extends Field_Strategy {
protected function getOptions() {
return ['cols' => 35,
'rows' => 10];
}
}
class Field_Strategy_select extends Field_Strategy {
protected function getOptions() {
return ['multioptions' => $this->_field->getOptionsListAsArray()];
}
}
?>
\ No newline at end of file
......@@ -423,7 +423,7 @@ class CustomFieldsControllerValuesForUserGroupTeachersTest extends CustomFieldCo
/** @test */
public function selectOptionsShouldBePresent() {
$this->assertXPathContentContains('//form//fieldset//select//option[@value="1"]', 'enabled');
$this->assertXPathContentContains('//form//fieldset//select//option[@value="0"]', 'enabled');
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment