Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function preprocessElement(Element $element, Variables $variables)
 {
     // Set errors flag.
     $variables['errors'] = $element->hasProperty('has_error');
     if ($element->getProperty('autocomplete_route_name')) {
         $variables['is_autocomplete'] = TRUE;
     }
     // See http://getbootstrap.com/css/#forms-controls.
     $checkbox = $variables['is_checkbox'] = $element->isType('checkbox');
     $radio = $variables['is_radio'] = $element->isType('radio');
     // Determine if the form element should have the "form-group" class added.
     // Use an explicitly set property from the element or use its other
     // properties as the criteria to determine if it should be set.
     $variables['is_form_group'] = $element->getProperty('form_group', !$variables['is_checkbox'] && !$variables['is_radio'] && !$element->isType(['hidden', 'textarea']));
     // Add label_display and label variables to template.
     $display = $variables['label_display'] = $variables['title_display'] = $element->getProperty('title_display');
     // Place single checkboxes and radios in the label field.
     if (($checkbox || $radio) && $display !== 'none' && $display !== 'invisible') {
         $label = Element::create($variables['label']);
         $children =& $label->getProperty('children', '');
         $children .= $variables['children'];
         unset($variables['children']);
         // Pass the label attributes to the label, if available.
         if ($element->hasProperty('label_attributes')) {
             $label->setAttributes($element->getProperty('label_attributes'));
         }
     }
     // Remove the #field_prefix and #field_suffix values set in
     // template_preprocess_form_element(). These are handled at the input level.
     // @see \Drupal\bootstrap\Plugin\Preprocess\Input::preprocess().
     unset($variables['prefix']);
     unset($variables['suffix']);
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function preprocessElement(Element $element, Variables $variables)
 {
     $link = $element->getProperty('link');
     $link += ['localized_options' => []];
     $link['localized_options']['set_active_class'] = TRUE;
     $icon = Bootstrap::glyphiconFromString($link['title']);
     $options = isset($link['localized_options']) ? $link['localized_options'] : [];
     if (isset($link['url'])) {
         // Turn link into a mini-button and colorize based on title.
         $class = Bootstrap::cssClassFromString($link['title'], 'default');
         if (!isset($options['attributes']['class'])) {
             $options['attributes']['class'] = [];
         }
         $string = is_string($options['attributes']['class']);
         if ($string) {
             $options['attributes']['class'] = explode(' ', $options['attributes']['class']);
         }
         $options['attributes']['class'][] = 'btn';
         $options['attributes']['class'][] = 'btn-xs';
         $options['attributes']['class'][] = 'btn-' . $class;
         if ($string) {
             $options['attributes']['class'] = implode(' ', $options['attributes']['class']);
         }
         $variables['link'] = ['#type' => 'link', '#title' => SafeMarkup::format(\Drupal::service('renderer')->render($icon) . '@text', ['@text' => $link['title']]), '#options' => $options, '#url' => $link['url']];
     } else {
         $variables['link'] = ['#type' => 'link', '#title' => $link['title'], '#options' => $options, '#url' => $link['url']];
     }
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function preprocessElement(Element $element, Variables $variables)
 {
     $variables->addClass(['image-widget', 'js-form-managed-file', 'form-managed-file', 'clearfix']);
     $data =& $variables->offsetGet('data', []);
     foreach ($element->children() as $key => $child) {
         // Modify the label to be a placeholder instead.
         if ($key === 'alt') {
             $child->setProperty('form_group', FALSE);
             $placeholder = (string) $child->getAttribute('placeholder');
             if (!$placeholder) {
                 $label = ['#theme' => 'form_element_label'];
                 $label += array_intersect_key($child->getArray(), array_flip(['#id', '#required', '#title', '#title_display']));
                 $child->setProperty('title_display', 'invisible');
                 $placeholder = trim(strip_tags(Element::create($label)->render()));
                 if ($child->getProperty('required')) {
                     $child->setProperty('description', t('@description (Required)', ['@description' => $child->getProperty('description')]));
                 }
             }
             if ($placeholder) {
                 $child->setAttribute('placeholder', $placeholder);
             }
         }
         $data[$key] = $child->getArray();
     }
 }
Esempio n. 4
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);
     }
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public static function processElement(Element $element, FormStateInterface $form_state, array &$complete_form)
 {
     foreach ($element->children() as $child) {
         if ($child->isPropertyEmpty('icon')) {
             $child->setIcon();
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function preprocessElement(Element $element, Variables $variables)
 {
     // Wrap header columns in label element for Bootstrap.
     if ($variables['multiple']) {
         $header = [['data' => ['#prefix' => '<label class="label">', 'title' => ['#markup' => $element->getProperty('title')], '#suffix' => '</label>'], 'colspan' => 2, 'class' => ['field-label', !empty($element['#required']) ? 'form-required' : '']], t('Order', [], ['context' => 'Sort order'])];
         $variables['table']['#header'] = $header;
     }
 }
Esempio n. 7
0
 /**
  * {@inheritdoc}
  */
 public function preprocessElement(Element $element, Variables $variables)
 {
     // Create variables for #input_group and #input_group_button flags.
     $variables['input_group'] = $element->getProperty('input_group') || $element->getProperty('input_group_button');
     // Map the element properties.
     $variables->map(['attributes' => 'attributes', 'field_prefix' => 'prefix', 'field_suffix' => 'suffix']);
     // Ensure attributes are proper objects.
     $this->preprocessAttributes();
 }
Esempio n. 8
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}");
     }
 }
