1

I faced a proble: i need to change vendor bundle configuration. How can i do that correctly?

Vendor bundle config:

namespace Oro\Bundle\DataGridBundle\Extension\Toolbar;

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

use Oro\Bundle\ConfigBundle\Config\ConfigManager;

class Configuration implements ConfigurationInterface
{
    /** @var int */
    private $defaultPerPage;

    /**
     * @param ConfigManager $cm
     */
    public function __construct(ConfigManager $cm)
    {
        $this->defaultPerPage = $cm->get('oro_data_grid.default_per_page');
    }

    /**
     * {@inheritDoc}
     */
    public function getConfigTreeBuilder()
    {
        $builder = new TreeBuilder();

        $builder->root('toolbarOptions')
            ->children()
                ->booleanNode('hide')->defaultFalse()->end()
                ->booleanNode('addResetAction')->defaultTrue()->end()
                ->booleanNode('addRefreshAction')->defaultTrue()->end()
                ->integerNode('turnOffToolbarRecordsNumber')->defaultValue(0)->end()
                ->arrayNode('pageSize')->addDefaultsIfNotSet()
                    ->children()
                        ->booleanNode('hide')->defaultFalse()->end()
                        ->scalarNode('default_per_page')->defaultValue($this->defaultPerPage)->end()
                        ->arrayNode('items')
                            ->defaultValue([10, 25, 50, 100])
                            ->prototype('variable')->end()
                        ->end()
                    ->end()
                ->end()
                ->arrayNode('pagination')
                    ->addDefaultsIfNotSet()
                    ->children()
                        ->booleanNode('hide')->defaultFalse()->end()
                    ->end()
                ->end()
            ->end();

        return $builder;
    }
}

The question is - how can i change ->arrayNode('items') to my custom array without editing bundle configuration.php?

Stepan Yudin
  • 470
  • 3
  • 19
  • Have a look to: `http://symfony.com/doc/current/cookbook/bundles/override.html` – scoolnico Oct 19 '15 at 10:18
  • Why do you need to override this part of the configuration? What are you trying to do? Wouldn't changing the values in your `app/config.yml` work as expected? – Touki Oct 19 '15 at 10:21
  • @Touki because these parameters are not present in config.yml. As i understand - this config tree is built 'on the fly'... – Stepan Yudin Oct 19 '15 at 11:05
  • 1
    @StepanYudin That still doesn't answer the root of your problem. It's very unlikely you have to change the Configuration **definition** of another bundle. What are you trying to achieve, exactly? That `$items` will be your custom-loaded-from-database/parameters.yml array values? Or do you want to you want to change the prototype of items? – Touki Oct 19 '15 at 11:17
  • @Touki, ok, this array simply represents pagination component's 'View per page' values. I just want to add new values 500 and 1000 without changing the bundle's source code – Stepan Yudin Oct 19 '15 at 11:19
  • Then what's wrong with adding these values in your `config.yml`, [like this](http://pastebin.com/N0tXdcYU)? – Touki Oct 19 '15 at 11:26
  • I already tried this. Here is error: **Uncaught exception** 'Symfony\Component\Config\Definition\Exception\InvalidConfigurationException' with message 'Unrecognized option "toolbarOptions" under "oro_data_grid"' in... – Stepan Yudin Oct 19 '15 at 11:58

1 Answers1

1

You do not need to change the configuration builder, just configure it as you want:

bundle_name:
    toolbarOptions:
        pageSize:
            items: [10, 25, 50, 100, 500, 1000]
Gerry
  • 6,012
  • 21
  • 33