X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fcontent_moderation%2Fsrc%2FModeratedNodeListBuilder.php;fp=web%2Fcore%2Fmodules%2Fcontent_moderation%2Fsrc%2FModeratedNodeListBuilder.php;h=30b90f98cd4ba3f50297e8f5ebb7cd773ed222af;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/web/core/modules/content_moderation/src/ModeratedNodeListBuilder.php b/web/core/modules/content_moderation/src/ModeratedNodeListBuilder.php new file mode 100644 index 000000000..30b90f98c --- /dev/null +++ b/web/core/modules/content_moderation/src/ModeratedNodeListBuilder.php @@ -0,0 +1,128 @@ +entityTypeManager = $entity_type_manager; + } + + /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { + return new static( + $entity_type, + $container->get('entity.manager')->getStorage($entity_type->id()), + $container->get('date.formatter'), + $container->get('redirect.destination'), + $container->get('entity_type.manager') + ); + } + + /** + * {@inheritdoc} + */ + public function load() { + $revision_ids = $this->getEntityRevisionIds(); + return $this->storage->loadMultipleRevisions($revision_ids); + } + + /** + * Loads entity revision IDs using a pager sorted by the entity revision ID. + * + * @return array + * An array of entity revision IDs. + */ + protected function getEntityRevisionIds() { + $query = $this->entityTypeManager->getStorage('content_moderation_state')->getAggregateQuery() + ->aggregate('content_entity_id', 'MAX') + ->groupBy('content_entity_revision_id') + ->condition('content_entity_type_id', $this->entityTypeId) + ->condition('moderation_state', 'published', '<>') + ->sort('content_entity_revision_id', 'DESC'); + + // Only add the pager if a limit is specified. + if ($this->limit) { + $query->pager($this->limit); + } + + $result = $query->execute(); + + return $result ? array_column($result, 'content_entity_revision_id') : []; + } + + /** + * {@inheritdoc} + */ + public function buildHeader() { + $header = parent::buildHeader(); + $header['status'] = $this->t('Moderation state'); + + return $header; + } + + /** + * {@inheritdoc} + */ + public function buildRow(EntityInterface $entity) { + $row = parent::buildRow($entity); + $row['status'] = $entity->moderation_state->value; + + return $row; + } + + /** + * {@inheritdoc} + */ + public function render() { + $build = parent::render(); + $build['table']['#empty'] = $this->t('There is no moderated @label yet. Only pending versions of @label, such as drafts, are listed here.', ['@label' => $this->entityType->getLabel()]); + + return $build; + } + +}