Esempio n. 9
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}");
     }
 }
Esempio n. 10
0
 /**
  * {@inheritdoc}
  */
 public function preprocessElement(Element $element, Variables $variables)
 {
     $element->map(['id', 'name', 'value', 'type']);
     // Autocomplete.
     if ($route = $element->getProperty('autocomplete_route_name')) {
         $variables['autocomplete'] = TRUE;
     }
     // Create variables for #input_group and #input_group_button flags.
     $variables['input_group'] = $element->getProperty('input_group') || $element->getProperty('input_group_button');
     // Map the element properties.
     $variables->map(['attributes' => 'attributes', 'icon' => 'icon', 'field_prefix' => 'prefix', 'field_suffix' => 'suffix', 'type' => 'type']);
     // Ensure attributes are proper objects.
     $this->preprocessAttributes();
 }
Esempio n. 11
0
 /**
  * {@inheritdoc}
  */
 public function preprocessElement(Element $element, Variables $variables)
 {
     $element->colorize();
     $element->setButtonSize();
     $element->setIcon($element->getProperty('icon'));
     $variables['icon_only'] = $element->getProperty('icon_only');
     $variables['label'] = $element->getProperty('value');
     if ($element->getProperty('split')) {
         $variables->map([$variables::SPLIT_BUTTON]);
     }
     parent::preprocessElement($element, $variables);
 }
Esempio n. 12
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);
     }
 }
Esempio n. 13
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;
     }
 }
Esempio n. 14
0
 /**
  * {@inheritdoc}
  */
 protected function preprocessVariables(Variables $variables, $hook, array $info)
 {
     // Retrieve the ID, generating one if needed.
     $id = $variables->getAttribute('id', Html::getUniqueId($variables->offsetGet('id', 'bootstrap-carousel')));
     unset($variables['id']);
     // Build slides.
     foreach ($variables->slides as $key => &$slide) {
         if (!isset($slide['attributes'])) {
             $slide['attributes'] = [];
         }
         $slide['attributes'] = new Attribute($slide['attributes']);
     }
     // Build controls.
     if ($variables->controls) {
         $left_icon = Bootstrap::glyphicon('chevron-left');
         $right_icon = Bootstrap::glyphicon('chevron-right');
         $url = Url::fromUserInput("#{$id}");
         $variables->controls = ['left' => ['#type' => 'link', '#title' => new FormattableMarkup(Element::create($left_icon)->render() . '<span class="sr-only">@text</span>', ['@text' => t('Previous')]), '#url' => $url, '#attributes' => ['class' => ['left', 'carousel-control'], 'role' => 'button', 'data-slide' => 'prev']], 'right' => ['#type' => 'link', '#title' => new FormattableMarkup(Element::create($right_icon)->render() . '<span class="sr-only">@text</span>', ['@text' => t('Next')]), '#url' => $url, '#attributes' => ['class' => ['right', 'carousel-control'], 'role' => 'button', 'data-slide' => 'next']]];
     }
     // Build indicators.
     if ($variables->indicators) {
         $variables->indicators = ['#theme' => 'item_list__bootstrap_carousel_indicators', '#list_type' => 'ol', '#items' => array_keys($variables->slides), '#target' => "#{$id}", '#start_index' => $variables->start_index];
     }
     // Ensure all attributes are proper objects.
     $this->preprocessAttributes($variables, $hook, $info);
 }
