Returns the root element for a triggering element.

@param array $form
The complete form.
@param \Drupal\Core\Form\FormStateInterface $form_state
The current form state.

@return array
The root element that contains the triggering element.
976204
public static function el(array &$form, FormStateInterface $form_state) {
    $trigger = $form_state->getTriggeringElement();
    return NestedArray::getValue($form, array_slice($trigger['#array_parents'], 0, -1));
  }
980048
public function processUploadElement(array $element, FormStateInterface $form_state) {
    $element = AjaxUpload::process($element, $form_state);

    $element['upload']['#ajax']['callback'] =
    $element['remove']['#ajax']['callback'] = [static::class, 'ajax'];

    $element['remove']['#value'] = $this->t('Cancel');

    return $element;
  }
1015187
private function getLocale(FormInterface $form)
    {
        if (null === $form->getParent()) {
            return null;
        }

        $entity = $form->getParent()->getData();

        if (!is_object($entity)) {
            return null;
        }

        $class = ClassUtils::getClass($entity);

        if (!$this->translatableManager->isTranslation($class)) {
            return null;
        }

        return $this->propertyAccessor->getValue($entity, $this->translatableManager->getTranslationLocaleProperty());
    }
1635
public function editTransversalSubmit(array &$form, FormStateInterface $form_state)
    {
        if (!$this->manager->getSiteContext()->isTemporary()) {

            // @todo Generate a better token (random).
            $token  = drupal_get_token();
            $layout = $this->manager->getSiteContext()->getCurrentLayout();
            $this->manager->getSiteContext()->setToken($token);

            // Saving the layout will force it be saved in the temporary storage.
            $this->manager->getSiteContext()->getStorage()->save($layout);

            $form_state->setRedirect(
                current_path(),
                ['query' => [ContextManager::PARAM_SITE_TOKEN => $token] + drupal_get_query_parameters()]
            );
        }
    }
695767
protected function isElementHasError(ElementInterface $element, FormInterface $form)
    {
        if ($element->getMessages()) {
            return true;
        }

        $elementName = $this->normalizeElementName($element->getName());
        $elements = $this->getInvalidFieldsetElements($element, $form);
        if (isset($elements[$elementName]) && $elements[$elementName] === $element) {
            return true;
        }

        return false;
    }
111531
public function form(Form $form)
    {
        if ($this->mode == self::MODE_INLINE || $this->mode == self::MODE_INLINE_NO_LABELS) {
            $form->addClass('form-inline');
        } elseif ($this->mode == self::MODE_HORIZONTAL) {
            $form->addClass('form-horizontal');
        }

        return parent::form($form);
    }
