You are here

class InlineEditingDisabler in Workbench Moderation 8

Same name and namespace in other branches
  1. 8.2 src/InlineEditingDisabler.php \Drupal\workbench_moderation\InlineEditingDisabler

Disables the inline editing for entities with forward revisions.

Hierarchy

Expanded class hierarchy of InlineEditingDisabler

1 string reference to 'InlineEditingDisabler'
workbench_moderation.services.yml in ./workbench_moderation.services.yml
workbench_moderation.services.yml
1 service uses InlineEditingDisabler
workbench_moderation.inline_editing_disabler in ./workbench_moderation.services.yml
Drupal\workbench_moderation\InlineEditingDisabler

File

src/InlineEditingDisabler.php, line 11

Namespace

Drupal\workbench_moderation
View source
class InlineEditingDisabler {

  /**
   * The moderation info.
   *
   * @var \Drupal\workbench_moderation\ModerationInformationInterface
   */
  protected $moderationInfo;

  /**
   * Creates a new InlineEditingDisabler instance.
   *
   * @param \Drupal\workbench_moderation\ModerationInformationInterface $moderation_info
   *   The moderation info.
   */
  public function __construct(ModerationInformationInterface $moderation_info) {
    $this->moderationInfo = $moderation_info;
  }

  /**
   * Implements hook_entity_view_alter().
   */
  public function entityViewAlter(&$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
    if ($this->moderationInfo
      ->isModeratableEntity($entity) && !$this->moderationInfo
      ->isLatestRevision($entity)) {

      // Hide quickedit, because its super confusing for the user to not edit
      // the live revision.
      unset($build['#attributes']['data-quickedit-entity-id']);
    }
  }

  /**
   * Implements hook_module_implements_alter().
   */
  public function moduleImplementsAlter(&$implementations, $hook) {
    if ($hook == 'entity_view_alter') {

      // Find the quickedit implementation and move workbench after it.
      unset($implementations['workbench_moderation']);
      $implementations['workbench_moderation'] = FALSE;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
InlineEditingDisabler::$moderationInfo protected property The moderation info.
InlineEditingDisabler::entityViewAlter public function Implements hook_entity_view_alter().
InlineEditingDisabler::moduleImplementsAlter public function Implements hook_module_implements_alter().
InlineEditingDisabler::__construct public function Creates a new InlineEditingDisabler instance.