Esempio n. 15
0
 /**
  * {@inheritdoc}
  */
 public function preprocessElement(Variables $variables, $hook, array $info)
 {
     // Set errors flag.
     $variables['errors'] = $variables->element->hasProperty('has_error');
     if ($variables->element->getProperty('autocomplete_route_name')) {
         $variables['is_autocomplete'] = TRUE;
     }
     // See http://getbootstrap.com/css/#forms-controls.
     $checkbox = $variables['is_checkbox'] = $variables->element->isType('checkbox');
     $radio = $variables['is_radio'] = $variables->element->isType('radio');
     $variables['is_form_group'] = !$variables['is_checkbox'] && !$variables['is_radio'] && !$variables->element->isType('hidden');
     // Add label_display and label variables to template.
     $display = $variables['label_display'] = $variables['title_display'] = $variables->element->getProperty('title_display');
     // Place single checkboxes and radios in the label field.
     if (($checkbox || $radio) && $display !== 'none' && $display !== 'invisible') {
         $label = Element::create($variables['label']);
         $children =& $label->getProperty('children', '');
         $children .= $variables['children'];
         unset($variables['children']);
         // Pass the label attributes to the label, if available.
         if ($variables->element->hasProperty('label_attributes')) {
             $label->setAttributes($variables->element->getProperty('label_attributes'));
         }
     }
     // Remove the #field_prefix and #field_suffix values set in
     // template_preprocess_form_element(). These are handled on the input level.
     // @see \Drupal\bootstrap\Plugin\Preprocess\Input::preprocess().
     if ($variables->element->hasProperty('input_group') || $variables->element->hasProperty('input_group_button')) {
         $variables['prefix'] = FALSE;
         $variables['suffix'] = FALSE;
     }
 }
Esempio n. 16
0
 /**
  * {@inheritdoc}
  */
 public function preprocessElement(Variables $variables, $hook, array $info)
 {
     $variables->element->map(['id', 'name', 'value', 'type']);
     // Autocomplete.
     if ($route = $variables->element->getProperty('autocomplete_route_name')) {
         $variables['autocomplete'] = TRUE;
         // Use an icon for autocomplete "throbber".
         $icon = Bootstrap::glyphicon('refresh', ['#type' => 'html_tag', '#tag' => 'span', '#attributes' => ['class' => ['ajax-progress', 'ajax-progress-throbber', 'invisible']], 'throbber' => ['#type' => 'html_tag', '#tag' => 'span', '#attributes' => ['class' => ['throbber']]]]);
         $variables->element->setProperty('input_group', TRUE);
         $variables->element->setProperty('field_suffix', $icon);
     }
     // Create variables for #input_group and #input_group_button flags.
     $variables['input_group'] = $variables->element->getProperty('input_group') || $variables->element->getProperty('input_group_button');
     if ($variables['input_group']) {
         $input_group_attributes = ['class' => ['input-group-' . ($variables->element->getProperty('input_group_button') ? 'btn' : 'addon')]];
         if ($prefix = $variables->element->getProperty('field_prefix')) {
             $variables->element->setProperty('field_prefix', ['#type' => 'html_tag', '#tag' => 'span', '#attributes' => $input_group_attributes, '#value' => Element::create($prefix)->render(), '#weight' => -1]);
         }
         if ($suffix = $variables->element->getProperty('field_suffix')) {
             $variables->element->setProperty('field_suffix', ['#type' => 'html_tag', '#tag' => 'span', '#attributes' => $input_group_attributes, '#value' => Element::create($suffix)->render(), '#weight' => 1]);
         }
     }
     // Map the element properties.
     $variables->map(['attributes' => 'attributes', 'icon' => 'icon', 'field_prefix' => 'prefix', 'field_suffix' => 'suffix', 'type' => 'type']);
     // Ensure attributes are proper objects.
     $this->preprocessAttributes($variables, $hook, $info);
 }
Esempio n. 17
0
 /**
  * {@inheritdoc}
  */
 public static function processElement(Element $element, FormStateInterface $form_state, array &$complete_form)
 {
     $dropbuttons = Element::create();
     foreach ($element->children(TRUE) as $key => $child) {
         if ($dropbutton = $child->getProperty('dropbutton')) {
             // If there is no dropbutton for this button group yet, create one.
             if (!isset($dropbuttons->{$dropbutton})) {
                 $dropbuttons->{$dropbutton} = ['#type' => 'dropbutton'];
             }
             $dropbuttons[$dropbutton]['#links'][$key] = $child->getArray();
             // Remove original child from the element so it's not rendered twice.
             $child->setProperty('printed', TRUE);
         }
     }
     $element->exchangeArray($dropbuttons->getArray() + $element->getArray());
 }
