Adds a new Twig filter.

@see http://twig.sensiolabs.org/doc/advanced.html#filters Twig documentation

@param string   $name    Name of filter
@param callable $filter  Filter implementation
@param array    $options
16539
public function addTwigFilter($name, callable $filter, array $options = [])
    {
        $twigFilter = new \Twig_SimpleFilter($name, $filter, $options);

        $this->twig->addFilter($twigFilter);
    }
1352291
public function select(array $filter = [], array $options = [])
    {
        // Create query object from filter and option arrays
        $query = $this->getQuery($filter, $options);

        try {
            $cursor = $this->getInstance()->executeQuery(
                $this->getParam('database') . '.' . $this->getCollection(),
                $query
            );
            $response = $cursor->toArray();

        } catch (MongoException $e) {
            new Exception('Unable to execute query');
        }

        return $response ?? false;
    }
616254
public function makeTwigFilters($filters = [])
    {
        if (!is_array($filters)) {
            $filters = [];
        }

        foreach ($this->listFilters() as $name => $callable) {

            /*
             * Handle a wildcard function
             */
            if (strpos($name, '*') !== false && $this->isWildCallable($callable)) {
                $callable = function ($name) use ($callable) {
                    $arguments = array_slice(func_get_args(), 1);
                    $method = $this->isWildCallable($callable, Str::camel($name));
                    return call_user_func_array($method, $arguments);
                };
            }

            if (!is_callable($callable)) {
                throw new ApplicationException(sprintf('The markup filter for %s is not callable.', $name));
            }

            $filters[] = new Twig_SimpleFilter($name, $callable, ['is_safe' => ['html']]);
        }

        return $filters;
    }
28881
private function createFilter($filter, $options = null)
    {
        $params = [];
        $data = $this->classmap[$filter];
        if (isset($options)) {
            if (!isset($data['options'])) {
                throw new InvalidConfigException('Filter "' . $filter . '" has no options.');
            }
            foreach ($options as $option => $value) {
                if (!isset($data['options'][$option])) {
                    throw new InvalidConfigException('Option "' . $option . '" is not defined for filter "' . $filter . '".');
                }
                $o = array_merge(['accept' => 'item', 'call' => 'param'], $data['options'][$option]);
                $ref = $o['reference'];
                if (!isset($params[$ref])) {
                    $params[$ref] = [];
                }
                if (isset($o['method']) && $o['call'] == 'param') {
                    $o['call'] = 'method';
                }
                if (!isset($o['method']) && $o['call'] == 'method') {
                    $o['method'] = $option;
                }
                if ($o['accept'] == 'items') {
                    if (!is_array($value)) {
                        throw new InvalidConfigException('Expects option "' . $option . '" to be array, ' .
                            gettype($value) . ' given in filter "' . $filter . '".');
                    }
                }
                if (isset($o['filter'])) {
                    if ($o['accept'] == 'items') {
                        foreach ($value as $k => &$v) {
                            $v = $o['filter']($v);
                        }
                    }
                    else {
                        $value = $o['filter']($value);
                    }
                }
                switch ($o['call']) {
                    case 'compact':
                        $key = isset($o['method']) ? 'method' : 'param';
                        if (!isset($params[$ref][$key])) {
                            $params[$ref][$key] = [];
                        }
                        if (isset($o['method'])) {
                            if (!isset($params[$ref][$key][$o['method']])) {
                                $params[$ref][$key][$o['method']] = [$option => $value];
                            } else {
                                array_push($params[$ref][$key][$o['method']], [$option => $value]);
                            }
                        } else {
                            $params[$ref][$key] = array_merge_recursive($params[$ref][$key], [$option => $value]);
                        }
                        break;
                    case 'method':
                        if (!isset($params[$ref]['method'])) {
                            $params[$ref]['method'] = [];
                        }
                        $params[$ref]['method'][] = [$o['method'], $value];
                        break;
                    case 'property':
                        if (!isset($params[$ref]['property'])) {
                            $params[$ref]['property'] = [];
                        }
                        $params[$ref]['property'][isset($o['property']) ? $o['property'] : $option] = $value;
                        break;
                    case 'param':
                        $params[$ref]['param'] = $value;
                        break;
                }
            }
        }
        foreach (['parser', 'renderer', 'filter'] as $type) {
            if (isset($data[$type])) {
                $args = [];
                if ($type == 'filter') {
                    array_push($args, $data['parser']);
                    if (isset($data['renderer'])) {
                        array_push($args, $data['renderer']);
                    }
                }
                if (isset($params[$type]['param'])) {
                    if (isset($data[$type.'_params_offset'])) {
                        $args += $data[$type.'_params_offset'];
                    }
                    array_push($args, $params[$type]['param']);
                }
                $object = (new ReflectionClass($data[$type]))->newInstanceArgs($args);
                if (!empty($params[$type]['method'])) {
                    foreach ($params[$type]['method'] as $name => $opt) {
                        if (is_numeric($name)) {
                            $object->$opt[0]($opt[1]);
                        } else {
                            $object->$name($opt);
                        }
                    }
                }
                if (!empty($params[$type]['property'])) {
                    foreach ($params[$type]['property'] as $property => $value) {
                        $object->$property = $value;
                    }
                }
                $data[$type] = $object;
            }
        }
        if (isset($params['self']) && !empty($params['self']['method'])) {
            foreach ($params['self']['method'] as $name => $opt) {
                if (is_numeric($name)) {
                    $this->$opt[0]($data, $opt[1]);
                } else {
                    $this->$name($data, $opt);
                }
            }
        }
        return $data['filter'];
    }
