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

Add routePersistence parameter to Page::resolveMenuItem() #1239

Merged
merged 1 commit into from
Oct 30, 2024

Conversation

mjauvin
Copy link
Member

@mjauvin mjauvin commented Oct 26, 2024

This permits reusing Cms Page resolveMenuItem with or without route persistence for the call to pageUrl().

The default behavior is unchanged as we default to false for route persistence.

@mjauvin mjauvin added the maintenance PRs that fix bugs, are translation changes or make only minor changes label Oct 26, 2024
@mjauvin mjauvin added this to the 1.2.7 milestone Oct 26, 2024
@mjauvin mjauvin self-assigned this Oct 26, 2024
@LukeTowers
Copy link
Member

Can you provide your usage example here along with why you needed routePersistence enabled for your use case?

@mjauvin
Copy link
Member Author

mjauvin commented Oct 26, 2024

@LukeTowers On the Project sub-section of this website, the menubar changes and all pages depend on the project slug, so their url is project/:slug/page (e.g. project/:slug/about, project/:slug/team, etc.)

In order to render the menu for those pages, the slug in their url needs to inherit the project slug, hence the route persistence.

@mjauvin
Copy link
Member Author

mjauvin commented Oct 26, 2024

With this PR, I can use the following in my component:

Event::listen('pages.menuitem.resolveItem', function ($type, $item, $url, $theme) {
    if ($type === 'cms-page' && str_starts_with($item->reference, 'project/')) {
        return \Cms\Classes\Page::resolveMenuItem($item, $url, $theme, true);
    }
}, 10000);

@mjauvin
Copy link
Member Author

mjauvin commented Oct 26, 2024

Without this PR, I need to duplicate the resolveMenuItem method in my component.

@LukeTowers LukeTowers changed the title Make resolveMenuItem more easily reusable. Add routePersistence parameter to Page::resolveMenuItem() Oct 30, 2024
@LukeTowers LukeTowers merged commit 9d19d71 into develop Oct 30, 2024
14 checks passed
@LukeTowers LukeTowers deleted the cms-page-resolve-menu-item branch October 30, 2024 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance PRs that fix bugs, are translation changes or make only minor changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants