Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finalize content_moderation / workflows commands #20

Open
wants to merge 1 commit into
base: 8.x-1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions src/Workflows/ContentModerationGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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() {
Expand Down
12 changes: 6 additions & 6 deletions src/Workflows/ContentModerationReportBase.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Drupal\magpjm\Workflows;
namespace Drupal\qa\Workflows;

use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
Expand All @@ -11,14 +11,13 @@ abstract class ContentModerationReportBase implements ContainerInjectionInterfac

protected $stateStorage;

protected $transStorage;
protected $workflowStorage;

protected function buildGrid() {
$grid = [];
$stateIds = array_keys($this->getStates());
$stateCells = array_map(function ($stateId) {
return [];
}, array_flip($stateIds));

$stateCells = array_fill(0, count($stateIds), []);

foreach ($stateIds as $stateId) {
$grid[$stateId] = $stateCells;
Expand Down Expand Up @@ -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);
Expand All @@ -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(),
Expand Down