Commit 185d88c6 authored by Stephen Mustgrave's avatar Stephen Mustgrave
Browse files

Issue #3306248: D10 Compatibility

parent c1bfc6e1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@
        "source": "https://git.drupalcode.org/project/moderation_dashboard"
    },
    "require": {
        "drupal/core": "^8.7.7 || ^9",
        "drupal/core": "^9 || ^10",
        "drupal/page_manager": "*",
        "drupal/panels": "*"
    }
+1 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ name: Moderation dashboard
description: 'Provides a per-user dashboard for moderation.'
type: module
package: Other
core_version_requirement: '^8.7.7 || ^9'
core_version_requirement: '^9 || ^10'
configure: moderation_dashboard.settings
dependencies:
  - drupal:content_moderation
+1 −1
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ activity:
    js/moderation_dashboard_activity.js: {}
  dependencies:
    - core/jquery
    - core/jquery.once
    - core/once

chart.js.internal:
  js:
+46 −6
Original line number Diff line number Diff line
@@ -2,9 +2,12 @@

namespace Drupal\moderation_dashboard\Plugin\views\field;

use Drupal\content_moderation\ModerationInformationInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Url;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * A Views field which provides a link to the latest version of an Entity.
@@ -13,22 +16,59 @@ use Drupal\views\ResultRow;
 */
class LinkToLatestVersion extends FieldPluginBase {

  /**
   * The EntityTypeManager service.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The content moderation information.
   *
   * @var \Drupal\content_moderation\ModerationInformationInterface
   */
  protected $moderationInformation;

  /**
   * {@inheritdoc}
   */
  public function render(ResultRow $values) {
    /** @var \Drupal\content_moderation\ModerationInformation $information */
    $moderation_information = \Drupal::service('content_moderation.moderation_information');
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, ModerationInformationInterface $moderation_information) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->entityTypeManager = $entity_type_manager;
    $this->moderationInformation = $moderation_information;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $container->get('entity_type.manager'),
      $container->get('content_moderation.moderation_information')
    );
  }


  /**
   * {@inheritdoc}
   */
  public function render(ResultRow $values) {
    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    $entity = $this->getEntity($values);
    $entity_type_id = $entity->getEntityTypeId();

    if (
      $moderation_information->isModeratedEntity($entity) &&
      $moderation_information->hasPendingRevision($entity)
      $this->moderationInformation->isModeratedEntity($entity) &&
      $this->moderationInformation->hasPendingRevision($entity)
    ) {
      $entity = $moderation_information->getLatestRevision($entity_type_id, $entity->id());
      $node_storage = $this->entityTypeManager->getStorage('node');
      $latest_revision_id = $node_storage->getLatestRevisionId($entity->id());
      $entity = $node_storage->loadRevision($latest_revision_id);

      $build = [
        '#title' => $entity->label(),
        '#type' => 'link',
+1 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ class ModerationDashboardPermissionTest extends BrowserTestBase {
      'type' => 'page',
    ]);
    $workflow = $this->createEditorialWorkflow();
    // @phpstan-ignore-next-line
    $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page');
    $workflow->save();
  }
Loading