Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public static function processElement(Element $element, FormStateInterface $form_state, array &$complete_form)
 {
     $element->setProperty('title_display', 'invisible');
     $element->setAttribute('placeholder', $element->getProperty('placeholder', $element->getProperty('title', t('Search'))));
     if (!$element->hasProperty('description')) {
         $element->setProperty('description', t('Enter the terms you wish to search for.'));
     }
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public static function preRenderElement(Element $element)
 {
     // Injects the icon into the title (the only way this is possible).
     if ($icon =& $element->getProperty('icon')) {
         $title = $element->getProperty('title');
         // Handle #icon_only.
         if ($element->getProperty('icon_only')) {
             if ($attribute_title = $element->getAttribute('title', '')) {
                 $title .= ' - ' . $attribute_title;
             }
             $element->setAttribute('title', $title)->addClass('icon-only')->setProperty('title', $icon);
             if (Bootstrap::getTheme()->getSetting('tooltip_enabled')) {
                 $element->setAttribute('data-toggle', 'tooltip');
             }
             return;
         }
         // Handle #icon_position.
         $position = $element->getProperty('icon_position', 'before');
         // Render #icon and trim it (so it doesn't add underlines in whitespace).
         $rendered_icon = trim(Element::create($icon)->render());
         // Default position is before.
         $markup = "{$rendered_icon}@title";
         if ($position === 'after') {
             $markup = "@title{$rendered_icon}";
         }
         // Replace the title and set an icon position class.
         $element->setProperty('title', new FormattableMarkup($markup, ['@title' => $title]))->addClass("icon-{$position}");
     }
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public static function processElement(Element $element, FormStateInterface $form_state, array &$complete_form)
 {
     $ajax_wrapper_id = $element->upload_button->getProperty('ajax')['wrapper'];
     if ($prefix = $element->getProperty('prefix')) {
         $prefix = preg_replace('/<div id="' . $ajax_wrapper_id . '">/', '<div id="' . $ajax_wrapper_id . '" class="form-group">', $prefix);
         $element->setProperty('prefix', $prefix);
     }
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  */
 public static function preRenderElement(Element $element)
 {
     $element['#attached']['library'][] = 'bootstrap/dropdown';
     // Enable targeted theming of specific dropbuttons (e.g., 'operations' or
     // 'operations__node').
     if ($subtype = $element->getProperty('subtype')) {
         $element->setProperty('theme', $element->getProperty('theme') . "__{$subtype}");
     }
 }
Beispiel #5
0
 /**
  * Processes elements that have input groups.
  *
  * @param \Drupal\bootstrap\Utility\Element $element
  *   The element object.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  * @param array $complete_form
  *   The complete form structure.
  */
 protected static function processInputGroups(Element $element, FormStateInterface $form_state, array &$complete_form)
 {
     // Automatically inject the nearest button found after this element if
     // #input_group_button exists.
     if ($element->getProperty('input_group_button')) {
         // Obtain the parent array to limit search.
         $array_parents = $element->getProperty('array_parents', []);
         // Remove the current element from the array.
         array_pop($array_parents);
         // Retrieve the parent element.
         $parent = Element::create(NestedArray::getValue($complete_form, $array_parents), $form_state);
         // Find the closest button.
         if ($button = self::findButton($parent)) {
             $element->appendProperty('field_suffix', $button->setIcon());
             $button->setProperty('access', FALSE);
         }
     }
     $input_group_attributes = ['class' => ['input-group-' . ($element->getProperty('input_group_button') ? 'btn' : 'addon')]];
     if ($prefix = $element->getProperty('field_prefix')) {
         $element->setProperty('field_prefix', ['#type' => 'html_tag', '#tag' => 'span', '#attributes' => $input_group_attributes, '#value' => Element::create($prefix)->render(), '#weight' => -1]);
     }
     if ($suffix = $element->getProperty('field_suffix')) {
         $element->setProperty('field_suffix', ['#type' => 'html_tag', '#tag' => 'span', '#attributes' => $input_group_attributes, '#value' => Element::create($suffix)->render(), '#weight' => 1]);
     }
 }