Beispiel #1
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);
 }
Beispiel #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);
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public static function processElement(Element $element, FormStateInterface $form_state, array &$complete_form)
 {
     if (isset($element->format)) {
         $element->format->addClass('form-inline');
         // Guidelines (removed).
         $element->format->guidelines->setProperty('access', FALSE);
         // Format (select).
         $element->format->format->addClass('input-sm')->setProperty('title_display', 'invisible')->setProperty('weight', -10);
         // Help (link).
         $element->format->help->about->setAttribute('title', t('Opens in new window'))->setProperty('icon', Bootstrap::glyphicon('question-sign'));
         if (Bootstrap::getTheme()->getSetting('tooltip_enabled')) {
             $element->format->help->about->setAttribute('data-toggle', 'tooltip');
         }
     }
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  */
 public function preprocessVariables(Variables $variables, $hook, array $info)
 {
     if (!empty($variables['description'])) {
         $variables['description'] = FieldFilteredMarkup::create($variables['description']);
     }
     $descriptions = [];
     $cardinality = $variables['cardinality'];
     if (isset($cardinality)) {
         if ($cardinality == -1) {
             $descriptions[] = t('Unlimited number of files can be uploaded to this field.');
         } else {
             $descriptions[] = \Drupal::translation()->formatPlural($cardinality, 'One file only.', 'Maximum @count files.');
         }
     }
     $upload_validators = $variables['upload_validators'];
     if (isset($upload_validators['file_validate_size'])) {
         $descriptions[] = t('@size limit.', ['@size' => format_size($upload_validators['file_validate_size'][0])]);
     }
     if (isset($upload_validators['file_validate_extensions'])) {
         $extensions = new FormattableMarkup('<code>@extensions</code>', ['@extensions' => implode(', ', explode(' ', $upload_validators['file_validate_extensions'][0]))]);
         $descriptions[] = t('Allowed types: @extensions.', ['@extensions' => $extensions]);
     }
     if (isset($upload_validators['file_validate_image_resolution'])) {
         $max = $upload_validators['file_validate_image_resolution'][0];
         $min = $upload_validators['file_validate_image_resolution'][1];
         if ($min && $max && $min == $max) {
             $descriptions[] = t('Images must be exactly <strong>@size</strong> pixels.', ['@size' => $max]);
         } elseif ($min && $max) {
             $descriptions[] = t('Images must be larger than <strong>@min</strong> pixels. Images larger than <strong>@max</strong> pixels will be resized.', ['@min' => $min, '@max' => $max]);
         } elseif ($min) {
             $descriptions[] = t('Images must be larger than <strong>@min</strong> pixels.', ['@min' => $min]);
         } elseif ($max) {
             $descriptions[] = t('Images larger than <strong>@max</strong> pixels will be resized.', ['@max' => $max]);
         }
     }
     $variables['descriptions'] = $descriptions;
     if ($descriptions) {
         $build = array();
         $id = Html::getUniqueId('upload-instructions');
         $build['toggle'] = ['#type' => 'link', '#title' => t('Upload requirements'), '#url' => Url::fromUserInput("#{$id}"), '#icon' => Bootstrap::glyphicon('question-sign'), '#attributes' => ['class' => ['icon-before'], 'data-toggle' => 'popover', 'data-html' => 'true', 'data-placement' => 'bottom', 'data-title' => t('Upload requirements')]];
         $build['requirements'] = ['#type' => 'container', '#theme_wrappers' => ['container__file_upload_help'], '#attributes' => ['id' => $id, 'class' => ['hidden', 'help-block'], 'aria-hidden' => 'true']];
         $build['requirements']['descriptions'] = ['#theme' => 'item_list__file_upload_help', '#items' => $descriptions];
         $variables['popover'] = $build;
     }
 }
Beispiel #5
0
 /**
  * {@inheritdoc}
  */
 public function alterForm(array &$form, FormStateInterface $form_state, $form_id = NULL)
 {
     parent::alterForm($form, $form_state, $form_id);
     $update_manager = new UpdateManager($this->theme);
     $pending = $update_manager->getPendingUpdates();
     if ($pending) {
         $form['update'] = ['#type' => 'details', '#title' => \Drupal::translation()->formatPlural(count($pending), 'Pending Update', 'Pending Updates'), '#panel_type' => 'primary', '#weight' => -20];
         $rows = [];
         foreach ($pending as $version => $update) {
             $row = [];
             $row[] = $version;
             $row[] = new FormattableMarkup('<strong>@title</strong><p class="help-block">@description</p>', ['@title' => $update->getTitle(), '@description' => $update->getDescription()]);
             $rows[] = ['class' => [$update->getLevel() ?: 'default'], 'data' => $row];
         }
         $form['update']['table'] = ['#type' => 'table', '#header' => [t('Update'), t('Description')], '#rows' => $rows];
         $form['update']['update'] = ['#type' => 'submit', '#value' => t('Update @theme', ['@theme' => $this->theme->getTitle()]), '#icon' => Bootstrap::glyphicon('open'), '#attributes' => ['class' => ['btn-primary']], '#submit' => [[get_class($this), 'updateTheme']]];
     }
 }
Beispiel #6
0
 /**
  * {@inheritdoc}
  */
 public function alterForm(array &$form, FormStateInterface $form_state, $form_id = NULL)
 {
     parent::alterForm($form, $form_state, $form_id);
     $updates = [];
     foreach ($this->theme->getPendingUpdates() as $version => $update) {
         $row = [];
         $row[] = $update->getSchema();
         $row[] = new FormattableMarkup('<strong>@title</strong><p class="help-block">@description</p>', ['@title' => $update->getLabel(), '@description' => $update->getDescription()]);
         $row[] = $update->getTheme()->getTitle();
         $updates[] = ['class' => [$update->getSeverity() ?: 'default'], 'data' => $row];
     }
     $form['update'] = ['#type' => 'details', '#title' => $this->t('Theme Updates'), '#panel_type' => !!$updates ? 'primary' : 'default', '#open' => !!$updates, '#weight' => -20];
     $form['update']['table'] = ['#type' => 'table', '#header' => [t('Schema'), t('Description'), t('Provider')], '#empty' => t('There are currently no pending updates for this theme.'), '#rows' => $updates];
     if ($updates) {
         $form['update']['actions'] = ['#type' => 'actions'];
         $form['update']['actions']['update'] = ['#type' => 'submit', '#value' => t('Update theme'), '#icon' => Bootstrap::glyphicon('open'), '#attributes' => ['class' => ['btn-primary']], '#submit' => [[get_class($this), 'updateTheme']]];
     }
 }
Beispiel #7
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]);
     }
 }
 /**
  * {@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);
 }
Beispiel #9
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);
 }
Beispiel #10
0
 /**
  * Processes elements with AJAX properties.
  *
  * @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.
  */
 public static function processAjax(Element $element, FormStateInterface $form_state, array &$complete_form)
 {
     $ajax = $element->getProperty('ajax');
     // Show throbber AJAX requests in an input button group.
     if (!isset($ajax['progress']['type']) || $ajax['progress']['type'] === 'throbber') {
         // Use an icon for autocomplete "throbber".
         $icon = Bootstrap::glyphicon('refresh');
         $element->appendProperty('field_suffix', Element::create($icon)->addClass(['ajax-progress', 'ajax-progress-throbber']));
         $element->setProperty('input_group', TRUE);
     }
 }
Beispiel #11
0
/**
 * Returns a specific Bootstrap Glyphicon.
 *
 * @param string $name
 *   The icon name, minus the "glyphicon-" prefix.
 * @param string $default
 *   (Optional) The default value to return.
 *
 * @return string
 *   The HTML markup containing the icon defined by $name, $default value if
 *   icon does not exist or returns empty output for whatever reason.
 *
 * @deprecated Will be removed in a future release.
 *
 * @code
 *   // Before.
 *   $icon = _bootstrap_icon($name, $default);
 *
 *   // After.
 *   use Drupal\bootstrap\Bootstrap;
 *   $glyphicon = Bootstrap::glyphicon($name, ['#markup' => $default]);
 *   $icon = \Drupal::service('renderer')->render($glyphicon);
 * @endcode
 *
 * @see \Drupal\bootstrap\Bootstrap::glyphicon()
 */
function _bootstrap_icon($name, $default = NULL)
{
    Bootstrap::deprecated();
    return \Drupal::service('renderer')->render(Bootstrap::glyphicon($name, ['#markup' => $default]));
}