This method is applicable to prototype nodes only.
public requiresAtLeastOneElement ( ) : |
||
Результат |
protected function getMultipleQueuesConfiguration() { $node = new ArrayNodeDefinition('queues'); $prototypeNode = $node->requiresAtLeastOneElement()->prototype('array'); $this->addQueueNodeConfiguration($prototypeNode); $prototypeNode->children()->scalarNode('callback')->isRequired()->end()->end(); $prototypeNode->end(); return $node; }
/** * Builds filter config tree for given filter name. * * @param string $filterName * * @return ArrayNodeDefinition */ private function buildFilterTree($filterName) { $filter = new ArrayNodeDefinition($filterName); /** @var ParentNodeDefinitionInterface $node */ $node = $filter->requiresAtLeastOneElement()->useAttributeAsKey('name')->prototype('array')->children()->scalarNode('name')->end()->arrayNode('relations')->children()->append($this->buildRelationsTree('search'))->append($this->buildRelationsTree('reset'))->end()->end()->scalarNode('request_field')->info('URL parameter name.')->isRequired()->end()->scalarNode('field')->info('Document field name.')->end()->arrayNode('tags')->info('Filter tags that will be passed to view data.')->prototype('scalar')->end()->end()->end(); switch ($filterName) { case 'choice': case 'multi_choice': $node->children()->integerNode('size')->info('Result size to return.')->end()->arrayNode('sort')->children()->enumNode('type')->values(['_term', '_count'])->defaultValue('_term')->end()->enumNode('order')->values(['asc', 'desc'])->defaultValue('asc')->end()->arrayNode('priorities')->prototype('scalar')->end()->end()->end()->end(); break; case 'fuzzy': $node->children()->scalarNode('fuzziness')->info('The maximum edit distance.')->end()->integerNode('prefix_length')->info('The number of initial characters which will not be “fuzzified”. This helps to reduce the number of terms which must be examined.')->end()->integerNode('max_expansions')->info('The maximum number of terms that the fuzzy query will expand to.')->end()->end(); break; case 'sort': $node->children()->arrayNode('choices')->prototype('array')->beforeNormalization()->always(function ($v) { if (empty($v['fields']) && !empty($v['field'])) { $field = ['field' => $v['field']]; if (array_key_exists('order', $v)) { $field['order'] = $v['order']; } if (array_key_exists('mode', $v)) { $field['mode'] = $v['mode']; } $v['fields'][] = $field; } if (empty($v['label'])) { $v['label'] = $v['fields'][0]['field']; } return $v; })->end()->addDefaultsIfNotSet()->children()->scalarNode('label')->end()->scalarNode('field')->end()->scalarNode('order')->defaultValue('asc')->end()->scalarNode('mode')->defaultNull()->end()->scalarNode('key')->info('Custom parameter value')->end()->booleanNode('default')->defaultFalse()->end()->arrayNode('fields')->isRequired()->requiresAtLeastOneElement()->prototype('array')->children()->scalarNode('field')->isRequired()->end()->scalarNode('order')->defaultValue('asc')->end()->scalarNode('mode')->defaultNull()->end()->end()->end()->end()->end()->end()->end(); break; case 'pager': $node->children()->integerNode('count_per_page')->info('Item count per page')->defaultValue(10)->end()->integerNode('max_pages')->info('Max pages displayed in pager at once.')->defaultValue(8)->end()->end(); break; case 'range': case 'date_range': $node->children()->booleanNode('inclusive')->info('Whether filter should match range ends.')->defaultFalse()->end()->end(); break; default: // Should not happen. break; } return $filter; }