src/View/Helper/ListFilterHelper.php
public function filterWidget($field, $options = [], $returnString = true)
    {
        $filters = $this->getFilters();
        if (empty($options) && !isset($filters[$field])) {
            trigger_error("No config found for field '{{$field}}'", E_USER_WARNING);

            return false;
        }

        // make sure options isn't merged, as it potentially has int keys which will be doubled
        if (isset($options['options'])) {
            unset($filters[$field]['options']);
        }

        $options = Hash::merge($filters[$field], $options);

        $ret = [];
        switch ($options['searchType']) {
            case 'betweenDates':
                $empty = isset($options['inputOptions']['empty']) ? $options['inputOptions']['empty'] : true;

                $fromFieldName = 'Filter.' . $field . '_from';
                $toFieldName = 'Filter.' . $field . '_to';

                if (empty($options['inputOptions']['label'])) {
                    $options['inputOptions']['label'] = $field;
                }

                $fromOptions = [
                    'label' => $options['inputOptions']['label'] . ' ' . __d('list_filter', 'from'),
                    'type' => 'date'
                ];
                $toOptions = [
                    'label' => $options['inputOptions']['label'] . ' ' . __d('list_filter', 'to'),
                    'type' => 'date'
                ];
                if (!empty($options['inputOptions']['from'])) {
                    $fromOptions = Hash::merge($fromOptions, $options['inputOptions']['from']);
                }
                if (!empty($options['inputOptions']['to'])) {
                    $toOptions = Hash::merge($toOptions, $options['inputOptions']['to']);
                }

                if ($empty) {
                    // map the empty option to both option arrays
                    $fromOptions['empty'] = true;
                    $toOptions['empty'] = true;
                    // if the empty option was set, make sure date inputs are not set to the current date by default
                    if (empty($fromOptions['val']) && empty($this->Form->context()->val($fromFieldName))) {
                        $fromOptions['val'] = '';
                    }
                    if (empty($toOptions['val']) && empty($this->Form->context()->val($toFieldName))) {
                        $toOptions['val'] = '';
                    }
                }

                $ret[] = $this->Form->input($fromFieldName, $fromOptions);
                $ret[] = $this->Form->input($toFieldName, $toOptions);
                break;
            case 'multipleselect':
                $inputOptions = Hash::merge([
                    'type' => 'select',
                    'options' => $options['options'],
                    'multiple' => true,
                ], $options['inputOptions']);
                $ret[] = $this->Form->input('Filter.' . $field, $inputOptions);
                break;
            default:
                $inputOptions = Hash::merge([
                    'options' => isset($options['options']) ? $options['options'] : false,
                ], $options['inputOptions']);
                $ret[] = $this->Form->input('Filter.' . $field, $inputOptions);
                break;
        }
        if ($returnString) {
            return implode("\n", $ret);
        }

        return $ret;
    }
public function filterWidget($field, $options = [], $returnString = true)
    {
        $filters = $this->getFilters();
        if (empty($options) && !isset($filters[$field])) {
            trigger_error("No config found for field '{{$field}}'", E_USER_WARNING);

            return false;
        }

        // make sure options isn't merged, as it potentially has int keys which will be doubled
        if (isset($options['options'])) {
            unset($filters[$field]['options']);
        }

        $options = Hash::merge($filters[$field], $options);

        $ret = [];
        switch ($options['searchType']) {
            case 'betweenDates':
                $empty = isset($options['inputOptions']['empty']) ? $options['inputOptions']['empty'] : true;

                $fromFieldName = 'Filter.' . $field . '_from';
                $toFieldName = 'Filter.' . $field . '_to';

                if (empty($options['inputOptions']['label'])) {
                    $options['inputOptions']['label'] = $field;
                }

                $fromOptions = [
                    'label' => $options['inputOptions']['label'] . ' ' . __d('list_filter', 'from'),
                    'type' => 'date'
                ];
                $toOptions = [
                    'label' => $options['inputOptions']['label'] . ' ' . __d('list_filter', 'to'),
                    'type' => 'date'
                ];
                if (!empty($options['inputOptions']['from'])) {
                    $fromOptions = Hash::merge($fromOptions, $options['inputOptions']['from']);
                }
                if (!empty($options['inputOptions']['to'])) {
                    $toOptions = Hash::merge($toOptions, $options['inputOptions']['to']);
                }

                if ($empty) {
                    // map the empty option to both option arrays
                    $fromOptions['empty'] = true;
                    $toOptions['empty'] = true;
                    // if the empty option was set, make sure date inputs are not set to the current date by default
                    if (empty($fromOptions['val']) && empty($this->Form->context()->val($fromFieldName))) {
                        $fromOptions['val'] = '';
                    }
                    if (empty($toOptions['val']) && empty($this->Form->context()->val($toFieldName))) {
                        $toOptions['val'] = '';
                    }
                }

                $ret[] = $this->Form->input($fromFieldName, $fromOptions);
                $ret[] = $this->Form->input($toFieldName, $toOptions);
                break;
            case 'multipleselect':
                $inputOptions = Hash::merge([
                    'type' => 'select',
                    'options' => $options['options'],
                    'multiple' => true,
                ], $options['inputOptions']);
                $ret[] = $this->Form->input('Filter.' . $field, $inputOptions);
                break;
            default:
                $inputOptions = Hash::merge([
                    'options' => isset($options['options']) ? $options['options'] : false,
                ], $options['inputOptions']);
                $ret[] = $this->Form->input('Filter.' . $field, $inputOptions);
                break;
        }
        if ($returnString) {
            return implode("\n", $ret);
        }

        return $ret;
    }
Outputs a filter widget based on configuration

@param string $field The field to filter with
@param array $options Options defined in Controller::listFilters()
@param bool $returnString If false, an array of the generated widget markup is being returned
@return string|array Markup string or array of the markup of one or multiple filter input widgets