diff --git a/config/optional/views.view.content_revisions.yml b/config/optional/views.view.content_revisions.yml index 143ca0e..b00f997 100644 --- a/config/optional/views.view.content_revisions.yml +++ b/config/optional/views.view.content_revisions.yml @@ -1,4 +1,3 @@ -uuid: b4670ff2-6960-43ac-a12b-43ee0b888274 langcode: en status: true dependencies: @@ -127,6 +126,71 @@ display: row: type: fields fields: + title: + id: title + table: node_field_revision + field: title + relationship: none + group_type: group + admin_label: '' + label: Title + exclude: true + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: string + settings: + link_to_entity: false + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + entity_type: node + entity_field: title + plugin_id: field changed: id: changed table: node_field_revision @@ -535,8 +599,23 @@ display: destination: true plugin_id: dropbutton filters: { } - sorts: { } - title: 'Revisions for %node_title%' + sorts: + changed: + id: changed + table: node_field_revision + field: changed + relationship: none + group_type: group + admin_label: '' + order: DESC + exposed: false + expose: + label: '' + granularity: second + entity_type: node + entity_field: changed + plugin_id: date + title: 'Revisions for {{ title }}' header: { } footer: { } empty: { } @@ -598,6 +677,16 @@ display: display_options: display_extenders: { } path: node/%/revisions + menu: + type: tab + title: Revisions + description: '' + expanded: false + parent: '' + weight: 0 + context: '0' + menu_name: main + enabled: true cache_metadata: max-age: 0 contexts: diff --git a/src/Plugin/views/field/RevisionLinkSetCurrent.php b/src/Plugin/views/field/RevisionLinkSetCurrent.php index a23ee9c..7e906a8 100644 --- a/src/Plugin/views/field/RevisionLinkSetCurrent.php +++ b/src/Plugin/views/field/RevisionLinkSetCurrent.php @@ -2,13 +2,16 @@ /** * @file - * Contains Drupal\moderation_state\Plugin\views\field\RevisionLinkSetCurrent + * Contains \Drupal\moderation_state\Plugin\views\field\RevisionLinkSetCurrent */ namespace Drupal\moderation_state\Plugin\views\field; +use Drupal\Core\Access\AccessManagerInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\node\Plugin\views\field\RevisionLinkRevert; use Drupal\views\ResultRow; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides a field handler so set a revision as current. @@ -20,6 +23,52 @@ use Drupal\views\ResultRow; class RevisionLinkSetCurrent extends RevisionLinkRevert { /** + * The access manager service. + * + * @var \Drupal\Core\Access\AccessManagerInterface + */ + protected $accessManager; + + /** + * The entity type manager. + * + * @var \Drupal\Core\Entity\EntityTypeManagerInterface + */ + protected $entityTypeManager; + + /** + * Constructs a RevisionLinkSetCurrent object. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\Access\AccessManagerInterface $access_manager + * The access manager. + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager + * The entity type manager. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, AccessManagerInterface $access_manager, EntityTypeManagerInterface $entity_type_manager) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $access_manager); + $this->entityTypeManager = $entity_type_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('access_manager'), + $container->get('entity_type.manager') + ); + } + + /** * {@inheritdoc} */ protected function getDefaultLabel() { @@ -30,17 +79,18 @@ class RevisionLinkSetCurrent extends RevisionLinkRevert { * {@inheritdoc} */ protected function renderLink(ResultRow $row) { + $text = parent::renderLink($row); /* @var \Drupal\node\NodeInterface $node */ $node = $this->getEntity($row); - if (!$node->getRevisionid()) { - return ''; + /* @var \Drupal\node\NodeTypeInterface $node_type */ + $node_type = $this->entityTypeManager->getStorage('node_type')->load($node->bundle()); + if (!$node_type->getThirdPartySetting('moderation_state', 'enabled', FALSE)) { + // @todo write a test for this. + return $text; } - // @todo This method doesn't get called to test this logic. if ($node->isDefaultRevision()) { return ''; } - $text = parent::renderLink($row); - $this->options['alter']['query'] = $this->getDestinationArray(); return $text; } }