1028922
public function setFilter($name, FilterInterface $filter = null)
    {
        $this->filters[$name] = $filter;

        return $this;
    }
1216765
public function addHeader($name, $options)
    {
        $header = new Header($name, $options);
        $header->setTable($this);
        $this->headersObjects[$name] = $header;
    }
649379
public function compileCheckboxOptions($filter, $options)
    {
        $allOptionsOfCurrentFilter = $filter['options'];

        // alphabetical sorting of filter options
        if ($filter['alphabeticalsorting'] == 1) {
            $this->sortArrayByColumn($allOptionsOfCurrentFilter, 'title');
        }

        // loop through options
        $checkboxOptions = array();
        if (is_array($allOptionsOfCurrentFilter)) {
            foreach ($allOptionsOfCurrentFilter as $key => $data) {
                $data['key'] = $key;

                // check if current option (of searchresults) is in array of all possible options
                $isOptionInOptionArray = false;
                if (is_array($options)) {
                    foreach ($options as $optionInResultList) {
                        if ($optionInResultList['value'] == $data['tag']) {
                            $isOptionInOptionArray = true;
                            $data['results'] = $optionInResultList['results'];
                            break;
                        }
                    }
                }

                // if option is in optionArray, we have to mark the checkboxes
                if ($isOptionInOptionArray) {
                    // if user has selected a checkbox it must be selected on the resultpage, too.
                    // options which have been preselected in the backend are
                    // already in $this->piVars['filter'][$filter['uid]]
                    if ($this->piVars['filter'][$filter['uid']][$key]) {
                        $data['selected'] = 1;
                    }

                    // mark all checkboxes if that config options is set and no search string was given and there
                    // are no preselected filters given for that filter
                    if ($this->isEmptySearch
                        && $filter['markAllCheckboxes']
                        && empty($this->preselectedFilter[$filter['uid']])
                    ) {
                        $data['selected'] = 1;
                    }
                } else { // if an option was not found in the search results
                    $data['disabled'] = 1;
                }

                $data['id'] = 'filter_' . $filter['uid'] . '_' . $key;
                $checkboxOptions[] = $data;
            }
        }

        // modify filter options by hook
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyFilterOptions'])) {
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyFilterOptions'] as $_classRef) {
                $_procObj = &GeneralUtility::makeInstance($_classRef);
                $_procObj->modifyFilterOptions($filter, $checkboxOptions, $this);
            }
        }

        return $checkboxOptions;
    }
934922
protected function applyFilter($name, $value, $options = [])
    {
        // If the filter does not exist, throw an Exception:
        if (!isset($this->filters[$name])) {
            throw new InvalidArgumentException("No filter found by the name of $name");
        }

        $filter = $this->filters[$name];
        if ($filter instanceof Closure) {
            return call_user_func_array($filter, [$value, $options]);
        } else {
            $filter = new $filter;
            return $filter->apply($value, $options);
        }
    }
1121646
public function add_filter($field, $filter) {

		if(!is_callable($filter)) return $this;

		if(!isset($this->filters[$field])) $this->filters[$field] = array();
		$this->filters[$field][] = $filter;

		return $this;

	}
1071270
public function createFilter($name, $type = null, array $options = [])
    {
        $this->preventIfLocked();

        if (null !== $type) {
            return $this->getFactory()->createFilterBuilder($name, $type, $options);
        }

        throw new \InvalidArgumentException('Filter type guessing is not yet supported.');
        // TODO return $this->getFormFactory()->createFilterBuilderForProperty($this->getDataClass(), $name, $options);
    }
993372
public function addFilter(AbstractQuery $filter, string $name = null): self
    {
        $filterArray = [];

        $type = self::NAMED_TYPE;

        if (null === $name) {
            $filterArray[] = $filter;
            $type = self::ANONYMOUS_TYPE;
        } else {
            $filterArray[$name] = $filter;
        }

        if ($this->hasParam('filters')
            && \count($this->getParam('filters'))
            && $this->_type !== $type
        ) {
            throw new InvalidException('Mix named and anonymous keys are not allowed');
        }

        $this->_type = $type;

        return $this->addParam('filters', $filterArray);
    }
623779
public static function addFilter(array $filters, array $filterArray, string $key, string $name): array
    {
        if (isset($filterArray[$name][$key])) {
            unset($filterArray[$name][$key]);
        }
        if (sizeof($filterArray[$name]) > 0) {
            $filters['filter']['bool']['must'][] = $filterArray;
        }

        return $filters;
    }
431331
public function findOneAndDelete(array $filter, array $options = [])
    {
        $options = ['remove' => true] + FindOneAndDeleteResolver::resolveStatic($options);

        return $this->findAndModify($filter, $options);
    }
979244
public function add($filter)
    {
        if (is_array($filter)) {
            $this->collection[] = new Filter($filter);
        } elseif (is_object($filter) && $filter instanceof Filter) {
            $this->collection[] = $filter;
        }

        return $this;
    }
374754
public function filter($name, array $options = [])
    {
        if (static::EXT_FILTER === parent::filter($name, $options) and isset($this->filters[$name])) {
            $filter = new $this->filters[$name]($this, $options);

            $filterResults = $filter->run();

            if (!empty($filterResults)) {
                $this->commands = array_merge($this->commands, (array)$filterResults);
            }
        }
    }
435247
public function prependAfterFilter($filter, array $options = [])
    {
        array_unshift($this->afterFilters, $this->parseFilter($filter, $options));
    }
217026
public function add($name, $filter, array $options = [])
    {
        $this->_collection()->add($name, $filter, $options);

        return $this;
    }