Пример #1
0
 /**
  * Preprocess links in the variables array to convert them from dropbuttons.
  *
  * @param \Drupal\bootstrap\Utility\Variables $variables
  *   A variables object.
  */
 protected function preprocessLinks(Variables $variables)
 {
     // Convert "dropbutton" theme suggestion variables.
     if (Unicode::strpos($variables->theme_hook_original, 'links__dropbutton') !== FALSE && !empty($variables->links)) {
         $operations = !!Unicode::strpos($variables->theme_hook_original, 'operations');
         // Normal dropbutton links are not actually render arrays, convert them.
         foreach ($variables->links as &$link) {
             if (isset($link['title']) && $link['url']) {
                 $link = ['#type' => 'link', '#title' => $link['title'], '#url' => $link['url']];
             }
         }
         // Pop off the first link as the "toggle".
         $variables->toggle = array_shift($variables->links);
         $toggle = Element::create($variables->toggle);
         // Convert any toggle links to a proper button.
         if ($toggle->isType('link')) {
             $toggle->exchangeArray(['#type' => 'button', '#value' => $toggle->getProperty('title'), '#attributes' => ['data-url' => $toggle->getProperty('url')->toString()]]);
             if ($operations) {
                 $toggle->setButtonSize('btn-xs');
             }
         } else {
             $toggle->unsetProperty('dropbutton');
         }
         $variables->items = array_values($variables->links);
         $variables->split = TRUE;
         unset($variables->links);
     }
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function alter(&$suggestions, &$variables = NULL, &$hook = NULL)
 {
     switch ($hook) {
         case 'links':
             if (Unicode::strpos($variables['theme_hook_original'], 'links__dropbutton') !== FALSE) {
                 // Handle dropbutton "subtypes".
                 // @see \Drupal\bootstrap\Plugin\Prerender\Dropbutton::preRenderElement()
                 if ($suggestion = Unicode::substr($variables['theme_hook_original'], 17)) {
                     $suggestions[] = 'bootstrap_dropdown' . $suggestion;
                 }
                 $suggestions[] = 'bootstrap_dropdown';
             }
             break;
         case 'fieldset':
         case 'details':
             $suggestions[] = 'bootstrap_panel';
             break;
         case 'input':
             $element = Element::create($variables['element']);
             if ($element->isButton()) {
                 if ($element->getProperty('dropbutton')) {
                     $suggestions[] = 'input__button__dropdown';
                 } else {
                     $suggestions[] = $element->getProperty('split') ? 'input__button__split' : 'input__button';
                 }
             } elseif (!$element->isType(['checkbox', 'hidden', 'radio'])) {
                 $suggestions[] = 'input__form_control';
             }
             break;
     }
 }