Handles form submission when the Upload button is clicked.

@param array $form
The complete form.
@param \Drupal\Core\Form\FormStateInterface $form_state
The current form state.
762257
public static function upload(array &$form, FormStateInterface $form_state) {
    $el = static::el($form, $form_state);

    $form_state->setValueForElement($el['fid'], $el['file']['#value']);
    NestedArray::setValue($form_state->getUserInput(), $el['fid']['#parents'], $el['file']['#value']);

    $form_state->setRebuild();
  }
687001
public function handleRequest(FormInterface $form, $request = null)
    {
        if (null !== $request) {
            throw new UnexpectedTypeException($request, 'null');
        }

        $name = $form->getName();
        $method = $form->getConfig()->getMethod();

        if ($method !== self::getRequestMethod()) {
            return;
        }

        // For request methods that must not have a request body we fetch data
        // from the query string. Otherwise we look for data in the request body.
        if ('GET' === $method || 'HEAD' === $method || 'TRACE' === $method) {
            if ('' === $name) {
                $data = $_GET;
            } else {
                // Don't submit GET requests if the form's name does not exist
                // in the request
                if (!isset($_GET[$name])) {
                    return;
                }

                $data = $_GET[$name];
            }
        } else {
            // Mark the form with an error if the uploaded size was too large
            // This is done here and not in FormValidator because $_POST is
            // empty when that error occurs. Hence the form is never submitted.
            if ($this->serverParams->hasPostMaxSizeBeenExceeded()) {
                // Submit the form, but don't clear the default values
                $form->submit(null, false);

                $form->addError(new FormError(
                    $form->getConfig()->getOption('upload_max_size_message')(),
                    null,
                    ['{{ max }}' => $this->serverParams->getNormalizedIniPostMaxSize()]
                ));

                return;
            }

            $fixedFiles = [];
            foreach ($_FILES as $fileKey => $file) {
                $fixedFiles[$fileKey] = self::stripEmptyFiles(self::fixPhpFilesArray($file));
            }

            if ('' === $name) {
                $params = $_POST;
                $files = $fixedFiles;
            } elseif (\array_key_exists($name, $_POST) || \array_key_exists($name, $fixedFiles)) {
                $default = $form->getConfig()->getCompound() ? [] : null;
                $params = \array_key_exists($name, $_POST) ? $_POST[$name] : $default;
                $files = \array_key_exists($name, $fixedFiles) ? $fixedFiles[$name] : $default;
            } else {
                // Don't submit the form if it is not present in the request
                return;
            }

            if (\is_array($params) && \is_array($files)) {
                $data = array_replace_recursive($params, $files);
            } else {
                $data = $params ?: $files;
            }
        }

        // Don't auto-submit the form unless at least one field is present.
        if ('' === $name && \count(array_intersect_key($data, $form->all())) <= 0) {
            return;
        }

        if (\is_array($data) && \array_key_exists('_method', $data) && $method === $data['_method'] && !$form->has('_method')) {
            unset($data['_method']);
        }

        $form->submit($data, 'PATCH' !== $method);
    }
233590
protected void insertUploadForm(FormPanel form) {

        form.getElement().getStyle().setDisplay(Display.NONE);
        m_contentWrapper.add(form);
    }
331689
public function submit(Form $form)
    {
        return $this->request($form->getUri(), $form->getMethod(), $form->getPhpValues(), $form->getPhpFiles());
    }
1147857
public function submitForm(array &$form, FormStateInterface $form_state) {
        $entity = $this->getEntity();

        $duplicate = $entity->createDuplicate();
        $duplicate->setTitle($this->t('Duplicate') . ": " . $duplicate->label());
        $duplicate->save();

        $form_state->setRedirect('entity.site_commerce.collection');
    }
948553
public function buildForm(array $form, FormStateInterface $form_state) {

    // Redirect the user to the homepage if they are already logged in.
    if ($this->commerceUserManager->isAuthenticated()) {
      return $this->redirect('<front>');
    }

    $request = $this->requestStack->getCurrentRequest();
    $password_token = $request->query->get('token');
    $email = $request->query->get('email');

    $form['email'] = [
      '#type' => 'email',
      '#title' => $this->t('Email Address'),
      '#default_value' => $email,
      '#disabled' => isset($email) ? TRUE : FALSE,
      '#required' => TRUE,
    ];

    $form['new_password'] = [
      '#type' => 'password_confirm',
      '#required' => TRUE,
    ];

    $form['password_token'] = [
      '#type' => 'hidden',
      '#value' => $password_token,
    ];

    $form['actions'] = [
      '#type' => 'actions',
    ];

    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this->t('Update password'),
    ];

    return $form;
  }
