S
S
symnoob2019-10-27 13:46:23
symfony
symnoob, 2019-10-27 13:46:23

Symfony 4 - Can anyone help with creating a bundle config?

Hello everyone,
who can help with the creation of the bundle config?
At the last step in checking "language:" I have a problem.
here it is somehow necessary to add smartly that in the parameter: 'ru, en ...' either an array or a string is expected,
that is, such a check is needed that would check the yaml itself.
So that it is checked for the scheme, as it were:
there is a filter; the Filter has values ​​\u200b\u200b(Array) they have values ​​\u200b\u200b(Array) Languages ​​\u200b\u200btexts also have values ​​\u200b\u200b(Array), for example, Russian, English, etc. ..
but these can have either a simple array or a string .
There can be a lot of filters, but they are all built according to this scheme, branching only in
yaml languages:

search:
  filter:
    product:
      language:
        ru: ['страховка', 'дом', 'camping']
        en: ['insurance', 'house', 'camping']
    page:
      language:
        ru: 'страница:*'
        en: 'page:*'
    price_until:
      language:
        ru: 'цена-до:*'
        en: 'price-until:*'

Configuration.php:
<?php

namespace Ferien\Bundle\SearchBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder('ferien_search');
        $treeBuilder->getRootNode()
        ->children()
            ->arrayNode('filter')
                ->isRequired()
                ->requiresAtLeastOneElement()
                ->useAttributeAsKey('name')
                ->prototype('array')
                    ->children()
                        ->arrayNode('language')
                            ->isRequired()
                            ->requiresAtLeastOneElement()
                            ->useAttributeAsKey('name')
                            ->prototype('array')
                                ->children()
                                ->end()
                            ->end()
                        ->end()
                    ->end()
                ->end()
            ->end()
        ->end();

        return $treeBuilder;
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question