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

_magicOptions() protected method

Magically set option type and corresponding options
protected _magicOptions ( string $fieldName, array $options, boolean $allowOverride ) : array
$fieldName string The name of the field to generate options for.
$options array Options list.
$allowOverride boolean Whether or not it is allowed for this method to overwrite the 'type' key in options.
return array
    protected function _magicOptions($fieldName, $options, $allowOverride)
    {
        $context = $this->_getContext();
        if (!isset($options['required']) && $options['type'] !== 'hidden') {
            $options['required'] = $context->isRequired($fieldName);
        }
        $type = $context->type($fieldName);
        $fieldDef = $context->attributes($fieldName);
        if ($options['type'] === 'number' && !isset($options['step'])) {
            if ($type === 'decimal' && isset($fieldDef['precision'])) {
                $decimalPlaces = $fieldDef['precision'];
                $options['step'] = sprintf('%.' . $decimalPlaces . 'F', pow(10, -1 * $decimalPlaces));
            } elseif ($type === 'float') {
                $options['step'] = 'any';
            }
        }
        $typesWithOptions = ['text', 'number', 'radio', 'select'];
        $magicOptions = in_array($options['type'], ['radio', 'select']) || $allowOverride;
        if ($magicOptions && in_array($options['type'], $typesWithOptions)) {
            $options = $this->_optionsOptions($fieldName, $options);
        }
        if ($allowOverride && substr($fieldName, -5) === '._ids') {
            $options['type'] = 'select';
            if (empty($options['multiple'])) {
                $options['multiple'] = true;
            }
        }
        if ($options['type'] === 'select' && array_key_exists('step', $options)) {
            unset($options['step']);
        }
        $autoLength = !array_key_exists('maxlength', $options) && !empty($fieldDef['length']) && $options['type'] !== 'select';
        $allowedTypes = ['text', 'textarea', 'email', 'tel', 'url', 'search'];
        if ($autoLength && in_array($options['type'], $allowedTypes)) {
            $options['maxlength'] = min($fieldDef['length'], 100000);
        }
        if (in_array($options['type'], ['datetime', 'date', 'time', 'select'])) {
            $options += ['empty' => false];
        }
        return $options;
    }