Cake\View\Helper\FormHelper::_optionsOptions PHP Method

_optionsOptions() protected method

Selects the variable containing the options for a select field if present, and sets the value to the 'options' key in the options array.
protected _optionsOptions ( string $fieldName, array $options ) : array
$fieldName string The name of the field to find options for.
$options array Options list.
return array
    protected function _optionsOptions($fieldName, $options)
    {
        if (isset($options['options'])) {
            return $options;
        }
        $pluralize = true;
        if (substr($fieldName, -5) === '._ids') {
            $fieldName = substr($fieldName, 0, -5);
            $pluralize = false;
        } elseif (substr($fieldName, -3) === '_id') {
            $fieldName = substr($fieldName, 0, -3);
        }
        $fieldName = array_slice(explode('.', $fieldName), -1)[0];
        $varName = Inflector::variable($pluralize ? Inflector::pluralize($fieldName) : $fieldName);
        $varOptions = $this->_View->get($varName);
        if (!is_array($varOptions) && !$varOptions instanceof Traversable) {
            return $options;
        }
        if ($options['type'] !== 'radio') {
            $options['type'] = 'select';
        }
        $options['options'] = $varOptions;
        return $options;
    }