diff --git a/src/Plugin/Block/ContentListBlock.php b/src/Plugin/Block/ContentListBlock.php index c7f689e7cf4ed2d08fe9366e2fc84be5b6ecf97d..78303338f17e69e3f331635034dd682b9d4e92c7 100644 --- a/src/Plugin/Block/ContentListBlock.php +++ b/src/Plugin/Block/ContentListBlock.php @@ -103,6 +103,23 @@ class ContentListBlock extends BlockBase implements ContainerFactoryPluginInterf $view->removeHandler($view->current_display, 'filter', 'type'); } + // Process Default moderation state filter field. + if (isset($this->configuration['moderation_state'])) { + + // Get moderation state. + $state = $this->configuration['moderation_state']; + + // Get current handler with old value. + $moderation_state = $view->getHandler($display_id, 'filter', 'current_state_views_filter'); + + // Set moderation_state configuration value. + $moderation_state['value'] = [$state => $state]; + + // Set handler with new value. + $view->setHandler($display_id, 'filter', 'current_state_views_filter', $moderation_state); + + } + // Check if we have an author restriction, if so add to arguments and // remove from exposed filters. if (isset($this->configuration['display_my_content']) && $this->configuration['display_my_content']) { @@ -209,6 +226,20 @@ class ContentListBlock extends BlockBase implements ContainerFactoryPluginInterf '#default_value' => isset($this->configuration['content_type']) ? $this->configuration['content_type'] : 'all', ]; + // Set the content type form element. + $form['filters']['moderation_state'] = [ + '#type' => 'select', + '#title' => $this->t('Default moderation state filter'), + '#options' => [ + 'All' => $this->t('- Any -'), + 'uw_workflow-uw_wf_archived' => $this->t('Archived'), + 'uw_workflow-draft' => $this->t('Draft'), + 'uw_workflow-uw_wf_needs_review' => $this->t('Needs Review'), + 'uw_workflow-published' => $this->t('Published'), + ], + '#default_value' => isset($this->configuration['moderation_state']) ? $this->configuration['moderation_state'] : 'All', + ]; + // Set the display only my content form element. $form['filters']['display_my_content'] = [ '#type' => 'select', @@ -260,6 +291,9 @@ class ContentListBlock extends BlockBase implements ContainerFactoryPluginInterf // Set the config for content type. $this->configuration['content_type'] = $values['filters']['content_type']; + // Set the config for moderation state. + $this->configuration['moderation_state'] = $values['filters']['moderation_state']; + // Set the config for displaying only my content. $this->configuration['display_my_content'] = $values['filters']['display_my_content'];