You are here

public function EntityTypeInfo::bundleFormAlter in Workbench Moderation 8.2

Same name and namespace in other branches
  1. 8 src/EntityTypeInfo.php \Drupal\workbench_moderation\EntityTypeInfo::bundleFormAlter()

Alters bundle forms to enforce revision handling.

Parameters

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

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

string $form_id: The form id.

See also

hook_form_alter()

File

src/EntityTypeInfo.php, line 321

Class

EntityTypeInfo
Service class for manipulating entity type information.

Namespace

Drupal\workbench_moderation

Code

public function bundleFormAlter(array &$form, FormStateInterface $form_state, $form_id) {
  if ($this->moderationInfo
    ->isRevisionableBundleForm($form_state
    ->getFormObject())) {

    /* @var ConfigEntityTypeInterface $bundle */
    $bundle = $form_state
      ->getFormObject()
      ->getEntity();
    $this->entityTypeManager
      ->getHandler($bundle
      ->getEntityType()
      ->getBundleOf(), 'moderation')
      ->enforceRevisionsBundleFormAlter($form, $form_state, $form_id);
  }
  else {
    if ($this->moderationInfo
      ->isModeratedEntityForm($form_state
      ->getFormObject())) {

      /* @var ContentEntityInterface $entity */
      $entity = $form_state
        ->getFormObject()
        ->getEntity();
      $this->entityTypeManager
        ->getHandler($entity
        ->getEntityTypeId(), 'moderation')
        ->enforceRevisionsEntityFormAlter($form, $form_state, $form_id);

      // Submit handler to redirect to the
      $form['actions']['submit']['#submit'][] = '\\Drupal\\workbench_moderation\\EntityTypeInfo::bundleFormRedirect';
    }
  }
}