diff --git a/administrator/components/com_fields/libraries/fieldslistplugin.php b/administrator/components/com_fields/libraries/fieldslistplugin.php new file mode 100644 index 0000000000000..2b384b8b8433e --- /dev/null +++ b/administrator/components/com_fields/libraries/fieldslistplugin.php @@ -0,0 +1,82 @@ +getOptionsFromField($field) as $value => $name) + { + $option = new DOMElement('option', $value); + $option->nodeValue = JText::_($name); + + $element = $fieldNode->appendChild($option); + $element->setAttribute('value', $value); + } + + return $fieldNode; + } + + /** + * Returns an array of key values to put in a list from the given field. + * + * @param stdClass $field The field. + * + * @return array + * + * @since __DEPLOY_VERSION__ + */ + public function getOptionsFromField($field) + { + $data = array(); + + // Fetch the options from the plugin + foreach ($this->params->get('options', array()) as $option) + { + $op = (object) $option; + $data[$op->value] = $op->name; + } + + // Fetch the options from the field + foreach ($field->fieldparams->get('options', array()) as $option) + { + $data[$option->value] = $option->name; + } + + return $data; + } +} diff --git a/plugins/fields/checkboxes/checkboxes.php b/plugins/fields/checkboxes/checkboxes.php index 81d3d7c82c3db..294c65e986e35 100644 --- a/plugins/fields/checkboxes/checkboxes.php +++ b/plugins/fields/checkboxes/checkboxes.php @@ -9,13 +9,13 @@ defined('_JEXEC') or die; -JLoader::import('fields.list.list', JPATH_PLUGINS); +JLoader::import('components.com_fields.libraries.fieldslistplugin', JPATH_ADMINISTRATOR); /** * Fields Checkboxes Plugin * * @since __DEPLOY_VERSION__ */ -class PlgFieldsCheckboxes extends PlgFieldsList +class PlgFieldsCheckboxes extends FieldsListPlugin { } diff --git a/plugins/fields/imagelist/imagelist.php b/plugins/fields/imagelist/imagelist.php index 98494ef083cdc..c823ed9e6fab7 100644 --- a/plugins/fields/imagelist/imagelist.php +++ b/plugins/fields/imagelist/imagelist.php @@ -9,14 +9,14 @@ defined('_JEXEC') or die; -JLoader::import('fields.list.list', JPATH_PLUGINS); +JLoader::import('components.com_fields.libraries.fieldslistplugin', JPATH_ADMINISTRATOR); /** * Fields Imagelist Plugin * * @since __DEPLOY_VERSION__ */ -class PlgFieldsImagelist extends PlgFieldsList +class PlgFieldsImagelist extends FieldsListPlugin { /** * Transforms the field into an XML element and appends it as child on the given parent. This diff --git a/plugins/fields/list/list.php b/plugins/fields/list/list.php index 92701b967408f..2ada1cef81b7b 100644 --- a/plugins/fields/list/list.php +++ b/plugins/fields/list/list.php @@ -9,75 +9,13 @@ defined('_JEXEC') or die; -JLoader::import('components.com_fields.libraries.fieldsplugin', JPATH_ADMINISTRATOR); +JLoader::import('components.com_fields.libraries.fieldslistplugin', JPATH_ADMINISTRATOR); /** * Fields list Plugin * * @since __DEPLOY_VERSION__ */ -class PlgFieldsList extends FieldsPlugin +class PlgFieldsList extends FieldsListPlugin { - /** - * Transforms the field into an XML element and appends it as child on the given parent. This - * is the default implementation of a field. Form fields which do support to be transformed into - * an XML Element mut implemet the JFormDomfieldinterface. - * - * @param stdClass $field The field. - * @param DOMElement $parent The field node parent. - * @param JForm $form The form. - * - * @return DOMElement - * - * @since 3.7.0 - */ - public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form) - { - $fieldNode = parent::onCustomFieldsPrepareDom($field, $parent, $form); - - if (!$fieldNode) - { - return $fieldNode; - } - - foreach ($this->getOptionsFromField($field) as $value => $name) - { - $option = new DOMElement('option', $value); - $option->nodeValue = JText::_($name); - - $element = $fieldNode->appendChild($option); - $element->setAttribute('value', $value); - } - - return $fieldNode; - } - - /** - * Returns an array of key values to put in a list from the given field. - * - * @param stdClass $field The field. - * - * @return array - * - * @since 3.7.0 - */ - public function getOptionsFromField($field) - { - $data = array(); - - // Fetch the options from the plugin - foreach ($this->params->get('options', array()) as $option) - { - $op = (object) $option; - $data[$op->value] = $op->name; - } - - // Fetch the options from the field - foreach ($field->fieldparams->get('options', array()) as $option) - { - $data[$option->value] = $option->name; - } - - return $data; - } } diff --git a/plugins/fields/radio/radio.php b/plugins/fields/radio/radio.php index 36d6e3fca38e8..daa6bc4ddf513 100644 --- a/plugins/fields/radio/radio.php +++ b/plugins/fields/radio/radio.php @@ -9,13 +9,13 @@ defined('_JEXEC') or die; -JLoader::import('fields.list.list', JPATH_PLUGINS); +JLoader::import('components.com_fields.libraries.fieldslistplugin', JPATH_ADMINISTRATOR); /** * Fields Radio Plugin * * @since __DEPLOY_VERSION__ */ -class PlgFieldsRadio extends PlgFieldsList +class PlgFieldsRadio extends FieldsListPlugin { } diff --git a/plugins/fields/sql/sql.php b/plugins/fields/sql/sql.php index 08977e72e6aed..420f5250e2566 100644 --- a/plugins/fields/sql/sql.php +++ b/plugins/fields/sql/sql.php @@ -9,14 +9,14 @@ defined('_JEXEC') or die; -JLoader::import('fields.list.list', JPATH_PLUGINS); +JLoader::import('components.com_fields.libraries.fieldslistplugin', JPATH_ADMINISTRATOR); /** * Fields Sql Plugin * * @since __DEPLOY_VERSION__ */ -class PlgFieldsSql extends PlgFieldsList +class PlgFieldsSql extends FieldsListPlugin { /** * Transforms the field into an XML element and appends it as child on the given parent. This