* @copyright Copyright (c) 2020 Samuel Marshall / JCH Optimize * @license GNU/GPLv3, or later. See LICENSE file * * If LICENSE file missing, see . */ defined('_JEXEC') or die; use JchOptimize\ContainerFactory; use JchOptimize\Core\Admin\MultiSelectItems; use JchOptimize\Core\Helper; use Joomla\CMS\Uri\Uri as JUri; include_once JPATH_ADMINISTRATOR . '/components/com_jchoptimize/autoload.php'; include_once JPATH_ADMINISTRATOR . '/components/com_jchoptimize/version.php'; JFormHelper::loadFieldClass('textarea'); abstract class JFormFieldExclude extends JFormFieldTextarea { protected bool $first_field = false; protected string $filegroup = 'file'; protected string $filetype = ''; /** * @var MultiSelectItems */ protected $multiSelect; public function __construct($form = null) { parent::__construct($form); $container = ContainerFactory::getContainer(); $this->multiSelect = $container->buildObject(MultiSelectItems::class); } public function setup(SimpleXMLElement $element, $value, $group = null): bool { $value = $this->castValue($value); return parent::setup($element, $value, $group); } /** * * @param string $value * * @return array */ protected function castValue($value) { if ( ! is_array($value)) { $value = Helper::getArray($value); } return $value; } /** * * @return string */ protected function getInput() { $attributes = 'class="inputbox chzn-custom-value input-xlarge jch-multiselect" multiple size="5" data-jch_type="' . $this->filetype . '" data-jch_param="' . $this->fieldname . '" data-jch_group="' . $this->filegroup . '"'; $select = JHTML::_( 'select.genericlist', $this->getOptions(), 'jform[' . $this->fieldname . '][]', $attributes, 'id', 'name', $this->value, $this->id ); $uriRoot = JUri::root(); return <<{$select} HTML; } protected function getOptions(): array { $options = []; foreach ($this->value as $excludeValue) { $options[$excludeValue] = $this->multiSelect->{'prepare' . ucfirst($this->filegroup) . 'Values'}( $excludeValue ); } return $options; } }