Commit 3803b758 authored by Crell's avatar Crell

Issue #2701365 by Crell: Handle not-yet-created revision tracker table

Merge branch '2701365-legacy-tracker' into 8.x-1.x
parents 9c1b25cd f1bca1fc
......@@ -2,6 +2,7 @@
namespace Drupal\workbench_moderation\Plugin\views\filter;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
......@@ -30,6 +31,11 @@ class LatestRevision extends FilterPluginBase implements ContainerFactoryPluginI
*/
protected $joinHandler;
/**
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* Constructs a new LatestRevision.
*
......@@ -37,11 +43,14 @@ class LatestRevision extends FilterPluginBase implements ContainerFactoryPluginI
* @param string $plugin_id
* @param mixed $plugin_definition
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* @param \Drupal\views\Plugin\ViewsHandlerManager $join_handler
* @param \Drupal\Core\Database\Connection $connection
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, ViewsHandlerManager $join_handler) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, ViewsHandlerManager $join_handler, Connection $connection) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
$this->joinHandler = $join_handler;
$this->connection = $connection;
}
/**
......@@ -51,7 +60,8 @@ class LatestRevision extends FilterPluginBase implements ContainerFactoryPluginI
return new static(
$configuration, $plugin_id, $plugin_definition,
$container->get('entity_type.manager'),
$container->get('plugin.manager.views.join')
$container->get('plugin.manager.views.join'),
$container->get('database')
);
}
......@@ -74,6 +84,15 @@ class LatestRevision extends FilterPluginBase implements ContainerFactoryPluginI
* {@inheritdoc}
*/
public function query() {
// The table doesn't exist until a moderated node has been saved at least
// once. Just in case, disable this filter until then. Note that this means
// the view will still show all revisions, not just latest, but this is
// sufficiently edge-case-y that it's probably not worth the time to
// handle more robustly.
if (!$this->connection->schema()->tableExists('workbench_revision_tracker')) {
return;
}
$table = $this->ensureMyTable();
/** @var Sql $query */
......
......@@ -25,7 +25,7 @@ class LatestRevisionViewsFilterTest extends BrowserTestBase {
*
*/
public function testViewShowsCorrectNids() {
$this->createNodeType('Test', 'test');
$node_type = $this->createNodeType('Test', 'test');
$permissions = [
'access content',
......@@ -35,6 +35,20 @@ class LatestRevisionViewsFilterTest extends BrowserTestBase {
$this->drupalLogin($editor1);
// Make a pre-moderation node.
/** @var Node $node_0 */
$node_0 = Node::create([
'type' => 'test',
'title' => 'Node 0 - Rev 1',
'uid' => $editor1->id(),
]);
$node_0->save();
// Now enable moderation for subsequent nodes.
$node_type->setThirdPartySetting('workbench_moderation', 'enabled', TRUE);
$node_type->save();
// Make a node that is only ever in Draft.
/** @var Node $node_1 */
......@@ -92,6 +106,7 @@ class LatestRevisionViewsFilterTest extends BrowserTestBase {
$this->assertFalse($page->hasContent('Node 2 - Rev 1'));
$this->assertFalse($page->hasContent('Node 3 - Rev 1'));
$this->assertFalse($page->hasContent('Node 3 - Rev 2'));
$this->assertFalse($page->hasContent('Node 0 - Rev 1'));
}
/**
......@@ -101,6 +116,9 @@ class LatestRevisionViewsFilterTest extends BrowserTestBase {
* The human-readable label of the type to create.
* @param string $machine_name
* The machine name of the type to create.
*
* @return NodeType
* The node type just created.
*/
protected function createNodeType($label, $machine_name) {
/** @var NodeType $node_type */
......@@ -108,7 +126,9 @@ class LatestRevisionViewsFilterTest extends BrowserTestBase {
'type' => $machine_name,
'label' => $label,
]);
$node_type->setThirdPartySetting('workbench_moderation', 'enabled', TRUE);
$node_type->save();
return $node_type;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment