You are here

public function ModerationHandler::onBundleModerationConfigurationFormSubmit in Workbench Moderation 8.2

Same name and namespace in other branches
  1. 8 src/Entity/Handler/ModerationHandler.php \Drupal\workbench_moderation\Entity\Handler\ModerationHandler::onBundleModerationConfigurationFormSubmit()

Operates on the bundle definition that has been marked as moderatable.

Note: The values on the EntityModerationForm itself are already saved so do not need to be saved here. If any changes are made to the bundle object here it is this method's responsibility to call save() on it.

The most common use case is to force revisions on for this bundle if moderation is enabled. That, sadly, does not have a common API in core.

Parameters

\Drupal\Core\Config\Entity\ConfigEntityTypeInterface $bundle: The bundle definition that is being saved.

Return value

mixed

Overrides ModerationHandlerInterface::onBundleModerationConfigurationFormSubmit

File

src/Entity/Handler/ModerationHandler.php, line 47
Contains Drupal\workbench_moderation\Entity\Handler\GenericCustomizations.

Class

ModerationHandler
Common customizations for most/all entities.

Namespace

Drupal\workbench_moderation\Entity\Handler

Code

public function onBundleModerationConfigurationFormSubmit(ConfigEntityInterface $bundle) {

  // The Revisions portion of Entity API is not uniformly applied or consistent.
  // Until that's fixed in core, we'll make a best-attempt to apply it to
  // the common entity patterns so as to avoid every entity type needing to
  // implement this method, although some will still need to do so for now.
  // This is the API that should be universal, but isn't yet. See NodeType
  // for an example.
  if (method_exists($bundle, 'setNewRevision')) {
    $bundle
      ->setNewRevision(TRUE);
  }
  elseif ($bundle
    ->get('new_revision') !== NULL) {
    $bundle
      ->set('new_revision', TRUE);
  }
  elseif ($bundle
    ->get('revision') !== NULL) {
    $bundle
      ->set('revision', TRUE);
  }
  $bundle
    ->save();
  return;
}