예제 #1
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();
     }
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public static function processElement(Element $element, FormStateInterface $form_state, array &$complete_form)
 {
     foreach ($element->children() as $child) {
         if ($child->isPropertyEmpty('icon')) {
             $child->setIcon();
         }
     }
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public static function processElement(Element $element, FormStateInterface $form_state, array &$complete_form)
 {
     $dropbuttons = Element::create();
     foreach ($element->children(TRUE) as $key => $child) {
         if ($dropbutton = $child->getProperty('dropbutton')) {
             // If there is no dropbutton for this button group yet, create one.
             if (!isset($dropbuttons->{$dropbutton})) {
                 $dropbuttons->{$dropbutton} = ['#type' => 'dropbutton'];
             }
             $dropbuttons[$dropbutton]['#links'][$key] = $child->getArray();
             // Remove original child from the element so it's not rendered twice.
             $child->setProperty('printed', TRUE);
         }
     }
     $element->exchangeArray($dropbuttons->getArray() + $element->getArray());
 }
예제 #4
0
 /**
  * Traverses an element to find the closest button.
  *
  * @param \Drupal\bootstrap\Utility\Element $element
  *   The element to iterate over.
  *
  * @return \Drupal\bootstrap\Utility\Element|FALSE
  *   The first button element or FALSE if no button could be found.
  */
 protected static function &findButton(Element $element)
 {
     $button = FALSE;
     foreach ($element->children() as $child) {
         if ($child->isButton()) {
             $button = $child;
         }
         if ($result =& self::findButton($child)) {
             $button = $result;
         }
     }
     return $button;
 }