You are here

public function ConfigEntityRevisionsRevertFormBase::__construct in Config Entity Revisions 1.x

Same name and namespace in other branches
  1. 8.2 src/ConfigEntityRevisionsRevertFormBase.php \Drupal\config_entity_revisions\ConfigEntityRevisionsRevertFormBase::__construct()
  2. 8 src/ConfigEntityRevisionsRevertFormBase.php \Drupal\config_entity_revisions\ConfigEntityRevisionsRevertFormBase::__construct()

Constructs a new class instance.

Parameters

\Drupal\Core\Entity\EntityTypeManager $entity_type_manager: The entity type manager.

\Drupal\Core\Datetime\DateFormatterInterface $date_formatter: The date formatter service.

\Drupal\Component\Datetime\TimeInterface $time: The time service.

\Drupal\Core\Messenger\MessengerInterface $messenger: The messenger service.

File

src/ConfigEntityRevisionsRevertFormBase.php, line 95

Class

ConfigEntityRevisionsRevertFormBase
Provides a form for reverting / publishing a revision.

Namespace

Drupal\config_entity_revisions

Code

public function __construct(EntityTypeManager $entity_type_manager, DateFormatterInterface $date_formatter, TimeInterface $time, MessengerInterface $messenger) {
  $this->entityTypeManager = $entity_type_manager;
  $this->dateFormatter = $date_formatter;
  $this->time = $time;
  $this->messenger = $messenger;
  $match = \Drupal::service('router')
    ->matchRequest(\Drupal::request());
  $this->config_entity = $match['config_entity']
    ->revisioned_entity();
  $this->revision_id = $match['revision_id'];
  $this->revision = $this->config_entity
    ->contentEntityStorage()
    ->loadRevision($this->revision_id);
  $revisionsID = $this->config_entity
    ->getContentEntityID();
  $latest_published = $this->config_entity
    ->contentEntityStorage()
    ->getLatestPublishedRevision($revisionsID);
  $publish = is_null($latest_published) || $this->revision
    ->getRevisionId() > $latest_published
    ->getRevisionId();
  $this->action = $publish ? 'publish' : 'revert';
}