Esempio n. 18
0
 /**
  * {@inheritdoc}
  */
 public static function process(array $element, FormStateInterface $form_state, array &$complete_form)
 {
     if (!empty($element['#bootstrap_ignore_process'])) {
         return $element;
     }
     static::processElement(Element::create($element), $form_state, $complete_form);
     return $element;
 }
Esempio n. 19
0
 /**
  * {@inheritdoc}
  */
 public function alterForm(array &$form, FormStateInterface $form_state, $form_id = NULL)
 {
     $e = Element::create($form, $form_state);
     $e->advanced->setProperty('collapsible', TRUE);
     $e->advanced->setProperty('collapsed', TRUE);
     $e->basic->removeClass('container-inline');
     $e->basic->submit->setProperty('icon_only', TRUE);
     $e->basic->keys->setProperty('input_group_button', TRUE);
 }
Esempio n. 20
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.'));
     }
 }
Esempio n. 21
0
 /**
  * Maps an element's properties to the variables attributes array.
  *
  * @param array $map
  *   An associative array whose keys are element property names and whose
  *   values are the variable names to set in the variables array; e.g.,
  *   array('#property_name' => 'variable_name'). If both names are identical
  *   except for the leading '#', then an attribute name value is sufficient
  *   and no property name needs to be specified.
  * @param bool $overwrite
  *   If the variable exists, it will be overwritten. This does not apply to
  *   attribute arrays, they will always be merged recursively.
  *
  * @return $this
  */
 public function map(array $map, $overwrite = TRUE)
 {
     // Immediately return if there is no element in the variable array.
     if (!$this->element) {
         return $this;
     }
     // Iterate over each map item.
     foreach ($map as $property => $variable) {
         // If the key is numeric, the attribute name needs to be taken over.
         if (is_int($property)) {
             $property = $variable;
         }
         // Merge attributes from the element.
         if (strpos($property, 'attributes') !== FALSE) {
             $this->setAttributes($this->element->getAttributes($property)->getArrayCopy(), $variable);
         } elseif ($overwrite || !$this->offsetExists($variable)) {
             $this->offsetSet($variable, $this->element->getProperty($property));
         }
     }
     return $this;
 }
Esempio n. 22
0
 /**
  * Pre-render render array element callback.
  *
  * @param array $element
  *   The render array element.
  *
  * @return array
  *   The modified render array element.
  */
 public static function preRender(array $element)
 {
     if (!empty($element['#bootstrap_ignore_pre_render'])) {
         return $element;
     }
     $e = Element::create($element);
     if ($e->isType('machine_name')) {
         $e->addClass('form-inline', 'wrapper_attributes');
     }
     // Add smart descriptions to the element, if necessary.
     $e->smartDescription();
     return $element;
 }
Esempio n. 23
0
 /**
  * {@inheritdoc}
  */
 public function alter(&$suggestions, &$variables = NULL, &$hook = NULL)
 {
     switch ($hook) {
         case 'fieldset':
         case 'details':
             $suggestions[] = 'bootstrap_panel';
             break;
         case 'input':
             $element = Element::create($variables['element']);
             if ($element->isButton()) {
                 $suggestions[] = 'input__button';
             } elseif (!$element->isType(['checkbox', 'hidden', 'radio'])) {
                 $suggestions[] = 'input__form_control';
             }
             break;
     }
 }
Esempio n. 24
0
 /**
  * {@inheritdoc}
  */
 public function preprocessVariables(Variables $variables, $hook, array $info)
 {
     if ($variables->theme_hook_original === 'links' && $variables->hasClass('operations')) {
         $variables->addClass('list-inline');
         foreach ($variables->links as &$data) {
             $link = Element::create($data['link']);
             $link->addClass(['btn', 'btn-sm']);
             $link->colorize();
             $link->setIcon();
             if ($this->theme->getSetting('tooltip_enabled')) {
                 $link->setAttribute('data-toggle', 'tooltip');
                 $link->setAttribute('data-placement', 'bottom');
             }
         }
     }
     $this->preprocessAttributes($variables, $hook, $info);
 }
