Last active
August 16, 2021 11:32
-
-
Save szeidler/d456a7691de7871b3bdd8b9ce892253c to your computer and use it in GitHub Desktop.
drupal/scheduler Hardcoded local task dependency on view scheduler_scheduled_content https://www.drupal.org/project/scheduler/issues/3224340
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/scheduler.links.task.yml b/scheduler.links.task.yml | |
index fed60f7..88810ac 100644 | |
--- a/scheduler.links.task.yml | |
+++ b/scheduler.links.task.yml | |
@@ -10,22 +10,6 @@ scheduler.cron_tab: | |
weight: 10 | |
base_route: scheduler.admin_form | |
-content_moderation.content: | |
- # Use content_moderation.content which is the same key as is used in the core | |
- # Content Moderation module. If that modules is enabled this avoids two | |
- # 'Overview' links. If https://www.drupal.org/project/drupal/issues/3199682 | |
- # gets committed then this route could be removed from here. | |
- title: 'Overview' | |
- route_name: system.admin_content | |
- parent_id: system.admin_content | |
- | |
-scheduler.scheduled_content: | |
- title: 'Scheduled content' | |
- route_name: view.scheduler_scheduled_content.overview | |
- parent_id: system.admin_content | |
- # Overview seems to have weight 0 and moderated content is weight 1. | |
- weight: 5 | |
- | |
scheduler.media_overview: | |
# This is added so that we get an 'overview' sub-task link alongside the | |
# 'scheduled media' sub-task link. | |
diff --git a/scheduler.module b/scheduler.module | |
index 4e959da..235410f 100644 | |
--- a/scheduler.module | |
+++ b/scheduler.module | |
@@ -13,6 +13,7 @@ use Drupal\Core\Field\BaseFieldDefinition; | |
use Drupal\Core\Form\FormStateInterface; | |
use Drupal\Core\Routing\RouteMatchInterface; | |
use Drupal\Core\Url; | |
+use Drupal\views\Entity\View; | |
/** | |
* Implements hook_help(). | |
@@ -1048,3 +1049,38 @@ function scheduler_modules_installed($modules) { | |
function scheduler_cache_flush() { | |
\Drupal::service('scheduler.manager')->invalidatePluginCache(); | |
} | |
+ | |
+/** | |
+ * Implements hook_local_tasks_alter(). | |
+ */ | |
+function scheduler_local_tasks_alter(&$local_tasks) { | |
+ $view = View::load('scheduler_scheduled_content'); | |
+ if ($view && $view->getDisplay('overview')) { | |
+ // Views do not currently support defining secondary local tasks, define it | |
+ // dynamically if the view and display exists. Update this when | |
+ // https://www.drupal.org/project/drupal/issues/2172307 gets fixed. | |
+ $local_tasks['scheduler.scheduled_content'] = [ | |
+ 'title' => t('Scheduled content'), | |
+ 'route_name' => 'view.scheduler_scheduled_content.overview', | |
+ 'parent_id' => 'system.admin_content', | |
+ 'class' => 'Drupal\Core\Menu\LocalTaskDefault', | |
+ 'options' => [], | |
+ // Overview seems to have weight 0 and moderated content is weight 1. | |
+ 'weight' => 5, | |
+ ]; | |
+ } | |
+ | |
+ if (!isset($local_tasks['content_moderation.content'])) { | |
+ // Define a fallback overview local task if content_moderation is not | |
+ // enabled. If https://www.drupal.org/project/drupal/issues/3199682 | |
+ // gets committed then this route could be removed from here. | |
+ $local_tasks['content_moderation.content'] = [ | |
+ 'title' => t('Overview'), | |
+ 'route_name' => 'system.admin_content', | |
+ 'parent_id' => 'system.admin_content', | |
+ 'class' => 'Drupal\Core\Menu\LocalTaskDefault', | |
+ 'options' => [], | |
+ 'weight' => 0, | |
+ ]; | |
+ } | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment