Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take the flag status into account with the subscriptions. #123

Open
wants to merge 1 commit into
base: 8.x-1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions message_subscribe_ui/src/Controller/SubscriptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down