class NodeModerationHandler in Workbench Moderation 8.2
Same name and namespace in other branches
- 8 src/Entity/Handler/NodeModerationHandler.php \Drupal\workbench_moderation\Entity\Handler\NodeModerationHandler
 
Customizations for node entities.
Hierarchy
- class \Drupal\workbench_moderation\Entity\Handler\ModerationHandler implements EntityHandlerInterface, ModerationHandlerInterface uses StringTranslationTrait
- class \Drupal\workbench_moderation\Entity\Handler\NodeModerationHandler
 
 
Expanded class hierarchy of NodeModerationHandler
1 file declares its use of NodeModerationHandler
File
- src/
Entity/ Handler/ NodeModerationHandler.php, line 16  - Contains Drupal\workbench_moderation\Entity\Handler\NodeCustomizations.
 
Namespace
Drupal\workbench_moderation\Entity\HandlerView source
class NodeModerationHandler extends ModerationHandler {
  /**
   * {@inheritdoc}
   */
  public function onPresave(ContentEntityInterface $entity, $default_revision, $published_state) {
    if ($this
      ->shouldModerate($entity)) {
      parent::onPresave($entity, $default_revision, $published_state);
      // Only nodes have a concept of published.
      /** @var $entity Node */
      $entity
        ->setPublished($published_state);
    }
  }
  /**
   * {@inheritdoc}
   */
  public function enforceRevisionsEntityFormAlter(array &$form, FormStateInterface $form_state, $form_id) {
    $form['revision']['#disabled'] = TRUE;
    $form['revision']['#default_value'] = TRUE;
    $form['revision']['#description'] = $this
      ->t('Revisions are required.');
  }
  /**
   * {@inheritdoc}
   */
  public function enforceRevisionsBundleFormAlter(array &$form, FormStateInterface $form_state, $form_id) {
    /* @var \Drupal\node\Entity\NodeType $entity */
    $entity = $form_state
      ->getFormObject()
      ->getEntity();
    if ($entity
      ->getThirdPartySetting('workbench_moderation', 'enabled', FALSE)) {
      // Force the revision checkbox on.
      $form['workflow']['options']['#default_value']['revision'] = 'revision';
      $form['workflow']['options']['revision']['#disabled'] = TRUE;
    }
  }
  /**
   * Check if an entity's default revision and/or state needs adjusting.
   *
   * @param \Drupal\Core\Entity\ContentEntityInterface $entity
   *
   * @return bool
   *   TRUE when either the default revision or the state needs to be updated.
   */
  protected function shouldModerate(ContentEntityInterface $entity) {
    // First condition is needed so you can add a translation.
    // Second condition is needed when you want to publish a translation.
    // Third condition is needed when you want to create a new draft for a published translation.
    return $entity
      ->isDefaultTranslation() || $entity->moderation_state->entity
      ->isPublishedState() || $entity
      ->isPublished();
  }
}Members
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            ModerationHandler:: | 
                  public static | function | 
            @inheritDoc Overrides EntityHandlerInterface:: | 
                  |
| 
            ModerationHandler:: | 
                  public | function | 
            Operates on the bundle definition that has been marked as moderatable. Overrides ModerationHandlerInterface:: | 
                  |
| 
            NodeModerationHandler:: | 
                  public | function | 
            Alters bundle forms to enforce revision handling. Overrides ModerationHandler:: | 
                  |
| 
            NodeModerationHandler:: | 
                  public | function | 
            Alters entity forms to enforce revision handling. Overrides ModerationHandler:: | 
                  |
| 
            NodeModerationHandler:: | 
                  public | function | 
            Overrides ModerationHandler:: | 
                  |
| 
            NodeModerationHandler:: | 
                  protected | function | Check if an entity's default revision and/or state needs adjusting. | |
| 
            StringTranslationTrait:: | 
                  protected | property | The string translation service. | 1 | 
| 
            StringTranslationTrait:: | 
                  protected | function | Formats a string containing a count of items. | |
| 
            StringTranslationTrait:: | 
                  protected | function | Returns the number of plurals supported by a given language. | |
| 
            StringTranslationTrait:: | 
                  protected | function | Gets the string translation service. | |
| 
            StringTranslationTrait:: | 
                  public | function | Sets the string translation service to use. | 2 | 
| 
            StringTranslationTrait:: | 
                  protected | function | Translates a string to the current language or to a given language. |