Builds the actions element for the current form.

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

@return array
The actions element.
426311
protected function actions(array $form, FormStateInterface $form_state) {
    $steps = $this->getVisibleSteps();
    $next_step_id = $this->getNextStepId();
    $previous_step_id = $this->getPreviousStepId();
    $has_next_step = $next_step_id && isset($steps[$next_step_id]['next_label']);
    $has_previous_step = $previous_step_id && isset($steps[$previous_step_id]['previous_label']);

    $actions = [
      '#type' => 'actions',
      '#access' => $has_next_step,
    ];

    if ($has_next_step) {
      $actions['next'] = [
        '#type' => 'submit',
        '#value' => $steps[$next_step_id]['next_label'],
        '#button_type' => 'primary',
        '#submit' => ['::submitForm'],
      ];

      if ($has_previous_step) {
        $label = $steps[$previous_step_id]['previous_label'];
        $actions['next']['#suffix'] = Link::createFromRoute($label, 'acm_checkout.form', [
          'step' => $previous_step_id,
        ])->toString();
      }
    }

    return $actions;
  }
1289322
public function submitForm(array &$form, FormStateInterface $form_state)
    {
        $site = &$form_state->getTemporaryValue('site');

        $this->manager->getStorage()->delete($site, $this->currentUser()->id());
        drupal_set_message($this->t("Site %title has been deleted", ['%title' => $site->getAdminTitle()]));

        $form_state->setRedirect('admin/dashboard/site');
    }
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());
    }
1199026
public function buildForm(array $form, FormStateInterface $form_state, $course_esid = NULL) {
    $this->course_esid = (int) $course_esid;
    if ($this->course_esid) {
      $step = (object) $this->databaseCourses->loadStep($this->course_esid);
      $this->step = $step;
      $this->course_id = $step->course_id;
      $this->course_sid = $step->course_sid;
      $this->course_eid = $step->course_eid;
    }
    return parent::buildForm($form, $form_state);
  }
331689
public function submit(Form $form)
    {
        return $this->request($form->getUri(), $form->getMethod(), $form->getPhpValues(), $form->getPhpFiles());
    }
682370
public static function process(array $element, FormStateInterface $form_state) {
    $element['fid'] = [
      '#type' => 'hidden',
    ];
    $element['upload'] = $element['remove'] = [
      '#type' => 'submit',
      '#is_button' => TRUE,
      '#limit_validation_errors' => [
        $element['#parents'],
      ],
      '#weight' => 100,
    ];

    $element['upload']['#value'] = t('Upload');
    $element['upload']['#submit'][] = [static::class, 'upload'];

    $element['remove']['#value'] = t('Remove');
    $element['remove']['#submit'][] = [static::class, 'remove'];

    $key = array_merge($element['#parents'], ['fid']);
    // Don't use $form_state->hasValue(), because it will return TRUE if the
    // value exists and is falsy. Valid file IDs will always be truthy.
    $fid = $form_state->getValue($key);

    if ($fid) {
      $element['fid']['#value'] = $fid;

      $element['file'] = [
        '#theme' => 'file_link',
        '#file' => File::load($fid),
      ];
      $element['upload']['#access'] = FALSE;
    }
    else {
      $element['file'] = [
        '#type' => 'upload',
        '#title' => $element['#title'],
        '#upload_location' => $element['#upload_location'],
        '#upload_validators' => $element['#upload_validators'],
      ];
      $element['remove']['#access'] = FALSE;
    }
    return $element;
  }
1336626
public function add(array $post, Form $form = null)
    {
        $model  = $this->getModel();
        $form   = ($form instanceof Form) ?
            $form->setData($post) :
            $this->prepareForm($model, $post, true, true);
        $argv   = compact('post', 'form');
        $argv   = $this->prepareEventArguments($argv);

        $this->getEventManager()->trigger(self::EVENT_PRE_ADD, $this, $argv);

        if (!$form->isValid()) {
            return $form;
        }

        $saved  = $this->save($form->getData());
        $argv   = compact('post', 'form', 'saved');
        $argv   = $this->prepareEventArguments($argv);

        $this->getEventManager()->trigger(self::EVENT_POST_ADD, $this, $argv);

        return $saved;
    }
