Adds the option to enhance the select box using Select2

@param array|ObjectConfig $config
@return string
320776
public function optionlist($config = array())
    {
        $translator = $this->getObject('translator');

        $config = new ObjectConfigJson($config);
        $config->append(array(
            'prompt'    => '- '.$translator->translate('Select').' -',
            'deselect'  => false,
            'options'   => array(),
            'select2'   => true,
            'attribs'   => array(),
        ));

        if ($config->deselect && !$config->attribs->multiple)
        {
            $deselect = $this->option(array('value' => '', 'label' => $config->prompt));
            $options  = $config->options->toArray();
            array_unshift($options, $deselect);
            $config->options = $options;
        }

        if ($config->attribs->multiple && $config->name && substr($config->name, -2) !== '[]') {
            $config->name .= '[]';
        }

        $html = '';

        if ($config->select2)
        {
            if (!$config->name) {
                $config->attribs->append(array(
                    'id' => 'select2-element-'.mt_rand(1000, 100000)
                ));
            }
            
            if ($config->deselect) {
                $config->attribs->append(array(
                    'data-placeholder' => $config->prompt
                ));
            }

            $config->append(array(
                'select2_options' => array(
                    'element' => $config->attribs->id ? '#'.$config->attribs->id : 'select[name=\"'.$config->name.'\"]',
                    'options' => array(
                        'allowClear'  => $config->deselect
                    )

                )
            ));

            $html .= $this->createHelper('behavior')->select2($config->select2_options);
        }

        $html .= parent::optionlist($config);

        return $html;
    }
1162523
public function optionlist($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'options'   => array(),
            'name'      => 'id',
            'selected'  => null,
            'disabled'  => null,
            'translate' => false,
            'attribs'   => array('size' => 1),
        ));

        $html = array();

        $html[] = '<select name="'. $config->name .'" '. $this->buildAttributes($config->attribs) .'>';

        foreach($config->options as $group => $options)
        {
            if (is_numeric($group)) {
                $options = array($options);
            } else {
                $html[] = '<optgroup label="' . StringEscaper::attr($group) . '">';
            }

            foreach ($options as $option)
            {
                $value = $option->value;
                $label = $config->translate ? $this->getObject('translator')->translate( $option->label ) : $option->label;

                $extra = '';
                if(isset($option->disabled) && $option->disabled) {
                    $extra .= 'disabled="disabled"';
                }

                if(isset($option->attribs)) {
                    $extra .= ' '.$this->buildAttributes($option->attribs);
                }

                if(!is_null($config->selected))
                {
                    if ($config->selected instanceof ObjectConfig)
                    {
                        foreach ($config->selected as $selected)
                        {
                            $sel = is_object($selected) ? $selected->value : $selected;
                            if ((string) $value == (string) $sel)
                            {
                                $extra .= 'selected="selected"';
                                break;
                            }
                        }
                    }
                    else $extra .= ((string) $value == (string) $config->selected ? ' selected="selected"' : '');
                }

                $html[] = '<option value="'. $value .'" '.$extra.'>' . $label . '</option>';
            }

            if (!is_numeric($group)) {
                $html[] = '</optgroup>';
            }
        }

        $html[] = '</select>';

        return implode(PHP_EOL, $html);
    }
620552
public function sort($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'title'     => '',
            'column'    => '',
            'direction' => 'asc',
            'sort'      => '',
            'url'       => null
        ));

        $translator = $this->getObject('translator');

        //Set the title
        if(empty($config->title)) {
            $config->title = ucfirst($config->column);
        }

        //Set the direction
        $direction  = strtolower($config->direction);
        $direction  = in_array($direction, array('asc', 'desc')) ? $direction : 'asc';

        if($config->column == $config->sort)
        {
            $direction = $direction == 'desc' ? 'asc' : 'desc'; // toggle
        }

        //Set the query in the route
        if(!$config->url instanceof HttpUrlInterface) {
            $config->url = HttpUrl::fromString($config->url);
        }

        $config->url->query['sort']      = $config->column;
        $config->url->query['direction'] = $direction;

        $html  = '<a href="'.$config->url.'" data-k-tooltip=\'{"container":".k-ui-container","delay":{"show":500,"hide":50}}\' data-original-title="'.$translator->translate('Click to sort by this column').'">';
        $html .= $translator->translate($config->title);

        if ($config->column == $config->sort)
        {
            $direction = $direction == 'desc' ? 'descending' : 'ascending'; // toggle
            $html .= '<span class="k-sort-'.$direction.'" aria-hidden="true"></span>';
            $html .= '<span class="k-visually-hidden">'.$direction.'</span>';
        }

        $html .= '</a>';

        return $html;
    }
