diff --git a/message_subscribe_ui/src/Controller/SubscriptionController.php b/message_subscribe_ui/src/Controller/SubscriptionController.php index d6a8a38..e4bb857 100644 --- a/message_subscribe_ui/src/Controller/SubscriptionController.php +++ b/message_subscribe_ui/src/Controller/SubscriptionController.php @@ -92,9 +92,15 @@ public static function create(ContainerInterface $container) { */ public function tabAccess(AccountInterface $user, FlagInterface $flag = NULL) { if (!$flag) { - // We are inside /message-subscribe so get the first flag. + // We are inside /message-subscribe so get the first enabled flag. $flags = $this->subscribers->getFlags(); - $flag = reset($flags); + foreach ($flags as $_flag) { + if ($_flag->status()) { + // Fetch the first enabled flag. + $flag = $_flag; + break; + } + } } if (!$flag) { @@ -144,14 +150,26 @@ public function tabTitle(FlagInterface $flag) { */ public function tab(UserInterface $user, FlagInterface $flag = NULL) { if (!$flag) { - // We are inside /message-subscribe so get the first flag. + // We are inside /message-subscribe so get the first enabled flag. $flags = $this->subscribers->getFlags(); - $flag = reset($flags); + foreach ($flags as $_flag) { + if ($_flag->status()) { + // Fetch the first enabled flag. + $flag = $_flag; + break; + } + } } $view = $this->getView($user, $flag); $result = $view->preview(); + // Add contextual links to the view for developer purposes. + $result['#view']->element['#view_id'] = $view->id(); + $result['#view']->element['#view_display_show_admin_links'] = $view->getShowAdminLinks(); + $result['#view']->element['#view_display_plugin_id'] = $view->display_handler->getPluginId(); + views_add_contextual_links($result['#view']->element, 'view', $view->current_display); + // Add cache tags for this flag and view. $result['#cache']['tags'] = $flag->getCacheTags() + $view->getCacheTags(); return $result; diff --git a/message_subscribe_ui/src/Plugin/Derivative/MessageSubscribeUiLocalTask.php b/message_subscribe_ui/src/Plugin/Derivative/MessageSubscribeUiLocalTask.php index 6be1975..9ab1f8d 100644 --- a/message_subscribe_ui/src/Plugin/Derivative/MessageSubscribeUiLocalTask.php +++ b/message_subscribe_ui/src/Plugin/Derivative/MessageSubscribeUiLocalTask.php @@ -46,6 +46,10 @@ public function getDerivativeDefinitions($base_plugin_definition) { $first = TRUE; foreach ($this->subscribers->getFlags() as $flag) { + if (!$flag->status()) { + // Ignore disabled flags. + continue; + } $this->derivatives[$flag->id()] = [ 'title' => $flag->label(), // First route gets the same route name as the parent (in order to