152649
public function renderActionsRow($actions)
    {
        /* @var $rowPlugin     \SxBootstrap\View\Helper\Bootstrap\Form\Actions */
        /* @var $elementPlugin \SxBootstrap\View\Helper\Bootstrap\Form\Element */
        $rowPlugin     = $this->getView()->plugin('sxb_form_actions');
        $rowPlugin     = $rowPlugin();
        $elementPlugin = $this->getView()->plugin('sxb_form_element');

        if ($actions instanceof ElementInterface) {
            return $rowPlugin->addContent($elementPlugin($actions));
        }

        if (!is_array($actions)) {
            throw new Exception\RuntimeException(
                'Invalid actions type supplied'
            );
        }

        foreach ($actions as $action) {
            $rowPlugin->addContent($elementPlugin($action));
        }

        return $rowPlugin;
    }
443580
public function disableSubmit(array &$form, FormStateInterface $form_state)
    {
        $types = array();
        foreach ($form_state->getValue('types') as $type => $selected) {
            if ($type === $selected) {
                $types[] = $type;
            }
        }

        if (empty($types)) {
            drupal_set_message($this->t("Nothing to do"));
            return;
        }

        $disabled = variable_get(APB_VAR_ENABLED_TYPES, []);
        $disabled += $types;

        if (empty($disabled)) {
            variable_set(APB_VAR_ENABLED_TYPES, null);
        } else {
            variable_set(APB_VAR_ENABLED_TYPES, array_unique($disabled));
        }

        drupal_set_message($this->t("Disabled selected types"));
    }
191984
public function submitModalFormAjax(array $form, FormStateInterface $form_state) {
    $response = new AjaxResponse();

    // If there are any form errors, re-display the form.
    if ($form_state->hasAnyErrors()) {
      $response->addCommand(new ReplaceCommand('#modal_openy_campaign_login_form', $form));

      return $response;
    }

    $storage = $form_state->getStorage();

    // For existed and logged in during validation members. All other cases were checked during validation.
    if ($storage['status'] === 'loggedin') {
      /** @var \Drupal\node\Entity\Node $campaign Campaign object. */
      $campaign = $storage['campaign'];

      // Get default values from settings.
      $config = $this->config('openy_campaign.general_settings');

      $msgSuccess = $config->get('successful_login');
      $modalMessage = check_markup($msgSuccess['value'], $msgSuccess['format']);
      // Get message from Campaign node.
      if (!empty($campaign->field_successful_login->value)) {
        $modalMessage = check_markup($campaign->field_successful_login->value, $campaign->field_successful_login->format);
      }

      // Login before Campaign start.
      $localeCampaignStartDate = OpenYLocaleDate::createDateFromFormat($campaign->get('field_campaign_start_date')->getString());
      if (!$localeCampaignStartDate->dateExpired()) {
        $msgNotStarted = $config->get('error_login_checkins_not_started');
        $modalMessage = check_markup($msgNotStarted['value'], $msgNotStarted['format']);
        // Get message from Campaign node.
        if (!empty($campaign->field_login_checkins_not_started->value)) {
          $modalMessage = check_markup($campaign->field_login_checkins_not_started->value, $campaign->field_login_checkins_not_started->format);
        }
      }

      $landingPageId = $form_state->getValue('landing_page_id');
      $queryParameters = [];
      if (!empty($landingPageId)) {
        $landingPage = $this->nodeStorage->load($landingPageId);
        $queryParameters = [trim($landingPage->toUrl()->toString(), "/")];
      }

      $response->addCommand(new ReplaceCommand('#modal_openy_campaign_login_form', $modalMessage));

      $response->addCommand(new InvokeCommand('#drupal-modal', 'closeDialog', $queryParameters));

      return $response;
    }

    return $response;
  }
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;
  }
654429
public function createOrUpdate(FormInterface $form)
    {
        /** @var CreateUpdateActionHandler $viewHandler */
        $viewHandler = $this->actionHandlers[CreateUpdateActionHandler::class];
        $viewHandler->setView($this->view);
        $viewHandler->setRequest($this->request);
        $viewHandler->setForm($form);

        return $this->getResponse($viewHandler->getView($this->driver));
    }
