* @link https://regularlabs.com * @copyright Copyright © 2024 Regular Labs All Rights Reserved * @license GNU General Public License version 2 or later */ namespace RegularLabs\Library\Form\Field; defined('_JEXEC') or die; use Joomla\CMS\Form\Field\CheckboxesField as JCheckboxesField; use Joomla\CMS\Form\FormHelper; use Joomla\CMS\Language\Text as JText; use SimpleXMLElement; use UnexpectedValueException; use function count; class CheckboxesField extends JCheckboxesField { /** * Name of the layout being used to render the field * * @var string */ protected $layout = 'regularlabs.form.field.checkboxes'; protected function getLayoutPaths() { $paths = parent::getLayoutPaths(); $paths[] = JPATH_LIBRARIES . '/regularlabs/layouts'; return $paths; } protected function getOptions() { $groups = $this->getGroups(); return self::flattenGroups($groups); } private static function flattenGroups(array $groups): array { $options = []; foreach ($groups as $group_name => $group) { if ($group_name !== 0) { $options[] = $group_name; } foreach ($group as $option) { $options[] = $option; } } return $options; } private function getGroups(): array { $fieldname = preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname); $groups = []; $label = 0; foreach ($this->element->children() as $element) { switch ($element->getName()) { // The element is an