Issue #204 new

Cannot configure Bootstrap from config file anymore

Sobit Akhmedov
created an issue

With the new version there's no way to set configuration in config file. For example, I tried this:

'bootstrap' => array(
    'class' => 'ext.bootstrap.components.Bootstrap',
    'plugins' => array(
        'tooltip' => array(
            'selector' => '[rel="tooltip"]',
        ),
        'popover' => array(
            'selector' => '[rel="popover"]',
        ),
    ),
),

But with no success.

Also I wanted not to register responsive template, but there's no way to do it anymore.

Comments (2)

  1. Magnus Klingenberg

    You're missing one level,

            'bootstrap'=>array(
                'class'=>'bootstrap.components.Bootstrap',
                'plugins' => array(
                    'tooltip' => array('options' => array('selector' => 'a[rel=tooltip]')),
                    'popover' => array('options' => array('selector' => 'a[rel=popover]'))
                )
            ),
    

    note the options level.

    Still, not possible since it will be overridden by the explicitly given options when calling Bootstrap::registerPlugin from registerTooltip and registerPopover. I'll attatch a patch that introduces default values for the options which can be overridden.

  2. Magnus Klingenberg

    Got access denied trying to upload the patch.. here it is:

    save it in a file, should apply cleanly on top of #cd1edd9958a2

    diff --git a/components/Bootstrap.php b/components/Bootstrap.php
    --- a/components/Bootstrap.php
    +++ b/components/Bootstrap.php
    @@ -34,6 +34,15 @@
         * @since 0.9.8
         */
        public $plugins = array();
    +
    +   /**
    +    * @var array default values for plugins.
    +    */
    +   protected $_pluginsDefaults = array(
    +       self::PLUGIN_TOOLTIP => array('options' => array('selector' => 'a[rel=tooltip]')),
    +       self::PLUGIN_POPOVER => array('options' => array('selector' => 'a[rel=popover]'))
    +   );
    +
        /**
         * @var boolean indicates whether assets should be republished on every request.
         */
    @@ -222,8 +231,6 @@
        public function registerPopover($selector = null, $options = array())
        {
            $this->registerTooltip(); // Popover requires the tooltip plugin
    -       if (!isset($options['selector']))
    -           $options['selector'] = $selector !== null ? $selector : 'a[rel=popover]';
            $this->registerPlugin(self::PLUGIN_POPOVER, 'body', $options);
        }
    
    @@ -248,8 +255,6 @@
         */
        public function registerTooltip($selector = null, $options = array())
        {
    -       if (!isset($options['selector']))
    -           $options['selector'] = $selector !== null ? $selector : 'a[rel=tooltip]';
            $this->registerPlugin(self::PLUGIN_TOOLTIP, 'body', $options);
        }
    
    @@ -270,13 +275,15 @@
         * @param string $name the name of the plugin
         * @param string $selector the CSS selector
         * @param array $options the plugin options
    -    * @param string $defaultSelector the default CSS selector
         * @since 0.9.8
         */
        protected function registerPlugin($name, $selector = null, $options = array())
        {
    -       // Initialization from extension configuration.
    -       $config = isset($this->plugins[$name]) ? $this->plugins[$name] : array();
    +       // Get default options for plugin.
    +       $config = isset($this->_pluginsDefaults[$name]) ? $this->_pluginsDefaults[$name] : array();
    +
    +       // Override defaults from extension configuration.
    +       $config = isset($this->plugins[$name]) ? CMap::mergeArray($config, $this->plugins[$name]) : $config;
    
            if ($selector === null && isset($config['selector']))
                $selector = $config['selector'];
    
  3. Log in to comment