381561
public function rebuildAjaxCallback(array &$form, FormStateInterface $form_state) {
    $values = $form_state->getValues();
    $state = $this->state;
    $location = !empty($values['location_select']) ? $values['location_select'] : $values['location'];
    $filter_date = !empty($values['date_select']) ? $values['date_select'] : $values['date'];
    $tz = \Drupal::config('system.date')->get('timezone.default');
    $date = new \DateTime($filter_date, new \DateTimeZone($tz));
    $filter_date = $date->format('n/d/y');

    $parameters = [
      'location' => $location,
      'filter_date' => $filter_date,
    ];
    $triggering_element = $form_state->getTriggeringElement();

    if (isset($triggering_element['#name']) && $triggering_element['#name'] == 'location') {
      $parameters['location'] = $triggering_element['#value'];
    }
    if (isset($triggering_element['#name']) && $triggering_element['#name'] == 'location_select' && $state['class'] != 'any') {
      $parameters['class'] = $state['class'];
      $parameters['filter_length'] = 'week';
      $parameters['category'] = $state['category'];
      $parameters['groupex_class'] = 'groupex_table_class_individual';
      $parameters['view_mode'] = 'class';
    }
    if (isset($triggering_element['#name']) && $triggering_element['#name'] == 'class_select' && $triggering_element['#value'] != 'any') {
      $parameters['class'] = $triggering_element['#value'];
      $parameters['filter_length'] = 'week';
      $parameters['category'] = $state['category'];
      $parameters['groupex_class'] = 'groupex_table_class_individual';
      $parameters['view_mode'] = 'class';
    }
    if (isset($triggering_element['#name']) && $triggering_element['#name'] == 'instructor_select') {
      $parameters['class'] = $state['class'];
      $parameters['filter_length'] = 'week';
      $parameters['category'] = $state['category'];
      $parameters['groupex_class'] = 'groupex_table_instructor_individual';
      if ($triggering_element['#value'] != 'any') {
        $parameters['instructor'] = $triggering_element['#value'];
      }
    }
    if (isset($triggering_element['#name']) && $triggering_element['#name'] == 'category_select' && $triggering_element['#value'] != 'any') {
      $parameters['class'] = $state['class'];
      $parameters['filter_length'] = 'week';
      $parameters['groupex_class'] = 'groupex_table_instructor_individual';
      if ($triggering_element['#value'] != 'any') {
        $parameters['category'] = $state['category'];;
      }
    }

    $formatted_results = self::buildResults($form, $form_state);
    $response = new AjaxResponse();
    $response->addCommand(new HtmlCommand('#groupex-full-form-wrapper .groupex-results', $formatted_results));
    $response->addCommand(new InvokeCommand(NULL, 'groupExLocationAjaxAction', [$parameters]));

    $link = [
      '#title' => $this->t('Download PDF'),
      '#type' => 'link',
      '#url' => $this->groupexHelper->getPdfLink($parameters['location']),
      '#attributes' => [
        'class' => [
          'btn',
          'btn-default',
          'pdf-link',
        ],
      ],
    ];
    $groupex_pdf_link = $link;

    $response->addCommand(new HtmlCommand('#groupex-full-form-wrapper .groupex-pdf-link-container', $groupex_pdf_link));

    $form_state->setRebuild();
    return $response;
  }
1009856
public function getContextSelectorForm()
    {
        if (!$this->contextSelectorForm) {
            if (!$this->contextSelectorType || !$this->formFactory) {
                return null;
            }

            $formOptions = [
                'action' => $this->requestUri,
                'attr' => [
                    'novalidate' => 'novalidate',
                    'class' => 'form-inline',
                ],
            ];
            $this->contextSelectorForm = $this->formFactory->createNamed(
                static::SESSION_KEY,
                $this->contextSelectorType,
                $this->getContext(),
                $formOptions
            );
        }

        return $this->contextSelectorForm;
    }
485158
protected function processChildren($form)
    {
        $result = array();
        // If this field has children - process them
        foreach ($form as $name => $child) {
            if ($this->isProcessableElement($child)) {
                $childModel = $this->createJsModel($child);
                if (null !== $childModel) {
                    $result[$name] = $childModel;
                }
            }
        }

        return $result;
    }
237419
public function getSchema(Form $form)
    {
        $schema = [
            'name' => $form->getName(),
            'id' => $form->FormName(),
            'action' => $form->FormAction(),
            'method' => $form->FormMethod(),
            'attributes' => $form->getAttributes(),
            'data' => [],
            'fields' => [],
            'actions' => []
        ];

        /** @var FormField $action */
        foreach ($form->Actions() as $action) {
            $schema['actions'][] = $action->getSchemaData();
        }

        /** @var FormField $field */
        foreach ($form->Fields() as $field) {
            $schema['fields'][] = $field->getSchemaData();
        }

        return $schema;
    }
810382
protected function _getSelectForm()
    {
        $form = new \Gems_Form(array('name' => 'autosubmit', 'class' => 'form-inline', 'role' => 'form'));

        $form->setHtml('div');
        $div = $form->getHtml();
        $div->class = 'search';

        $span = $div->div(array('class' => 'panel panel-default'))->div(array('class' => 'inputgroup panel-body'));

        $element = $form->createElement('select', 'gpa_level', array(
            'multiOptions' => $this->patchLevels,
            'onchange' => 'this.form.submit();',
            'onkeyup' => 'this.form.submit();',
            ));

        $element->setValue($this->getPatchLevel());
        $span->input($element);

        $form->addElement($element);

        $submit = $form->createElement('submit', 'search', array(
            'label' => $this->_('Search'),
            'class' => 'button small',
            ));

        $span->input($submit);
        $form->addElement($submit);

        return $form;
    }
