From 54bd2fbae5154de3210a0d9736b8c266dbba9d3e Mon Sep 17 00:00:00 2001 From: "Frederic G. MARAND" Date: Tue, 2 May 2017 11:39:13 +0200 Subject: [PATCH] content_moderation: WIP. --- src/Workflows/ContentModerationGraph.php | 24 ++++++++++--------- src/Workflows/ContentModerationReportBase.php | 12 +++++----- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/Workflows/ContentModerationGraph.php b/src/Workflows/ContentModerationGraph.php index 11501af..eb651f6 100644 --- a/src/Workflows/ContentModerationGraph.php +++ b/src/Workflows/ContentModerationGraph.php @@ -3,15 +3,15 @@ namespace Drupal\qa\Workflows; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; -use Drupal\Core\Entity\EntityStorageInterface; +use Drupal\Core\Config\Entity\ConfigEntityStorageInterface; +use Drupal\Core\Entity\ContentEntityStorageInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\qa\Workflows\ContentModerationReportBase; use Grafizzi\Graph\Attribute; use Grafizzi\Graph\Edge; use Grafizzi\Graph\Graph; use Grafizzi\Graph\Node; -use Monolog\Handler\StreamHandler; -use Monolog\Logger; use Pimple\Container; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -26,10 +26,10 @@ class ContentModerationGraph extends ContentModerationReportBase implements Cont */ protected $pimple; - public function __construct(EntityStorageInterface $stateStorage, EntityStorageInterface $transStorage, Container $pimple) { + public function __construct(ContentEntityStorageInterface $stateStorage, ConfigEntityStorageInterface $workflowStorage, Container $pimple) { $this->pimple = $pimple; $this->stateStorage = $stateStorage; - $this->transStorage = $transStorage; + $this->workflowStorage = $workflowStorage; } /** @@ -84,19 +84,21 @@ public static function create(ContainerInterface $container) { /** @var EntityTypeManagerInterface $etm */ $etm = $container->get('entity_type.manager'); - $stateStorage = $etm->getStorage('moderation_state'); - $transStorage = $etm->getStorage('moderation_state_transition'); + /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $stateStorage */ + $stateStorage = $etm->getStorage('content_moderation_state'); - $logger = new Logger(basename(__FILE__, '.php')); - // Change the minimum logging level using the Logger:: constants. - $logger->pushHandler(new StreamHandler('php://stderr', Logger::INFO)); + /** @var \Psr\Log\LoggerInterface $logger */ + $logger = $container->get('logger.channel.qa'); + + /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $stateStorage */ + $workflowStorage = $etm->getStorage('workflow'); $pimple = new Container([ 'logger' => $logger, 'directed' => TRUE, ]); - return new static($stateStorage, $transStorage, $pimple); + return new static($stateStorage, $workflowStorage, $pimple); } public function report() { diff --git a/src/Workflows/ContentModerationReportBase.php b/src/Workflows/ContentModerationReportBase.php index 12afde3..16398a6 100644 --- a/src/Workflows/ContentModerationReportBase.php +++ b/src/Workflows/ContentModerationReportBase.php @@ -1,6 +1,6 @@ getStates()); - $stateCells = array_map(function ($stateId) { - return []; - }, array_flip($stateIds)); + + $stateCells = array_fill(0, count($stateIds), []); foreach ($stateIds as $stateId) { $grid[$stateId] = $stateCells; @@ -50,6 +49,7 @@ public function getDuplicateTransLabels() { protected function getStates() { $fullStates = $this->stateStorage->loadMultiple(); + print_R($fullStates); $simpleStates = array_map(function ($entity) { return $entity->label(); }, $fullStates); @@ -58,7 +58,7 @@ protected function getStates() { } protected function getTrans() { - $fullTrans = $this->transStorage->loadMultiple(); + $fullTrans = $this->workflowStorage->loadMultiple(); $simpleTrans = array_map(function ($trans) { return [ 'label' => $trans->label(),