diff --git a/core/modules/comment/src/Plugin/views/wizard/Comment.php b/core/modules/comment/src/Plugin/views/wizard/Comment.php index 61d92c5..a74168d 100644 --- a/core/modules/comment/src/Plugin/views/wizard/Comment.php +++ b/core/modules/comment/src/Plugin/views/wizard/Comment.php @@ -28,14 +28,6 @@ class Comment extends WizardPluginBase { * Set default values for the filters. */ protected $filters = [ - 'status' => [ - 'value' => TRUE, - 'table' => 'comment_field_data', - 'field' => 'status', - 'plugin_id' => 'boolean', - 'entity_type' => 'comment', - 'entity_field' => 'status', - ], 'status_node' => [ 'value' => TRUE, 'table' => 'node_field_data', diff --git a/core/modules/media/src/Plugin/views/wizard/Media.php b/core/modules/media/src/Plugin/views/wizard/Media.php index eb45701..30a7ad6 100644 --- a/core/modules/media/src/Plugin/views/wizard/Media.php +++ b/core/modules/media/src/Plugin/views/wizard/Media.php @@ -23,22 +23,6 @@ class Media extends WizardPluginBase { protected $createdColumn = 'media_field_data-created'; /** - * Set default values for the filters. - * - * @var array - */ - protected $filters = [ - 'status' => [ - 'value' => '1', - 'table' => 'media_field_data', - 'field' => 'status', - 'plugin_id' => 'boolean', - 'entity_type' => 'media', - 'entity_field' => 'status', - ], - ]; - - /** * {@inheritdoc} */ public function getAvailableSorts() { diff --git a/core/modules/media/src/Plugin/views/wizard/MediaRevision.php b/core/modules/media/src/Plugin/views/wizard/MediaRevision.php index 7abc41a..10b5154 100644 --- a/core/modules/media/src/Plugin/views/wizard/MediaRevision.php +++ b/core/modules/media/src/Plugin/views/wizard/MediaRevision.php @@ -23,22 +23,6 @@ class MediaRevision extends WizardPluginBase { protected $createdColumn = 'media_field_revision-created'; /** - * Set default values for the filters. - * - * @var array - */ - protected $filters = [ - 'status' => [ - 'value' => '1', - 'table' => 'media_field_revision', - 'field' => 'status', - 'plugin_id' => 'boolean', - 'entity_type' => 'media', - 'entity_field' => 'status', - ], - ]; - - /** * {@inheritdoc} */ protected function defaultDisplayOptions() { diff --git a/core/modules/node/src/Plugin/views/wizard/Node.php b/core/modules/node/src/Plugin/views/wizard/Node.php index 34d4bcf..1be211f 100644 --- a/core/modules/node/src/Plugin/views/wizard/Node.php +++ b/core/modules/node/src/Plugin/views/wizard/Node.php @@ -26,20 +26,6 @@ class Node extends WizardPluginBase { protected $createdColumn = 'node_field_data-created'; /** - * Set default values for the filters. - */ - protected $filters = [ - 'status' => [ - 'value' => TRUE, - 'table' => 'node_field_data', - 'field' => 'status', - 'plugin_id' => 'boolean', - 'entity_type' => 'node', - 'entity_field' => 'status', - ] - ]; - - /** * Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::getAvailableSorts(). * * @return array diff --git a/core/modules/node/src/Plugin/views/wizard/NodeRevision.php b/core/modules/node/src/Plugin/views/wizard/NodeRevision.php index 9c3465d..258d6d3 100644 --- a/core/modules/node/src/Plugin/views/wizard/NodeRevision.php +++ b/core/modules/node/src/Plugin/views/wizard/NodeRevision.php @@ -25,20 +25,6 @@ class NodeRevision extends WizardPluginBase { protected $createdColumn = 'changed'; /** - * Set default values for the filters. - */ - protected $filters = [ - 'status' => [ - 'value' => TRUE, - 'table' => 'node_field_revision', - 'field' => 'status', - 'plugin_id' => 'boolean', - 'entity_type' => 'node', - 'entity_field' => 'status', - ] - ]; - - /** * Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::rowStyleOptions(). * * Node revisions do not support full posts or teasers, so remove them. diff --git a/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php b/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php index 1771c71..4984994 100644 --- a/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php +++ b/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php @@ -3,6 +3,7 @@ namespace Drupal\views\Plugin\views\wizard; use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Entity\EntityPublishedInterface; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\UrlGeneratorTrait; @@ -140,7 +141,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition $entity_types = \Drupal::entityManager()->getDefinitions(); foreach ($entity_types as $entity_type_id => $entity_type) { - if ($this->base_table == $entity_type->getBaseTable() || $this->base_table == $entity_type->getDataTable()) { + if (in_array($this->base_table, [$entity_type->getBaseTable(), $entity_type->getDataTable(), $entity_type->getRevisionTable(), $entity_type->getRevisionDataTable()], TRUE)) { $this->entityType = $entity_type; $this->entityTypeId = $entity_type_id; } @@ -165,6 +166,21 @@ public function getCreatedColumn() { public function getFilters() { $filters = []; + // Add a default filter on the publishing status field, if available. + if (is_subclass_of($this->entityType->getClass(), EntityPublishedInterface::class)) { + $field_name = $this->entityType->getKey('published'); + $this->filters = [ + $field_name => [ + 'value' => TRUE, + 'table' => $this->base_table, + 'field' => $field_name, + 'plugin_id' => 'boolean', + 'entity_type' => $this->entityTypeId, + 'entity_field' => $field_name, + ] + ] + $this->filters; + } + $default = $this->filter_defaults; foreach ($this->filters as $name => $info) {