You are here

public function ContentEntityConflictHandler::entityMainFormValidateLast in Conflict 8.2

Form level validation handler running after all others.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

See also

\Drupal\conflict\Entity\ContentEntityConflictHandler::entityFormAlter()

File

src/Entity/ContentEntityConflictHandler.php, line 304

Class

ContentEntityConflictHandler

Namespace

Drupal\conflict\Entity

Code

public function entityMainFormValidateLast(&$form, FormStateInterface $form_state) {

  // Run only as part of the final form level submission or if the form has
  // been completely validated and has no errors.
  if (!$this
    ->isFormLevelSubmission($form_state) || $form_state::hasAnyErrors() || empty($form_state
    ->get('conflict.paths'))) {
    return;
  }

  /** @var \Drupal\Core\Entity\ContentEntityFormInterface $form_object */
  $form_object = $form_state
    ->getFormObject();

  // Support https://www.drupal.org/node/2833682.
  if (method_exists($form_object, 'getIntermediateEntity')) {
    $entity = $form_object
      ->getIntermediateEntity();
  }
  else {
    $entity = $form_object
      ->buildEntity($form, $form_state);
  }

  // Exchange the entity with the intermediate one and flag the form so that
  // the conflict resolution form gets appended on form rebuild.
  $form_object
    ->setEntity($entity);
  $form_state
    ->set('conflict.build_conflict_resolution_form', TRUE);
  $form_state
    ->setCached(TRUE);
  $form_state
    ->setRebuild(TRUE);
  $conflict_paths =& $form_state
    ->get('conflict.paths');
  $this->moduleHandler
    ->alter('conflict_paths', $conflict_paths, $form_state);
}