';
- foreach ($section['fields'] as $element => $property) {
+ foreach ($section['fields'] as $element => $properties) {
+ // Set empty form field element
+ $form_field = '';
+
// Create attributes
- $property['attributes'] = Arr::keyExists($property, 'attributes') ? $property['attributes'] : [];
+ $properties['attributes'] = Arr::keyExists($properties, 'attributes') ? $properties['attributes'] : [];
// Create attribute class
- $property['attributes']['class'] = Arr::keyExists($property, 'attributes.class') ? $property['attributes']['class'] : '';
-
- // Create attribute size
- $property['size'] = Arr::keyExists($property, 'size') ? $this->sizes[$property['size']] : $this->sizes['12'];
-
- // Create attribute value
- $property['value'] = Arr::keyExists($property, 'value') ? $property['value'] : '';
-
- // Create title label
- $property['title'] = Arr::keyExists($property, 'title') ? $property['title'] : false;
-
- // Create help text
- $property['help'] = Arr::keyExists($property, 'help') ? $property['help'] : false;
+ $properties['attributes']['class'] = Arr::keyExists($properties, 'attributes.class') ? $properties['attributes']['class'] : '';
// Set element name
$field_name = $this->getElementName($element);
@@ -139,56 +130,53 @@ class Forms
// Set element id
$field_id = $this->getElementID($element);
- // Set element value
- $form_value = Arr::keyExists($values, $element) ? Arr::get($values, $element) : $property['value'];
+ // Set element default value
+ $field_value = Arr::keyExists($values, $element) ? Arr::get($values, $element) : (Arr::keyExists($properties, 'value') ? $properties['value'] : '');
- // Set form element
- $form_field = '';
-
- // Form elements
- switch ($property['type']) {
+ // Field types
+ switch ($properties['type']) {
// Simple text-input, for multi-line fields.
case 'textarea':
- $form_field = $this->textareaField($field_id, $field_name, $form_value, $property);
+ $form_field = $this->textareaField($field_id, $field_name, $field_value, $properties);
break;
// The hidden field is like the text field, except it's hidden from the content editor.
case 'hidden':
- $form_field = $this->hiddenField($field_id, $field_name, $form_value, $property);
+ $form_field = $this->hiddenField($field_id, $field_name, $field_value, $properties);
break;
// A WYSIWYG HTML field.
case 'html':
- $form_field = $this->htmlField($field_id, $field_name, $form_value, $property);
+ $form_field = $this->htmlField($field_id, $field_name, $field_value, $properties);
break;
// Selectbox field
case 'select':
- $form_field = $this->selectField($field_id, $field_name, $property['options'], $form_value, $property);
+ $form_field = $this->selectField($field_id, $field_name, $properties['options'], $field_value, $properties);
break;
// Template select field for selecting entry template
case 'template_select':
- $form_field = $this->templateSelectField($field_id, $field_name, $form_value, $property);
+ $form_field = $this->templateSelectField($field_id, $field_name, $field_value, $properties);
break;
// Visibility select field for selecting entry visibility state
case 'visibility_select':
- $form_field = $this->visibilitySelectField($field_id, $field_name, ['draft' => __('admin_entries_draft'), 'visible' => __('admin_entries_visible'), 'hidden' => __('admin_entries_hidden')], (! empty($form_value) ? $form_value : 'visible'), $property);
+ $form_field = $this->visibilitySelectField($field_id, $field_name, ['draft' => __('admin_entries_draft'), 'visible' => __('admin_entries_visible'), 'hidden' => __('admin_entries_hidden')], (! empty($field_value) ? $field_value : 'visible'), $properties);
break;
case 'heading':
- $form_field = $this->headingField($field_id, $property);
+ $form_field = $this->headingField($field_id, $properties);
break;
case 'routable_select':
- $form_field = $this->routableSelectField($field_id, $field_name, [true => __('admin_yes'), false => __('admin_no')], (is_string($form_value) ? true : ($form_value ? true : false)), $property);
+ $form_field = $this->routableSelectField($field_id, $field_name, [true => __('admin_yes'), false => __('admin_no')], (is_string($field_value) ? true : ($field_value ? true : false)), $properties);
break;
case 'tags':
- $form_field = $this->tagsField($field_id, $field_name, $form_value, $property);
+ $form_field = $this->tagsField($field_id, $field_name, $field_value, $properties);
break;
case 'datetimepicker':
- $form_field = $this->dateField($field_id, $field_name, $form_value, $property);
+ $form_field = $this->dateField($field_id, $field_name, $field_value, $properties);
break;
case 'media_select':
- $form_field = $this->mediaSelectField($field_id, $field_name, $this->flextype->EntriesController->getMediaList($request->getQueryParams()['id'], false), $form_value, $property);
+ $form_field = $this->mediaSelectField($field_id, $field_name, $this->flextype->EntriesController->getMediaList($request->getQueryParams()['id'], false), $field_value, $properties);
break;
// Simple text-input, for single-line fields.
default:
- $form_field = $this->textField($field_id, $field_name, $form_value, $property);
+ $form_field = $this->textField($field_id, $field_name, $field_value, $properties);
break;
}
@@ -262,21 +250,25 @@ class Forms
* @param string $field_name Field name
* @param array $options Field options
* @param string $value Field value
- * @param array $property Field property
+ * @param array $properties Field properties
*
* @return string Returns field
*
* @access protected
*/
- protected function mediaSelectField(string $field_id, string $field_name, array $options, string $value, array $property) : string
+ protected function mediaSelectField(string $field_id, string $field_name, array $options, string $value, array $properties) : string
{
- $property['attributes']['id'] = $field_id;
- $property['attributes']['class'] .= ' ' . $this->field_class;
+ $title = isset($properties['title']) ? $properties['title'] : '';
+ $size = isset($properties['size']) ? $this->sizes[$properties['size']] : $this->sizes['12'];
+ $help = isset($properties['help']) ? $properties['help'] : '';
- $field = '
';
- $field .= ($property['title'] ? Form::label($field_id, __($property['title'])) : '');
- $field .= Form::select($field_name, $options, $value, $property['attributes']);
- $field .= ($property['help'] ? '
' . __($property['help']) . '' : '');
+ $properties['attributes']['id'] = $field_id;
+ $properties['attributes']['class'] .= ' ' . $this->field_class;
+
+ $field = '
';
+ $field .= ($title ? Form::label($field_id, __($title)) : '');
+ $field .= Form::select($field_name, $options, $value, $properties['attributes']);
+ $field .= ($help ? '' . __($help) . '' : '');
$field .= '
';
return $field;
@@ -288,16 +280,20 @@ class Forms
* @param string $field_id Field ID
* @param string $field_name Field name
* @param string $value Field value
- * @param array $property Field property
+ * @param array $properties Field properties
*
* @return string Returns field
*
* @access protected
*/
- protected function templateSelectField(string $field_id, string $field_name, string $value, array $property) : string
+ protected function templateSelectField(string $field_id, string $field_name, string $value, array $properties) : string
{
- $property['attributes']['id'] = $field_id;
- $property['attributes']['class'] .= ' ' . $this->field_class;
+ $title = isset($properties['title']) ? $properties['title'] : '';
+ $size = isset($properties['size']) ? $this->sizes[$properties['size']] : $this->sizes['12'];
+ $help = isset($properties['help']) ? $properties['help'] : '';
+
+ $properties['attributes']['id'] = $field_id;
+ $properties['attributes']['class'] .= ' ' . $this->field_class;
$_templates_list = $this->flextype['themes']->getTemplates($this->flextype['registry']->get('settings.theme'));
@@ -311,10 +307,10 @@ class Forms
}
}
- $field = '
';
- $field .= ($property['title'] ? Form::label($field_id, __($property['title'])) : '');
- $field .= Form::select($field_name, $options, $value, $property['attributes']);
- $field .= ($property['help'] ? '
' . __($property['help']) . '' : '');
+ $field = '
';
+ $field .= ($title ? Form::label($field_id, __($title)) : '');
+ $field .= Form::select($field_name, $options, $value, $properties['attributes']);
+ $field .= ($help ? '' . __($help) . '' : '');
$field .= '
';
return $field;
@@ -327,24 +323,26 @@ class Forms
* @param string $field_name Field name
* @param array $options Field options
* @param mixed $value Field value
- * @param array $property Field property
+ * @param array $properties Field properties
*
* @return string Returns field
*
* @access protected
*/
- protected function routableSelectField(string $field_id, string $field_name, array $options, $value, array $property) : string
+ protected function routableSelectField(string $field_id, string $field_name, array $options, $value, array $properties) : string
{
- $title = isset($property['title']) ? $property['title'] : '';
- $size = isset($property['size']) ? $property['size'] : '';
+ $title = isset($properties['title']) ? $properties['title'] : '';
+ $size = isset($properties['size']) ? $this->sizes[$properties['size']] : $this->sizes['12'];
+ $help = isset($properties['help']) ? $properties['help'] : '';
- $property['attributes']['id'] = $field_id;
- $property['attributes']['class'] .= ' ' . $this->field_class;
+
+ $properties['attributes']['id'] = $field_id;
+ $properties['attributes']['class'] .= ' ' . $this->field_class;
$field = '
';
- $field .= ($property['title'] ? Form::label($field_id, __($title)) : '');
- $field .= Form::select($field_name, $options, $value, $property['attributes']);
- $field .= ($property['help'] ? '' . __($property['help']) . '' : '');
+ $field .= ($title ? Form::label($field_id, __($title)) : '');
+ $field .= Form::select($field_name, $options, $value, $properties['attributes']);
+ $field .= ($help ? '' . __($help) . '' : '');
$field .= '
';
return $field;
@@ -357,21 +355,25 @@ class Forms
* @param string $field_name Field name
* @param array $options Field options
* @param string $value Field value
- * @param array $property Field property
+ * @param array $properties Field properties
*
* @return string Returns field
*
* @access protected
*/
- protected function selectField(string $field_id, string $field_name, array $options, $value, array $property) : string
+ protected function selectField(string $field_id, string $field_name, array $options, $value, array $properties) : string
{
- $property['attributes']['id'] = $field_id;
- $property['attributes']['class'] .= ' ' . $this->field_class;
+ $title = isset($properties['title']) ? $properties['title'] : '';
+ $size = isset($properties['size']) ? $this->sizes[$properties['size']] : $this->sizes['12'];
+ $help = isset($properties['help']) ? $properties['help'] : '';
- $field = '