771963
public function setForm($form)
    {
        foreach ($this->fields as $field) {
            $field->setForm($form);
        }
        
        return parent::setForm($form);
    }
62736
public function getRootFormCascadeOption(FormInterface $form)
    {
        if (! $form->isRoot()) {
            return $this->getRootFormCascadeOption($form->getParent());
        }

        return $form->getConfig()->getOption('cascade_filter', false);
    }
87671
public function submitForm(array &$form, FormStateInterface $form_state)
    {
        $group   = &$form_state->getTemporaryValue('group');
        $values  = &$form_state->getValues();

        /** @var $group Group */
        $group->setTitle($values['title']);
        $group->setIsGhost($values['is_ghost']);

        foreach (['allowed_themes'] as $name) {
            $list = $form_state->getValue($name, []);
            $list = array_values(array_filter($list));
            if ($list) {
                $group->setAttribute($name, $list);
            } else {
                $group->deleteAttribute($name);
            }
        }

        $isNew = !$group->getId();

        $this->groupManager->save($group, ['title', 'is_ghost', 'attributes']);
        if ($isNew) {
            drupal_set_message($this->t("Group %title has been created", ['%title' => $group->getTitle()]));
        } else {
            drupal_set_message($this->t("Group %title has been updated", ['%title' => $group->getTitle()]));
        }

        $form_state->setRedirect('admin/dashboard/group/' . $group->getId());
    }
1291721
private function renderForm(Form $form) : string
    {
        $html = '';

        foreach ($form->getComponents() as $component) {
            if ($component instanceof Element) {
                $html .= $this->renderElementAsRow($component);
            } elseif ($component instanceof Group) {
                foreach ($component->getElements() as $element) {
                    $html .= $this->renderElementAsRow($element);
                }
            }
        }

        $table = new Tag('table');
        $table->setAttribute('class', $this->class);
        $table->setHtmlContent($html);

        return $table->render();
    }
1277479
public function buildForm(array $form, FormStateInterface $form_state) {
    $form['#attributes']['class'][] = 'card card__block form--default form-wrapper form-group';

    if (empty($nid)) {
      $node = \Drupal::routeMatch()->getParameter('node');
      if ($node instanceof NodeInterface) {
        // You can get nid and anything else you need from the node object.
        $nid = $node->id();
      }
      elseif (!is_object($node)) {
        $nid = $node;
      }
    }

    // Load the current Event enrollments so we can check duplicates.
    $storage = \Drupal::entityTypeManager()->getStorage('event_enrollment');
    $enrollments = $storage->loadByProperties(['field_event' => $nid]);

    $enrollmentIds = [];
    foreach ($enrollments as $enrollment) {
      $enrollmentIds[] = $enrollment->getAccount();
    }

    $form['name'] = [
      '#type' => 'social_enrollment_entity_autocomplete',
      '#selection_handler' => 'social',
      '#selection_settings' => [
        'skip_entity' => $enrollmentIds,
      ],
      '#target_type' => 'user',
      '#tags' => TRUE,
      '#description' => $this->t('To add multiple members, separate each member with a comma ( , ).'),
      '#title' => $this->t('Select members to add'),
    ];

    $form['actions']['cancel'] = [
      '#type' => 'link',
      '#title' => t('Cancel'),
      '#url' => Url::fromRoute('view.event_manage_enrollments.page_manage_enrollments', ['node' => $nid]),
    ];

    $form['actions']['submit'] = [
      '#prefix' => '<div class="form-actions">',
      '#suffix' => '</div>',
      '#type' => 'submit',
      '#value' => $this->t('Save'),
      '#button_type' => 'primary',
    ];

    $form['#cache']['contexts'][] = 'user';

    return $form;
  }
115140
public function submitForm(array &$form, FormStateInterface $form_state) {
    $action = $form_state->getUserInput()['op'];

    switch ($action) {
      case 'Synchronize Promotions':
        $this->promotionManager->syncPromotions();
        drupal_set_message('Promotions Synchronization Complete.', 'status');
        break;
    }
  }