Example #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);
 }
Example #2
0
 /**
  * {@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);
 }
Example #3
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);
 }
Example #4
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);
 }
Example #5
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();
 }
Example #6
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);
 }
Example #7
0
 /**
  * {@inheritdoc}
  */
 public function preprocessElement(Variables $variables, $hook, array $info)
 {
     $variables->map(['attributes']);
     $this->preprocessAttributes($variables, $hook, $info);
 }
 /**
  * {@inheritdoc}
  */
 public function preprocessElement(Element $element, Variables $variables)
 {
     $variables->map(['attributes']);
     $this->preprocessAttributes();
 }