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

dev #12992 #14706 custom fields

if no custom field defined, display error message when editing field values
parent cc072d35
Branches
Tags
4 merge requests!321Dev#12992 custom fields,!302Dev#12992 Custom Fields,!235Dev#12992 Custom Fields,!228Dev#12992 Custom Fields
......@@ -95,12 +95,17 @@
$value_object->setValue($value)->save();
}
}
if (empty($model_values->getFields()))
$this->view->error_message = $this->_('Aucun champ personnalisé n\'a été défini');
$this->view->titre = $this->view->_(
'Champs personnalisés: %s "%s"',
strtolower($model->getLabel()),
$model_values->getLabel());
$this->view->titre = $this->view->_('Champs personnalisés: %s "%s"',
strtolower($model->getLabel()),
$model_values->getLabel());
$this->view->form = new ZendAfi_Form_Admin_CustomFields_ModelValues(['model_values' => $model_values]);
$this->view->form = new ZendAfi_Form_Admin_CustomFields_ModelValues(['model_values' => $model_values]);
}
}
}
?>
\ No newline at end of file
<?php echo $this->renderForm($this->form); ?>
<?php
if ($this->error_message)
echo $this->tag('p',
$this->error_message,
['class' => 'error']);
echo $this->renderForm($this->form);
?>
......@@ -31,14 +31,17 @@ class ZendAfi_Form_Admin_CustomFields_ModelValues extends ZendAfi_Form {
public function init() {
parent::init();
if (!$fields = $this->_model_values->getFields())
return;
$field_names = [];
foreach($this->_model_values->getFields() as $item) {
$field_name = 'field_'.$item->getId();
foreach($fields as $field) {
$field_name = 'field_'.$field->getId();
$field_names []= $field_name;
$field_strategy = 'Field_Strategy_'.$item->getFieldType();
(new $field_strategy($this))->addElement($item,
$field_strategy = 'Field_Strategy_'.$field->getFieldType();
(new $field_strategy($this))->addElement($field,
$field_name,
$this->_model_values->getValue($item->getId()));
$this->_model_values->getValue($field->getId()));
}
$this->addDisplayGroup($field_names,
......
......@@ -392,6 +392,29 @@ class CustomFieldsControllerUpDownActionTest extends CustomFieldControllerTestCa
class CustomFieldsControllerValuesForUserGroupWithoutDefinedCustomFieldsTest extends CustomFieldControllerTestCase {
public function setUp() {
parent::setUp();
$this->fixture('Class_UserGroup',
['id' => 1,
'libelle' => 'Teachers']);
Class_CustomField_Meta::deleteBy([]);
$this->dispatch('/admin/custom-fields/values/model/UserGroup/id/1', true);
}
/** @test */
public function pageShouldDisplayNoCustomFieldsDefined() {
$this->assertXPathContentContains('//p[@class="error"]', 'Aucun champ personnalisé n\'a été défini');
}
}
class CustomFieldsControllerValuesForUserGroupTeachersTest extends CustomFieldControllerTestCase {
public function setUp() {
parent::setUp();
......
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