Esempio n. 25
0
 /**
  * {@inheritdoc}
  */
 protected function preprocessElement(Variables $variables, $hook, array $info)
 {
     // Assign the ID, if not already set.
     $variables->element->map(['id']);
     // Add necessary classes.
     $variables->element->addClass(['form-item', 'js-form-item', 'form-wrapper', 'js-form-wrapper']);
     $body = [];
     $properties = ['field_prefix', 'body', 'children'];
     // Only add the #value property if it's a "details" or "fieldset" element
     // type. Some form elements may use "CompositeFormElementTrait" which
     // will inadvertently and eventually become preprocessed here and #value
     // may actually be the element's value instead of a renderable element.
     if ($variables->element->isType(['details', 'fieldset'])) {
         $properties[] = 'value';
     }
     // Add the "#field_suffix" property.
     $properties[] = 'field_suffix';
     // Merge all possible content from the element into a single render array.
     foreach ($properties as $property) {
         $body[$property] = Element::create($variables->element->getProperty($property, []))->getArray();
     }
     $variables['body'] = array_filter($body);
     $map = ['attributes' => 'attributes', 'body_attributes' => 'body_attributes', 'content_attributes' => 'body_attributes', 'description' => 'description', 'description_attributes' => 'description_attributes', 'description_display' => 'description_display', 'errors' => 'errors', 'footer' => 'footer', 'required' => 'required', 'panel_state' => 'panel_state', 'title' => 'heading', 'title_attributes' => 'heading_attributes'];
     // Handle specific "details" elements.
     if ($variables->element->isType('details')) {
         // Details are always collapsible per the HTML5 spec.
         // @see https://www.drupal.org/node/1852020
         $variables['collapsible'] = TRUE;
         // Determine the collapsed state.
         $variables['collapsed'] = !$variables->element->getProperty('open', TRUE);
         // Remove the unnecessary details attribute.
         $variables->element->removeAttribute('open');
     } elseif ($variables->element->isType('fieldset')) {
         // Override variables to mimic the default "fieldset" element info.
         // They will be mapped below if they exist on the element.
         unset($variables['collapsible'], $variables['collapsed']);
         $map['collapsed'] = 'collapsed';
         $map['collapsible'] = 'collapsible';
     }
     // Map the element properties to the variables array.
     $variables->map($map);
 }
 /**
  * {@inheritdoc}
  */
 public function alterForm(array &$form, FormStateInterface $form_state, $form_id = NULL)
 {
     $e = Element::create($form, $form_state);
     $e->addClass(['form-inline', 'bg-info', 'text-center', 'clearfix']);
     // Backlink.
     $options = $e->backlink->getProperty('options', []);
     $e->backlink->addClass(isset($options['attributes']['class']) ? $options['attributes']['class'] : []);
     $e->backlink->addClass(['btn', 'btn-info', 'pull-left']);
     $e->backlink->setButtonSize();
     $e->backlink->setIcon(Bootstrap::glyphicon('chevron-left'));
     // Ensure the UUID is set.
     if ($uuid = $e->uuid->getProperty('value')) {
         $options['query'] = ['uuid' => $uuid];
     }
     // Override the options attributes.
     $options['attributes'] = $e->backlink->getAttributes()->getArrayCopy();
     $e->backlink->setProperty('options', $options);
     // View mode.
     $e->view_mode->addClass('pull-right', $e::WRAPPER);
 }
Esempio n. 27
0
 /**
  * Sets up the vertical tab groupings.
  *
  * @param array $form
  *   Nested array of form elements that comprise the form.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  */
 protected function createGroups(array &$form, FormStateInterface $form_state)
 {
     $f = Element::create($form, $form_state);
     // Vertical tabs for global settings provided by core or contrib modules.
     if (!isset($form['global'])) {
         $form['global'] = ['#type' => 'vertical_tabs', '#weight' => -9, '#prefix' => '<h2><small>' . t('Override Global Settings') . '</small></h2>'];
     }
     // Iterate over existing children and move appropriate ones to global group.
     foreach ($f->children() as $child) {
         if ($child->isType(['details', 'fieldset']) && !$child->hasProperty('group')) {
             $child->setProperty('type', 'details');
             $child->setProperty('group', 'global');
         }
     }
     // Provide the necessary default groups.
     $form['bootstrap'] = ['#type' => 'vertical_tabs', '#attached' => ['library' => ['bootstrap/theme-settings']], '#prefix' => '<h2><small>' . t('Bootstrap Settings') . '</small></h2>', '#weight' => -10];
     $groups = ['general' => t('General'), 'components' => t('Components'), 'javascript' => t('JavaScript'), 'advanced' => t('Advanced')];
     foreach ($groups as $group => $title) {
         $form[$group] = ['#type' => 'details', '#title' => $title, '#group' => 'bootstrap'];
     }
 }
