/** * Preprocess input. */ function bootstrap_preprocess_input(&$variables) { $element =& $variables['element']; $attributes = new Attribute($variables['attributes']); // Set the element's attributes. \Drupal\Core\Render\Element::setAttributes($element, array('id', 'name', 'value', 'type')); // Handle button inputs. if (_bootstrap_is_button($element)) { $variables['attributes']['class'][] = 'btn'; _bootstrap_colorize_button($variables); _bootstrap_iconize_button($element); // Add button size, if necessary. if ($size = bootstrap_setting('button_size')) { $variables['attributes']['class'][] = $size; } // Add in the button type class. $variables['attributes']['class'][] = 'form-' . $element['#type']; $variables['label'] = $element['#value']; } _bootstrap_prerender_input($variables); // Autocomplete fields. if (!empty($element['#autocomplete_route_name']) && Drupal::PathValidator($element['#autocomplete_route_name'])) { $variables['autocomplete'] = TRUE; // Attributes for hidden input field. $autocomplete_attributes = new Attribute(); $autocomplete_attributes['type'] = 'hidden'; $autocomplete_attributes['id'] = $element['#attributes']['id'] . '-autocomplete'; $autocomplete_attributes['value'] = Drupal::Url($element['#autocomplete_route_name'], $element['#autocomplete_route_parameters']); $autocomplete_attributes['disabled'] = 'disabled'; $autocomplete_attributes['class'] = 'autocomplete'; // Uses icon for autocomplete "throbber". $icon = _bootstrap_icon('refresh'); // Fallback to using core's throbber. if (empty($icon)) { $icon = array('#type' => 'container', '#attributes' => array('class' => array('ajax-progress', 'ajax-progress-throbber', 'invisible')), 'throbber' => array('#type' => 'html_tag', '#tag' => 'div', '#attributes' => array('class' => array('throbber')))); } $variables['autocomplete_icon'] = $icon; $variables['autocomplete_attributes'] = $autocomplete_attributes; } // Search fields. if ($element['#type'] == 'search') { $attributes['placeholder'] = t('Search'); $attributes['data-original-title'] = t('Enter the terms you wish to search for.'); } // Additional Twig variables. $variables['icon'] = $element['#icon']; $variables['element'] = $element; }
/** * Overrides theme_menu_local_action(). */ function bootstrap_menu_local_action($variables) { $link = $variables['element']['#link']; $options = isset($link['localized_options']) ? $link['localized_options'] : array(); // If the title is not HTML, sanitize it. if (empty($options['html'])) { $link['title'] = check_plain($link['title']); } $icon = _bootstrap_iconize_button($link['title']); // Format the action link. $output = '<li>'; if (isset($link['href'])) { // Turn link into a mini-button and colorize based on title. if ($class = _bootstrap_colorize_button($link['title'])) { if (!isset($options['attributes']['class'])) { $options['attributes']['class'] = array(); } $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'][] = $class; if ($string) { $options['attributes']['class'] = implode(' ', $options['attributes']['class']); } } // Force HTML so we can add the icon rendering element. $options['html'] = TRUE; $output .= l($icon . $link['title'], $link['href'], $options); } else { $output .= $icon . $link['title']; } $output .= "</li>\n"; return $output; }