ModerationStateTransitionListBuilder.php in Workbench Moderation 8
File
src/ModerationStateTransitionListBuilder.php
View source
<?php
namespace Drupal\workbench_moderation;
use Drupal\Core\Config\Entity\DraggableListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ModerationStateTransitionListBuilder extends DraggableListBuilder {
protected $stateStorage;
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($entity_type, $container
->get('entity_type.manager')
->getStorage($entity_type
->id()), $container
->get('entity_type.manager')
->getStorage('moderation_state'));
}
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $transition_storage, EntityStorageInterface $state_storage) {
parent::__construct($entity_type, $transition_storage);
$this->stateStorage = $state_storage;
}
public function getFormId() {
return 'workbench_moderation_transition_list';
}
public function buildHeader() {
$header['label'] = $this
->t('Moderation state transition');
$header['id'] = $this
->t('Machine name');
$header['from'] = $this
->t('From state');
$header['to'] = $this
->t('To state');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity
->label();
$row['id']['#markup'] = $entity
->id();
$row['from']['#markup'] = $this->stateStorage
->load($entity
->getFromState())
->label();
$row['to']['#markup'] = $this->stateStorage
->load($entity
->getToState())
->label();
return $row + parent::buildRow($entity);
}
public function render() {
$build = parent::render();
$build['item'] = [
'#type' => 'item',
'#markup' => $this
->t('When saving an entity, only a destination state that has a transition is legal. That includes its current state. If you want to allow an entity to be saved without changing its state then you must define a transition from that state to itself. Note that all users will still need permission to use a defined transition.'),
'#weight' => -5,
];
return $build;
}
}