Esempio n. 28
0
 /**
  * {@inheritdoc}
  */
 public function preprocessVariables(Variables $variables, $hook, array $info)
 {
     $options = [];
     $file = $variables['file'] instanceof File ? $variables['file'] : File::load($variables['file']->fid);
     $url = file_create_url($file->getFileUri());
     $file_size = $file->getSize();
     $mime_type = $file->getMimeType();
     // Set options as per anchor format described at
     // http://microformats.org/wiki/file-format-examples
     $options['attributes']['type'] = "{$mime_type}; length={$file_size}";
     // Use the description as the link text if available.
     if (empty($variables['description'])) {
         $link_text = $file->getFilename();
     } else {
         $link_text = $variables['description'];
         $options['attributes']['title'] = $file->getFilename();
     }
     // Retrieve the generic mime type from core (mislabeled as "icon_class").
     $generic_mime_type = file_icon_class($mime_type);
     // Map the generic mime types to an icon and state.
     $mime_map = ['application-x-executable' => ['label' => t('binary file'), 'icon' => 'console'], 'audio' => ['label' => t('audio file'), 'icon' => 'headphones'], 'image' => ['label' => t('image'), 'icon' => 'picture'], 'package-x-generic' => ['label' => t('archive'), 'icon' => 'compressed'], 'text' => ['label' => t('document'), 'icon' => 'file'], 'video' => ['label' => t('video'), 'icon' => 'film']];
     // Retrieve the mime map array.
     $mime = isset($mime_map[$generic_mime_type]) ? $mime_map[$generic_mime_type] : ['label' => t('file'), 'icon' => 'file', 'state' => 'primary'];
     // Classes to add to the file field for icons.
     $variables->addClass(['file', 'file--mime-' . strtr($mime_type, ['/' => '-', '.' => '-']), 'file--' . $generic_mime_type]);
     // Set the icon for the mime type.
     $icon = Bootstrap::glyphicon($mime['icon']);
     $variables->icon = Element::create($icon)->addClass('text-primary')->getArray();
     $options['attributes']['title'] = t('Open @mime in new window', ['@mime' => $mime['label']]);
     if ($this->theme->getSetting('tooltip_enabled')) {
         $options['attributes']['data-toggle'] = 'tooltip';
         $options['attributes']['data-placement'] = 'bottom';
     }
     $variables['link'] = Link::fromTextAndUrl($link_text, Url::fromUri($url, $options));
     // Add the file size as a variable.
     $variables->file_size = format_size($file_size);
     // Preprocess attributes.
     $this->preprocessAttributes($variables, $hook, $info);
 }
Esempio n. 29
0
 /**
  * {@inheritdoc}
  */
 public function preprocessVariables(Variables $variables, $hook, array $info)
 {
     if ($variables->theme_hook_original === 'links' && $variables->hasClass('operations')) {
         $variables->addClass('list-inline');
         foreach ($variables->links as &$data) {
             $link = Element::create($data['link']);
             $link->addClass(['btn', 'btn-sm']);
             $link->colorize();
             $link->setIcon();
             if ($icon = $link->getProperty('icon')) {
                 $link->addClass('icon-before');
                 $title = ['icon' => $icon, 'title' => ['#markup' => $link->getProperty('title')]];
                 $link->setProperty('title', Element::create($title));
             }
             if (($options =& $link->getProperty('options', [])) && isset($options['attributes']['title'])) {
                 $link->setAttribute('data-toggle', 'tooltip');
                 $link->setAttribute('data-placement', 'bottom');
             }
         }
     }
     $this->preprocessAttributes($variables, $hook, $info);
 }
Esempio n. 30
0
 /**
  * Traverses an element to find the closest button.
  *
  * @param \Drupal\bootstrap\Utility\Element $element
  *   The element to iterate over.
  *
  * @return \Drupal\bootstrap\Utility\Element|FALSE
  *   The first button element or FALSE if no button could be found.
  */
 protected static function &findButton(Element $element)
 {
     $button = FALSE;
     foreach ($element->children() as $child) {
         if ($child->isButton()) {
             $button = $child;
         }
         if ($result =& self::findButton($child)) {
             $button = $result;
         }
     }
     return $button;
 }