1272516
public function addOptions($options = [], $selectedValue = '')
    {
        // Create all options
        foreach ($options as $value => $title) {
            // Create option
            $fi = $this->getHTMLFormFactory()->buildFormElement('option', '', $value, '', '', $title);

            // Check if it's the selected value
            if ($value == $selectedValue) {
                $fi->attr('selected', 'selected');
            }

            // Append option to select
            $this->append($fi);
        }

        // Return FormSelect object
        return $this;
    }
1199914
public function config($config = null) {
		if ($config) {
			if (!is_array($config)) {
				return isset($this->_config[$config]) ? $this->_config[$config] : null;
			}
			$this->_config = $config + $this->_config;
		}
		return $this->_config;
	}
1358321
protected function parseDescriptorField($config)
    {
        if (is_array($config)) {
            $descriptor = [];
            foreach ($config as $field) {
                if (!empty($this->{$field})) {
                    $descriptor[] = $this->{$field};
                }
            }

            return implode(' ', $descriptor);
        } else {
            return $this->{$config};
        }
    }
299484
public function searchableContent(array $config = array())
    {
        $result = '';
        $type = $this->searchType();

        /*
         * Plain Bootstrap with glyphicons
         */
        if ('resource-table::bootstrap' === $this->_viewName) {
            switch ($type) {

                // Select
                case 'select':
                    if (!count($this->options())) {
                        // Options must be provided for select
                        return '';
                    }
                    $result .= '<select name="resource_table_'.$this->index().'" class="'.array_get($config, 'control_class', 'form-control input-sm').' resource-table-column-filter">'.$this->_optionsHTML().'</select>';
                    break;

                // Simple string input
                case 'string':
                default:
                    $result .= '<input type="text" placeholder="'.array_get($config, 'placeholder', trans('resource-table::default.Search_for').' '.$this->label()).'" class="'.array_get($config, 'control_class', 'form-control input-sm').' resource-table-column-filter" name="resource_table_'.$this->index().'" value="'.ResourceTable::getSearchValue($this->index()).'" />';
                    break;
            }
        }

        /*
         * Just simple table
         */
        if (!$result) {
            switch ($type) {

                // Select
                case 'select':
                    if (!count($this->options())) {
                        // Options must be provided for select
                        return '';
                    }
                    $result .= '<select name="resource_table_'.$this->index().'" class="'.array_get($config, 'control_class').' resource-table-column-filter">'.$this->_optionsHTML().'</select>';
                    break;

                // Simple string input
                case 'string':
                default:
                    $result .= '<input type="text" class="'.array_get($config, 'control_class').' resource-table-column-filter" name="resource_table_'.$this->index().'" value="'.ResourceTable::getSearchValue($this->index()).'" placeholder="'.array_get($config, 'placeholder').'" />';
                    break;
            }
        }

        return $result;
    }
406330
public function settings(Array $config = []) : Paginator
    {
        foreach( $config as $key => $value )
        {
            $this->$key = $value;
        }        

        $this->class = array_merge($this->config['class'], $this->class ?? []);
        $this->style = array_merge($this->config['style'], $this->style ?? []);

        if( isset($config['url']) && $this->type !== 'ajax' )
        {
            $this->url = Base::suffix(URL::site($config['url']));
        }
        elseif( $this->type === 'ajax' )
        {
            $this->url = 'javascript:;';
        }
        else
        {
            $this->url = CURRENT_CFURL;
        }

        return $this;
    }
1002691
public function get_option($config = '') {
        if ($config === 'dropbox_key') {
            return trim(get_config('dropbox', 'dropbox_key'));
        } else if ($config === 'dropbox_secret') {
            return trim(get_config('dropbox', 'dropbox_secret'));
        } else if ($config === 'dropbox_cachelimit') {
            return $this->max_cache_bytes();
        } else {
            $options = parent::get_option();
            $options['dropbox_key'] = trim(get_config('dropbox', 'dropbox_key'));
            $options['dropbox_secret'] = trim(get_config('dropbox', 'dropbox_secret'));
            $options['dropbox_cachelimit'] = $this->max_cache_bytes();
        }

        return $options;
    }
356223
public function formfield_select($config = array())
    {
        $config = new AnConfig($config);

        $config->append(array(
            'class' => 'input-block-level',
            'name' => '',
            'selected' => '',
            'description' => '',
            'id' => '',
            'label' => '',
            'options' => array(),
            'disabled' => false,
        ));

        return $this->_render('formfield_select', $config);
    }
1339442
public function option($config = array())
    {
        $config = new KObjectConfigJson($config);
        $config->append(array(
            'id'        => null,
            'name'      => 'id',
            'value'     => null,
            'label'     => '',
            'disabled'  => false,
            'level'     => 1,
            'attribs'   => array(),
        ));

        $option = new stdClass;
        $option->id       = $config->id;
        $option->name     = $config->name;
        $option->value 	  = $config->value;
        $option->label    = trim( $config->label ) ? $config->label : $config->value;
        $option->disabled = $config->disabled;
        $option->level    = $config->level;
        $option->attribs  = KObjectConfig::unbox($config->attribs);

        if($config->level) {
            $option->attribs['class'] = array('level'.$config->level);
        }

        if($config->disabled) {
            $option->attribs['class'] = array('k-is-disabled', 'disabled');
        }

        return $option;
    }
