示例#1
0
文件: Input.php 项目: 318io/318-io
 /**
  * {@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);
 }
示例#2
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);
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function preprocessVariables(Variables $variables)
 {
     $breadcrumb =& $variables['breadcrumb'];
     // Determine if breadcrumbs should be displayed.
     $breadcrumb_visibility = $this->theme->getSetting('breadcrumb');
     if ($breadcrumb_visibility == 0 || $breadcrumb_visibility == 2 && \Drupal::service('router.admin_context')->isAdminRoute() || empty($breadcrumb)) {
         $breadcrumb = [];
         return;
     }
     // Optionally get rid of the homepage link.
     $show_breadcrumb_home = $this->theme->getSetting('breadcrumb_home');
     if (!$show_breadcrumb_home) {
         array_shift($breadcrumb);
     }
     if ($this->theme->getSetting('breadcrumb_title') && !empty($breadcrumb)) {
         $request = \Drupal::request();
         $route_match = \Drupal::routeMatch();
         $page_title = \Drupal::service('title_resolver')->getTitle($request, $route_match->getRouteObject());
         if (!empty($page_title)) {
             $breadcrumb[] = ['text' => $page_title, 'attributes' => new Attribute(['class' => ['active']])];
             // Add cache context based on url.
             $variables->addCacheContexts(['url']);
         }
     }
 }
示例#4
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();
     }
 }
示例#5
0
 /**
  * {@inheritdoc}
  */
 public function preprocessVariables(Variables $variables)
 {
     // Setup default attributes.
     $variables->getAttributes($variables::NAVBAR);
     $variables->getAttributes($variables::HEADER);
     $variables->getAttributes($variables::CONTENT);
     $variables->getAttributes($variables::FOOTER);
     $this->preprocessAttributes();
 }
示例#6
0
 /**
  * {@inheritdoc}
  */
 public function preprocessVariables(Variables $variables)
 {
     // Ensure a unique ID, generating one if needed.
     $id = $variables->getAttribute('id', Html::getUniqueId($variables->offsetGet('id', 'progress-bar')));
     $variables->setAttribute('id', $id);
     unset($variables['id']);
     // Preprocess attributes.
     $this->preprocessAttributes();
 }
示例#7
0
文件: Select.php 项目: frankcr/sftw8
 /**
  * {@inheritdoc}
  */
 public function preprocessElement(Variables $variables, $hook, array $info)
 {
     // Create variables for #input_group and #input_group_button flags.
     $variables['input_group'] = $variables->element->getProperty('input_group') || $variables->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($variables, $hook, $info);
 }
示例#8
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);
 }
示例#9
0
 /**
  * {@inheritdoc}
  */
 public function preprocessElement(Variables $variables, $hook, array $info)
 {
     $variables->element->colorize();
     $variables->element->setButtonSize();
     $variables->element->setIcon($variables->element->getProperty('icon'));
     $variables['icon_only'] = $variables->element->getProperty('icon_only');
     $variables['label'] = $variables->element->getProperty('value');
     if ($variables->element->getProperty('split')) {
         $variables->map([$variables::SPLIT_BUTTON]);
     }
     parent::preprocessElement($variables, $hook, $info);
 }
 /**
  * {@inheritdoc}
  */
 public function preprocessElement(Variables $variables, $hook, array $info)
 {
     $variables->addClass(['image-widget', 'js-form-managed-file', 'form-managed-file', 'clearfix']);
     /** @var \Drupal\file\Entity\File $file */
     foreach ($variables->element->getProperty('files') as $file) {
         $variables->element->{'file_' . $file->id()}->filename->setProperty('suffix', ' <span class="file-size badge">' . format_size($file->getSize()) . '</span>');
     }
     $data =& $variables->offsetGet('data', []);
     foreach ($variables->element->children() as $key => $child) {
         $data[$key] = $child->getArray();
     }
 }
示例#11
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();
 }
示例#12
0
文件: Links.php 项目: frankcr/sftw8
 /**
  * {@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);
 }
示例#13
0
 /**
  * {@inheritdoc}
  */
 public function preprocess(array &$variables, $hook, array $info)
 {
     $this->hook = $hook;
     $this->info = $info;
     $this->variables = Variables::create($variables);
     if ($this->variables->element) {
         $this->preprocessElement($this->variables->element, $this->variables);
     }
     $this->preprocessVariables($this->variables);
 }
示例#14
0
 /**
  * {@inheritdoc}
  */
 public function preprocessVariables(Variables $variables)
 {
     $region = $variables['elements']['#region'];
     $variables['region'] = $region;
     $variables['content'] = $variables['elements']['#children'];
     // Help region.
     if ($region === 'help' && !empty($variables['content'])) {
         $variables['content'] = ['icon' => Bootstrap::glyphicon('question-sign'), 'content' => ['#markup' => $variables['content']]];
         $variables->addClass(['alert', 'alert-info', 'messages', 'info']);
     }
     // Support for "well" classes in regions.
     static $region_wells;
     if (!isset($region_wells)) {
         $region_wells = $this->theme->getSetting('region_wells');
     }
     if (!empty($region_wells[$region])) {
         $variables->addClass($region_wells[$region]);
     }
 }
