/** * {@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']); }
/** * {@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.')); } }