651227
public function command($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'id'      => '',
            'href'    => '',
            'icon'    => '',
            'allowed' => true,
            'disabled'=> false,
            'data'    => array(),
            'attribs' => array(
                'href'  => '#',
                'class' => array('toolbar')
            )
        ));

        $translator = $this->getObject('translator');

        if ($config->allowed === false)
        {
            $config->attribs->title = $translator->translate('You are not allowed to perform this action');
            $config->attribs->class->append(array('k-is-disabled', 'k-is-unauthorized'));
        }

        //Create the id
        $config->attribs['id'] = 'command-'.$config->id;

        $config->attribs->class->append(array('k-button', 'k-button--default', 'k-button-'.$config->id));

        if ($config->id === 'new' || $config->id === 'save') {
            $config->attribs->class->append(array('k-button--success'));
        }

        //Add the data attributes
        foreach($config->data as $key => $value) {
            $config->attribs['data-'.$key] = (string) $value;
        }

        //Create the href
        if(!empty($config->href)) {
            $config->attribs['href'] = $config->href;
        }

        $attribs = clone $config->attribs;
        $attribs->class = implode(" ", ObjectConfig::unbox($attribs->class));

        $html = '<a '.$this->buildAttributes($attribs).'>';

        $html .= '<span class="'.$config->icon.'" aria-hidden="true"></span> ';
        $html .= '<span class="k-button__text">';
        $html .= $translator->translate($config->label);
        $html .= '</span>';
        $html .= '</a>';

        return $html;
    }
1197394
protected function _objectConfig(KObjectConfig $config)
    {
        $config->append(array(
            'id'         => $this->row,
            'objectName' => $this->title,
            'type'       => array('objectName' => $this->name, 'object' => true),
            'url'        => 'option=com_' . $this->package . '&view=' . $this->name . '&id=' . $this->row,
            'attributes' => array('class' => array('object')),
            'find'       => 'object',
            'translate'  => false
        ));
    }
357055
public function javascript($config = array())
    {
        return $this->getTemplate()->helper('behavior.bootstrap', array(
            'debug' => JFactory::getApplication()->getCfg('debug'),
            'css' => false,
            'javascript' => true
        ));
    }
378442
protected function mergeOptions(&$config, $options)
    {
        foreach ($config as $paramName => $paramValue) {
            if (isset($options[$paramName])) {
                if (is_array($paramValue)) {
                    $config[$paramName] =  array_merge($config[$paramName], $options[$paramName]);
                } else {
                    $config[$paramName] = $options[$paramName];
                }
            }
        }

        return $config;
    }
1117781
protected function _initialize(ObjectConfig $config)
    {
        $self = $this;

        $config->append(array(
            'autoescape'       => true,
            'strict_variables' => false,
            'optimizations'    => -1,
            'functions'        => array(
                'import' => function($url, $data) use($self) {
                    return $self->renderPartial($url, $data);
                }
            ),
        ));

        parent::_initialize($config);
    }
170183
public function makeSelected($config, $selected, $custom)
    {
        $options = $prefix = $suffix = '';

        if (isset($config['config']['multiple'])) {
            $custom = 'multiple';
            $config['name'] = $config['name'].'[]';
        }

        if (config('form-maker.form.orientation') === 'horizontal') {
            $prefix = '<div class="'.config('form-maker.form.input-column').'">';
            $suffix = '</div>';
        }

        foreach ($config['config']['options'] as $key => $value) {
            $selectedValue = '';

            if (isset($config['config']['multiple']) && is_object($selected)) {
                if (in_array($value, $selected->toArray())) {
                    $selectedValue = 'selected';
                }
            } else {
                if ($selected == '') {
                    $selectedValue = ((string) $config['objectValue'] === (string) $value) ? 'selected' : '';
                } else {
                    if (isset($config['objectValue']) && is_array(json_decode($config['objectValue']))) {
                        $selectedValue = (in_array($value, json_decode($config['objectValue']))) ? 'selected' : '';
                    } else {
                        $selectedValue = ((string) $selected === (string) $value) ? 'selected' : '';
                    }
                }
            }

            $options .= '<option value="'.$value.'" '.$selectedValue.'>'.$key.'</option>';
        }

        return $prefix.'<select '.$this->processCustom($custom).' id="'.$this->getId($config).'" class="'.$config['class'].'" name="'.$config['name'].'">'.$options.'</select>'.$suffix;
    }