- md5
- 7207c27eb3af736ab01fc185bcfe29b6
- sha1
- 6237b5544fe9b449e6c545f222b5642d802b6cb4
- sha256
- 45eaee80350d7e3ab1f191f93c093ed174dd4bb3c37526bf81e5e624d9eb72a2
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
<?php
/**
* @package Joomla.Administrator
* @subpackage com_fields
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Fields\Administrator\Plugin;
\defined('_JEXEC') or die;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Language\Text;
/**
* Base plugin for all list based plugins
*
* @since 3.7.0
*/
class FieldsListPlugin extends FieldsPlugin
{
/**
* Transforms the field into a DOM XML element and appends it as a child on the given parent.
*
* @param \stdClass $field The field.
* @param \DOMElement $parent The field node parent.
* @param Form $form The form.
*
* @return \DOMElement
*
* @since 3.7.0
*/
public function onCustomFieldsPrepareDom($field, \DOMElement $parent, Form $form)
{
$fieldNode = parent::onCustomFieldsPrepareDom($field, $parent, $form);
if (!$fieldNode)
{
return $fieldNode;
}
$fieldNode->setAttribute('validate', 'options');
foreach ($this->getOptionsFromField($field) as $value => $name)
{
$option = new \DOMElement('option', htmlspecialchars($value, ENT_COMPAT, 'UTF-8'));
$option->textContent = htmlspecialchars(Text::_($name), ENT_COMPAT, 'UTF-8');
$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
$params = clone $this->params;
$params->merge($field->fieldparams);
foreach ($params->get('options', array()) as $option)
{
$op = (object) $option;
$data[$op->value] = $op->name;
}
return $data;
}
}
The same content is in 51 releases, Joomla 4.0.0-beta6 to 4.2.0-beta2. See them all, or every version of this file.