Back to PluginsField class

Method getOptions

protected array
getOptions
()
Method to get a list of options for a list input.
Returns
  • array An array of JHtml options.
Since
  • 2.5.0
Class: PluginsField
Project: Joomla

Method getOptions - Source code

/**
 * Method to get a list of options for a list input.
 *
 * @return	array  An array of JHtml options.
 *
 * @since   2.5.0
 */
protected function getOptions()
{
    $folder = $this->folder;
    $parentOptions = parent::getOptions();
    if (!empty($folder)) {
        // Get list of plugins
        $db = Factory::getDbo();
        $query = $db->getQuery(true)->select([$db->quoteName('element', 'value'), $db->quoteName('name', 'text')])->from($db->quoteName('#__extensions'))->where([$db->quoteName('folder') . ' = :folder', $db->quoteName('enabled') . ' = 1'])->bind(':folder', $folder)->order([$db->quoteName('ordering'), $db->quoteName('name')]);
        if ((string) $this->element['useaccess'] === 'true') {
            $query->whereIn($db->quoteName('access'), Factory::getUser()->getAuthorisedViewLevels());
        }
        $options = $db->setQuery($query)->loadObjectList();
        $lang = Factory::getLanguage();
        $useGlobal = $this->element['useglobal'];
        if ($useGlobal) {
            $globalValue = Factory::getApplication()->get($this->fieldname);
        }
        foreach ($options as $i => $item) {
            $source = JPATH_PLUGINS . '/' . $folder . '/' . $item->value;
            $extension = 'plg_' . $folder . '_' . $item->value;
            $lang->load($extension . '.sys', JPATH_ADMINISTRATOR) || $lang->load($extension . '.sys', $source);
            $options[$i]->text = Text::_($item->text);
            // If we are using useglobal update the use global value text with the plugin text.
            if ($useGlobal && isset($parentOptions[0]) && $item->value === $globalValue) {
                $text = Text::_($extension);
                $parentOptions[0]->text = Text::sprintf('JGLOBAL_USE_GLOBAL_VALUE', $text === '' || $text === $extension ? $item->value : $text);
            }
        }
    } else {
        Log::add(Text::_('JFRAMEWORK_FORM_FIELDS_PLUGINS_ERROR_FOLDER_EMPTY'), Log::WARNING, 'jerror');
    }
    return array_merge($parentOptions, $options);
}