Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions libraries/src/Form/Field/ListField.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ class ListField extends FormField
*/
protected $layout = 'joomla.form.field.list';

/**
* The header.
*
* @var mixed
* @since __DEPLOY_VERSION__
*/
protected $header;

/**
* Method to get the field input markup for a generic list.
* Use the multiple attribute to enable multiselect.
Expand All @@ -74,8 +82,14 @@ protected function getInput()
*/
protected function getOptions()
{
$header = $this->header;
$fieldname = preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname);
$options = [];
// Add header.
if (!empty($header)) {
$header_title = Text::_($header);
$options[] = HTMLHelper::_('select.option', '', $header_title);
}

foreach ($this->element->xpath('option') as $option) {
// Filter requirements
Expand Down Expand Up @@ -232,4 +246,30 @@ public function __get($name)

return parent::__get($name);
}

/**
* Method to attach a Form object to the field.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @see FormField::setup()
* @since __DEPLOY_VERSION__
*/
public function setup(\SimpleXMLElement $element, $value, $group = null)
{
$return = parent::setup($element, $value, $group);

if ($return) {
// Check if its using the old way
$this->header = (string) $this->element['header'] ?: false;
}

return $return;
}
}
6 changes: 0 additions & 6 deletions libraries/src/Form/Field/SqlField.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,6 @@ protected function getOptions()
}
}

// Add header.
if (!empty($header)) {
$header_title = Text::_($header);
$options[] = HTMLHelper::_('select.option', '', $header_title);
}

// Build the field options.
if (!empty($items)) {
foreach ($items as $item) {
Expand Down