228417
public function buildForm(array $form, FormStateInterface $form_state) {
    $form['#title'] = $this->t('Configure Presto functionality');

    // Clear any module success messages.
    drupal_get_messages('status');

    // Add configuration forms for optional deps if defined.
    $optionalDeps = $this->optionalDependencyManager->getDefinitions();
    $form['optional_dependencies'] = [
      '#type' => 'fieldset',
      '#title' => $this->t('Optional Dependencies'),
      '#collapsible' => FALSE,
      '#tree' => TRUE,
    ];

    $hasOptionalDepsForm = FALSE;
    $form_state->set('optional_dependencies', []);
    foreach ($optionalDeps as $optionalDep) {
      /** @var \Drupal\presto\Installer\OptionalDependencies\OptionalDependencyInterface $instance */
      $instance = $this->optionalDependencyManager->createInstance(
        $optionalDep['id']
      );

      $pluginForm = [];
      $subFormState = SubformState::createForSubform(
        $pluginForm,
        $form,
        $form_state
      );
      $form['optional_dependencies'][$optionalDep['id']] = $instance->buildConfigurationForm(
        $pluginForm,
        $subFormState
      );

      if (count($form['optional_dependencies'][$optionalDep['id']]) > 0) {
        $hasOptionalDepsForm = TRUE;
      }

      $form_state->set(['optional_dependencies', $optionalDep['id']], $instance);
    }

    // Hide optional dependencies fieldset if the config form is empty.
    $form['optional_dependencies']['#access'] = $hasOptionalDepsForm;

    $form['ecommerce'] = [
      '#type' => 'fieldset',
      '#title' => $this->t('eCommerce'),
      '#collapsible' => FALSE,
    ];

    // Only enable commerce if this profile was installed via Composer
    // (which is when the below interface will exist).
    $enableCommerce = FALSE;
    /** @noinspection ClassConstantCanBeUsedInspection */
    if (interface_exists('CommerceGuys\Intl\Currency\CurrencyInterface')) {
      $enableCommerce = TRUE;
    }

    if (!$enableCommerce) {
      $disabledMsg = $this->t('<p><strong>Not supported.</strong></p><p>Unfortunately, eCommerce is only supported if you install Presto via Composer. <a href=":url">See the README for more information on installing via Composer.</a></p>', [
        ':url' => 'https://github.com/Sitback/presto#installing-presto',
      ]);
      $form['ecommerce']['disabled_info'] = [
        '#type' => 'markup',
        '#markup' => $disabledMsg,
      ];
    }

    $form['ecommerce']['enable_ecommerce'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Enable eCommerce'),
      '#description' => $this->t(
        'Enables Drupal Commerce and some sane defaults to help you kickstart your eCommerce site.'
      ),
      '#disabled' => !$enableCommerce,
      '#default_value' => $enableCommerce,
    ];

    $form['ecommerce']['ecommerce_install_demo_content'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Install Demo Content'),
      '#description' => $this->t(
        'Creates a few demo products to help you test your new eCommerce site.'
      ),
      '#disabled' => !$enableCommerce,
      '#default_value' => $enableCommerce,
      '#states' => [
        'visible' => [
          'input[name="enable_ecommerce"]' => [
            'checked' => TRUE,
          ],
        ],
        'unchecked' => [
          'input[name="enable_ecommerce"]' => [
            'checked' => FALSE,
          ],
        ],
      ],
    ];

    $form['actions']['#type'] = 'actions';
    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this->t('Save and continue'),
      '#button_type' => 'primary',
      '#submit' => ['::submitForm'],
    ];

    return $form;
  }
812448
protected function getAllActions()
    {
        $fields = $this->form->Fields()->dataFields();
        $actions = $this->form->Actions()->dataFields();

        $fieldsAndActions = array_merge($fields, $actions);
        $actions = array_filter($fieldsAndActions, function ($fieldOrAction) {
            return $fieldOrAction instanceof FormAction;
        });

        return $actions;
    }
177236
protected function getFormErrors(FormInterface $form)
    {
        $errors = [];
        foreach ($form->getErrors() as $error) {
            $errors[] = $error->getMessage();
        }
        foreach ($form->all() as $child) {
            if (!$child->isValid()) {
                $errors[$child->getName()] = $this->getFormErrors($child);
            }
        }

        return $errors;
    }
705423
public function getState(Form $form)
    {
        $state = [
            'id' => $form->FormName(),
            'fields' => [],
            'messages' => [],
            'notifyUnsavedChanges' => $form->getNotifyUnsavedChanges(),
        ];

        // flattened nested fields are returned, rather than only top level fields.
        $state['fields'] = array_merge(
            $this->getFieldStates($form->Fields()),
            $this->getFieldStates($form->Actions())
        );

        if ($message = $form->getSchemaMessage()) {
            $state['messages'][] = $message;
        }

        return $state;
    }
853601
public FormAction setValuesInForm(Form form) {
		FormAction formAction = new FormAction();
		form.setFormAction(formAction);
		this.forms.add(form);
		return formAction;
	}