示例#15
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-panel')));
     unset($variables['id']);
     // Handle collapsible state.
     if ($variables['heading'] && $variables['collapsible']) {
         // Retrieve the body ID attribute.
         if ($body_id = $variables->getAttribute('id', "{$id}--content", 'body_attributes')) {
             // Ensure the target is set.
             if ($variables['target'] = $variables->offsetGet('target', "#{$body_id}")) {
                 // Set additional necessary attributes to the heading.
                 $variables->setAttributes(['aria-controls' => preg_replace('/^#/', '', $variables['target']), 'aria-expanded' => !$variables['collapsed'] ? 'true' : 'false', 'aria-pressed' => !$variables['collapsed'] ? 'true' : 'false', 'data-toggle' => 'collapse', 'role' => 'button'], 'heading_attributes');
             }
         }
     }
     // Ensure there is a valid panel state.
     if (!$variables->offsetGet('panel_type')) {
         $variables->offsetSet('panel_type', 'default');
     }
     // Convert the description variable.
     $this->preprocessDescription($variables, $hook, $info);
     // Ensure all attributes are proper objects.
     $this->preprocessAttributes($variables, $hook, $info);
 }
示例#16
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);
 }
示例#17
0
文件: Links.php 项目: 318io/318-io
 /**
  * {@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);
 }
示例#18
0
 /**
  * Converts any set description variable into a traversable array.
  *
  * @param \Drupal\bootstrap\Utility\Variables $variables
  *   A variables object.
  * @param string $hook
  *   The name of the theme hook.
  * @param array $info
  *   The theme hook info array.
  *
  * @see https://www.drupal.org/node/2324025
  */
 protected function preprocessDescription(Variables $variables, $hook, array $info)
 {
     if ($variables->offsetGet('description')) {
         // Retrieve the description attributes.
         $description_attributes = $variables->offsetGet('description_attributes', []);
         // Remove standalone description attributes.
         $variables->offsetUnset('description_attributes');
         // Build the description attributes.
         if ($id = $variables->getAttribute('id')) {
             $variables->setAttribute('aria-describedby', "{$id}--description");
             $description_attributes['id'] = "{$id}--description";
         }
         // Replace the description variable.
         $variables->offsetSet('description', ['attributes' => new Attribute($description_attributes), 'content' => $variables['description'], 'position' => $variables->offsetGet('description_display', 'after')]);
     }
 }
示例#19
0
文件: Page.php 项目: frankcr/sftw8
 /**
  * {@inheritdoc}
  */
 public function preprocessVariables(Variables $variables, $hook, array $info)
 {
     // Setup default attributes.
     $variables->getAttributes(DrupalAttributes::NAVBAR);
     $variables->getAttributes(DrupalAttributes::HEADER);
     $variables->getAttributes(DrupalAttributes::CONTENT);
     $variables->getAttributes(DrupalAttributes::FOOTER);
     $this->preprocessAttributes($variables, $hook, $info);
 }
示例#20
0
 /**
  * {@inheritdoc}
  */
 protected function preprocessVariables(Variables $variables, $hook, array $info)
 {
     // Immediately log an error and return if Bootstrap modals are not enabled.
     if (!$this->theme->getSetting('modal_enabled')) {
         \Drupal::logger('bootstrap')->error(t('Bootstrap modals are not enabled.'));
         return;
     }
     // Retrieve the ID, generating one if needed.
     $id = $variables->getAttribute('id', Html::getUniqueId($variables->offsetGet('id', 'bootstrap-modal')));
     $variables->setAttribute('id', $id);
     unset($variables['id']);
     if ($variables->title) {
         $title_id = $variables->getAttribute('id', "{$id}--title", $variables::TITLE);
         $variables->setAttribute('id', $title_id, $variables::TITLE);
         $variables->setAttribute('aria-labelledby', $title_id);
     }
     // Use a provided modal size or retrieve the default theme setting.
     $variables->size = $variables->size ?: $this->theme->getSetting('modal_size');
     // Convert the description variable.
     $this->preprocessDescription($variables, $hook, $info);
     // Ensure all attributes are proper objects.
     $this->preprocessAttributes($variables, $hook, $info);
 }
示例#21
0
 /**
  * {@inheritdoc}
  */
 public function preprocessElement(Variables $variables, $hook, array $info)
 {
     $variables->map(['attributes']);
     $this->preprocessAttributes($variables, $hook, $info);
 }
示例#22
0
 /**
  * {@inheritdoc}
  */
 public function preprocessElement(Element $element, Variables $variables)
 {
     $variables->map(['attributes']);
     $this->preprocessAttributes();
 }