diff -u b/content_planner.services.yml b/content_planner.services.yml --- b/content_planner.services.yml +++ b/content_planner.services.yml @@ -12,6 +12,6 @@ parent: default_plugin_manager - content_planner.kanban_service: - class: Drupal\content_planner\DashboardKanbanService + content_planner.content_moderation_service: + class: Drupal\content_planner\ContentModerationService arguments: ['@entity_type.manager'] reverted: --- b/src/DashboardKanbanService.php +++ /dev/null @@ -1,116 +0,0 @@ -entityTypeManager = $entityTypeManager; - } - - /** - * Gets the Content Moderation Entities. - * - * @param string $workflow - * The workflow ID. - * @param array $filters - * An array with the filters. - * @param array $entities - * An array with the entities. - * - * @return \Drupal\content_moderation\Entity\ContentModerationState[] - * Returns an array with the content moderation states for the given - * workflow. - */ - public function getEntityContentModerationEntities($workflow, array $filters = [], array $entities = []) { - $result = []; - try { - $query = $this->entityTypeManager->getStorage('content_moderation_state')->getQuery(); - if (!empty(array_keys($entities))) { - $query->condition('workflow', $workflow); - $query->condition('content_entity_type_id', array_keys($entities), 'in'); - } - - // Moderation state filter. - if (array_key_exists('moderation_state', $filters) && $filters['moderation_state']) { - $query->condition('moderation_state', $filters['moderation_state']); - } - - // User ID filter. - if (array_key_exists('uid', $filters) && $filters['uid']) { - $query->condition('uid', $filters['uid']); - } - - // User ID filter. - $result = $query->execute(); - } - catch (InvalidPluginDefinitionException $e) { - watchdog_exception('content_kanban', $e); - } - catch (PluginNotFoundException $e) { - watchdog_exception('content_kanban', $e); - } - if ($result) { - return ContentModerationState::loadMultiple($result); - } - - return $result; - } - - /** - * Gets the entity IDs from Content Moderation entities. - * - * @param string $workflow - * The workflow id. - * @param array $filters - * An array with the filters. - * @param array $entities - * An array with the entities. - * - * @return array - * Returns an array with the entity ids. - */ - public function getEntityIdsFromContentModerationEntities($workflow, array $filters = [], array $entities = []) { - $entityIds = []; - - if ($content_moderation_states = $this->getEntityContentModerationEntities($workflow, $filters, $entities)) { - foreach ($content_moderation_states as $content_moderation_state) { - - // Get property. - $content_entity_id_property = $content_moderation_state->content_entity_id; - - // Get value. - $content_entity_id_value = $content_entity_id_property->getValue(); - $entity_type_id_value = $content_moderation_state->get('content_entity_type_id')->getValue(); - // Get the entity type id. - $entity_type_id = $entity_type_id_value[0]['value']; - // Build the ids array with entity type as key. - $entityIds[$entity_type_id][] = $content_entity_id_value[0]['value']; - } - - } - return $entityIds; - } - -} diff -u b/src/Plugin/DashboardBlock/UserBlock.php b/src/Plugin/DashboardBlock/UserBlock.php --- b/src/Plugin/DashboardBlock/UserBlock.php +++ b/src/Plugin/DashboardBlock/UserBlock.php @@ -8,8 +8,6 @@ use Drupal\user\Entity\Role; use Drupal\user\Entity\User; use Symfony\Component\HttpFoundation\Request; -use Drupal\Core\StringTranslation\StringTranslationTrait; - /** * Provides a user block for Content Planner Dashboard. * @@ -20,9 +18,6 @@ */ class UserBlock extends DashboardBlockBase { - - use StringTranslationTrait; - /** * Builds the render array for a dashboard block. * @@ -143,13 +138,13 @@ * The content count for the given user and the given moderation state. */ public function getUserContentWorkflowCount($user_id, $moderation_state) { - $kanban_service = \Drupal::service('content_planner.kanban_service'); + $content_moderation_service = \Drupal::service('content_planner.content_moderation_service'); $filters = [ 'uid' => $user_id, 'moderation_state' => $moderation_state, ]; - $nids = $kanban_service->getEntityIdsFromContentModerationEntities('netnode', $filters); + $nids = $content_moderation_service->getEntityIdsFromContentModerationEntities('netnode', $filters); return count($nids); } @@ -206,8 +201,8 @@ return [ '#type' => 'checkboxes', - '#title' => $this->t('Which Roles to display'), - '#description' => $this->t('Select which Roles should be displayed in the block.'), + '#title' => t('Which Roles to display'), + '#description' => t('Select which Roles should be displayed in the block.'), '#required' => TRUE, '#options' => $roles_options, '#default_value' => $default_value, only in patch2: unchanged: --- a/modules/content_kanban/src/Form/KanbanFilterForm.php +++ b/modules/content_kanban/src/Form/KanbanFilterForm.php @@ -4,13 +4,13 @@ namespace Drupal\content_kanban\Form; use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; use Drupal\Component\Plugin\Exception\PluginNotFoundException; -use Drupal\content_kanban\KanbanService; use Drupal\Core\Entity\EntityTypeManager; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Link; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\content_kanban\Form\SettingsForm; +use Drupal\content_planner\ContentModerationService; use Drupal\node\Entity\NodeType; /** @@ -19,11 +19,11 @@ use Drupal\node\Entity\NodeType; class KanbanFilterForm extends FormBase { /** - * The Kanban service. + * The Content Moderation service. * - * @var \Drupal\content_kanban\KanbanService + * @var \Drupal\content_planner\ContentModerationService */ - protected $kanbanService; + protected $contentModerationService; /** * An array with the form params. @@ -42,8 +42,8 @@ class KanbanFilterForm extends FormBase { /** * {@inheritdoc} */ - public function __construct(KanbanService $kanban_service, EntityTypeManager $entityTypeManager) { - $this->kanbanService = $kanban_service; + public function __construct(ContentModerationService $content_moderation_service, EntityTypeManager $entityTypeManager) { + $this->contentModerationService = $content_moderation_service; $this->entityTypeManager = $entityTypeManager; } @@ -52,7 +52,7 @@ class KanbanFilterForm extends FormBase { */ public static function create(ContainerInterface $container) { return new static( - $container->get('content_kanban.kanban_service'), + $container->get('content_planner.content_moderation_service'), $container->get('entity_type.manager') ); } @@ -165,7 +165,7 @@ class KanbanFilterForm extends FormBase { $options = []; // Load Content Moderation entities. - $content_moderation_entities = $this->kanbanService->getEntityContentModerationEntities($this->formParams['workflow_id']); + $content_moderation_entities = $this->contentModerationService->getEntityContentModerationEntities($this->formParams['workflow_id']); foreach ($content_moderation_entities as $content_moderation_entity) { // Get the entity id and entity type id. $entityId = $content_moderation_entity->content_entity_id->value; only in patch2: unchanged: --- a/modules/content_kanban/src/KanbanService.php +++ b/modules/content_kanban/src/KanbanService.php @@ -195,90 +195,6 @@ class KanbanService { return $this->definedColors[$index]; } - /** - * Gets the Content Moderation Entities. - * - * @param string $workflow - * The workflow ID. - * @param array $filters - * An array with the filters. - * @param array $entities - * An array with the entities. - * - * @return \Drupal\content_moderation\Entity\ContentModerationState[] - * Returns an array with the content moderation states for the given - * workflow. - */ - public function getEntityContentModerationEntities($workflow, array $filters = [], array $entities = []) { - $result = []; - try { - $query = $this->entityTypeManager->getStorage('content_moderation_state')->getQuery(); - if (!empty(array_keys($entities))) { - $query->condition('workflow', $workflow); - $query->condition('content_entity_type_id', array_keys($entities), 'in'); - } - - // Moderation state filter. - if (array_key_exists('moderation_state', $filters) && $filters['moderation_state']) { - $query->condition('moderation_state', $filters['moderation_state']); - } - - // User ID filter. - if (array_key_exists('uid', $filters) && $filters['uid']) { - $query->condition('uid', $filters['uid']); - } - - // User ID filter. - $result = $query->execute(); - } - catch (InvalidPluginDefinitionException $e) { - watchdog_exception('content_kanban', $e); - } - catch (PluginNotFoundException $e) { - watchdog_exception('content_kanban', $e); - } - if ($result) { - return ContentModerationState::loadMultiple($result); - } - - return $result; - } - - /** - * Gets the entity IDs from Content Moderation entities. - * - * @param string $workflow - * The workflow id. - * @param array $filters - * An array with the filters. - * @param array $entities - * An array with the entities. - * - * @return array - * Returns an array with the entity ids. - */ - public function getEntityIdsFromContentModerationEntities($workflow, array $filters = [], array $entities = []) { - $entityIds = []; - - if ($content_moderation_states = $this->getEntityContentModerationEntities($workflow, $filters, $entities)) { - foreach ($content_moderation_states as $content_moderation_state) { - - // Get property. - $content_entity_id_property = $content_moderation_state->content_entity_id; - - // Get value. - $content_entity_id_value = $content_entity_id_property->getValue(); - $entity_type_id_value = $content_moderation_state->get('content_entity_type_id')->getValue(); - // Get the entity type id. - $entity_type_id = $entity_type_id_value[0]['value']; - // Build the ids array with entity type as key. - $entityIds[$entity_type_id][] = $content_entity_id_value[0]['value']; - } - - } - return $entityIds; - } - /** * Gets the entities by Type. * only in patch2: unchanged: --- /dev/null +++ b/src/ContentModerationService.php @@ -0,0 +1,116 @@ +entityTypeManager = $entityTypeManager; + } + + /** + * Gets the Content Moderation Entities. + * + * @param string $workflow + * The workflow ID. + * @param array $filters + * An array with the filters. + * @param array $entities + * An array with the entities. + * + * @return \Drupal\content_moderation\Entity\ContentModerationState[] + * Returns an array with the content moderation states for the given + * workflow. + */ + public function getEntityContentModerationEntities($workflow, array $filters = [], array $entities = []) { + $result = []; + try { + $query = $this->entityTypeManager->getStorage('content_moderation_state')->getQuery(); + if (!empty(array_keys($entities))) { + $query->condition('workflow', $workflow); + $query->condition('content_entity_type_id', array_keys($entities), 'in'); + } + + // Moderation state filter. + if (array_key_exists('moderation_state', $filters) && $filters['moderation_state']) { + $query->condition('moderation_state', $filters['moderation_state']); + } + + // User ID filter. + if (array_key_exists('uid', $filters) && $filters['uid']) { + $query->condition('uid', $filters['uid']); + } + + // User ID filter. + $result = $query->execute(); + } + catch (InvalidPluginDefinitionException $e) { + watchdog_exception('content_planner', $e); + } + catch (PluginNotFoundException $e) { + watchdog_exception('content_planner', $e); + } + if ($result) { + return ContentModerationState::loadMultiple($result); + } + + return $result; + } + + /** + * Gets the entity IDs from Content Moderation entities. + * + * @param string $workflow + * The workflow id. + * @param array $filters + * An array with the filters. + * @param array $entities + * An array with the entities. + * + * @return array + * Returns an array with the entity ids. + */ + public function getEntityIdsFromContentModerationEntities($workflow, array $filters = [], array $entities = []) { + $entityIds = []; + + if ($content_moderation_states = $this->getEntityContentModerationEntities($workflow, $filters, $entities)) { + foreach ($content_moderation_states as $content_moderation_state) { + + // Get property. + $content_entity_id_property = $content_moderation_state->content_entity_id; + + // Get value. + $content_entity_id_value = $content_entity_id_property->getValue(); + $entity_type_id_value = $content_moderation_state->get('content_entity_type_id')->getValue(); + // Get the entity type id. + $entity_type_id = $entity_type_id_value[0]['value']; + // Build the ids array with entity type as key. + $entityIds[$entity_type_id][] = $content_entity_id_value[0]['value']; + } + + } + return $entityIds; + } + +}