977057
public function updateEditForm($form)
    {
        if ($this->isAssetAdmin() && $this->hasSecureAssets()) {
            
            if (($record = $form->getRecord()) && $record instanceof Folder) {
                
                if ($field = $form->Fields()->dataFieldByName('ViewerGroups')) {
                    
                    // Create Form Object:
                    
                    $dummy = Form::create(
                        $this->owner,
                        'EditForm',
                        FieldList::create(),
                        FieldList::create()
                    );
                    
                    // Populate Form Data:
                    
                    $dummy->loadDataFrom($record);
                    
                    // Define Form Action (allows ViewerGroups field to work in asset EditForm):
                    
                    $dummy->setFormAction(
                        sprintf(
                            '%s/field/File/item/%d/ItemEditForm',
                            $form->FormAction(),
                            $record->ID
                        )
                    );
                    
                    // Update Field Object:
                    
                    $field->setForm($dummy);
                    
                }
                
            }
            
        }
    }
1237080
public function editFormSucceeded(Form $form, ArrayHash $values): void
	{
		try {
			$this->currentUser->setUsername($values->username);
		} catch (UniqueConstraintViolationException $ex) {
			$form->addError('cms.user.duplicityUsername');
			return;
		} catch (InvalidArgumentException $ex) {
			$form->addError('cms.user.invalidUsername');
			return;
		}

		try {
			$this->currentUser->setEmail($values->email);
		} catch (UniqueConstraintViolationException $ex) {
			$form->addError('cms.user.duplicityEmail');
			return;
		} catch (InvalidArgumentException $ex) {
			$form->addError('cms.user.invalidUsername');
			return;
		}

		try {
			$this->currentUser->setPhone($values->phone ?: null);
		} catch (InvalidArgumentException $ex) {
			$form->addError('cms.user.invalidPhone');
			return;
		}

		$this->currentUser->firstName = $values->firstName;
		$this->currentUser->surname = $values->surname;
		$this->currentUser->roles->set($values->roles);

		$language = $this->localeService->getById($values->language);
		$this->currentUser->language = $language === null ? null : $language->name;

		$this->orm->persistAndFlush($this->currentUser);

		$this->flashNotifier->success('cms.user.dataSaved');
		$this->restoreBacklink();
	}
637417
public function cancelSubmit(array &$form, FormStateInterface $form_state)
    {
        if ($this->manager->getPageContext()->isTemporary()) {
            $this->manager->getPageContext()->rollback();

            drupal_set_message($this->t("Changes have been dropped"), 'error');

            $form_state->setRedirect(
                current_path(),
                ['query' => drupal_get_query_parameters(null, ['q', ContextManager::PARAM_PAGE_TOKEN])]
            );
        }
    }
71480
public function navButtonSubmit(array &$form, FormStateInterface &$form_state) {
    $storage = $form_state->getStorage();
    // Save steps values to storage.
    if ($form_state->getValue('location')) {
      $storage['location'] = $form_state->getValue('location');
    }
    if ($form_state->getValue('type')) {
      $storage['type'] = $form_state->getValue('type');
    }
    $form_state->setStorage($storage);
    $form_state->setRebuild();
  }
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;
  }
108412
public function submitForm(array &$form, FormStateInterface $form_state)
    {
        $node   = $form_state->getTemporaryValue('node');
        $action = $form_state->getValue('action');
        $siteId = $form_state->getValue('site');

        $options = [];
        if (isset($_GET['destination'])) {
            $options['query']['destination'] = $_GET['destination'];
            unset($_GET['destination']);
        }

        switch ($action) {

            case 'duplicate':
                list($path, $options) = $this->siteManager->getUrlGenerator()->getRouteAndParams($siteId, 'node/' . $node->id(). '/clone', $options);
                drupal_set_message($this->t("You can now edit this node on this site, it will be automatically duplicated."));
                break;

            default:
                $path = 'node/' . $node->id() . '/edit';
                drupal_set_message($this->t("You are now editing the global content for all sites."));
                break;
        }

        $form_state->setRedirect($path, $options);
    }
1036232
public function submitStepABack(array $form, FormStateInterface $form_state)
    {
        $formData = &$form_state->getStorage();

        /** @var $site Site */
        $site = $formData['site'];
        $site->state = SiteState::REQUESTED;
        $site->theme = $form_state->getValue('theme');
        $site->ts_created = $site->ts_changed = new \DateTime();
        $site->template_id = $form_state->getValue('is_template') ? 0 : $form_state->getValue('template_id');
        $site->is_template = $form_state->getValue('is_template');

        $formData['step'] = 'a';
        $form_state->setRebuild(true);
    }
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;
  }
1274947
public function editSubmit(array &$form, FormStateInterface $form_state)
    {
        if (!$this->manager->getPageContext()->isTemporary()) {

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

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

            $form_state->setRedirect(
                current_path(),
                ['query' => [ContextManager::PARAM_PAGE_TOKEN => $token] + drupal_get_query_parameters()]
            );
        }
    }
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));
  }
57786
public function onSubmission(SubmissionEvent $event)
    {
        $page = $event->getPage();
        $formSubmission = $event->getSubmission();

        $from = $page->getFromEmail();
        $to = $page->getToEmail();
        $subject = $page->getSubject();
        if (!empty($from) && !empty($to) && !empty($subject)) {
            $this->formMailer->sendContactMail($formSubmission, $from, $to, $subject);
        }
    }