Skip to content

[4.x] Add helper arg for addons to easily remove child item in core nav - #8883

Merged
jasonvarga merged 2 commits into
4.xfrom
features/add-arg-to-easily-remove-child-cp-nav-item
Nov 1, 2023
Merged

jasonvarga merged 2 commits into
4.xfrom
features/add-arg-to-easily-remove-child-cp-nav-item

Conversation

@jesseleite

@jesseleite jesseleite commented Oct 25, 2023

Copy link
Copy Markdown
Contributor

This PR adds ability for an addon to remove specific core nav item children more easily. For example, in our Shopify rad pack addon, @ryanmitchell is wanting to remove the Products collection item from Collections, because that item is being listed as a child of the Shopify nav item instead.

Before

Nav::extend(function ($nav) {
    $collectionsNav = $nav->content('Collections');

    $children = $collectionsNav
        ->resolveChildren()
        ->children()
        ->reject(function ($item) {
            if (in_array($item->display(), ['Products', 'Variants'])) {
                return true;
            }
        });

    $collectionsNav->children($children);
});

After

Nav::extend(function ($nav) {
    $nav->remove('Content', 'Collections', 'Products');
    $nav->remove('Content', 'Collections', 'Variants');
});

Todo

@jesseleite jesseleite changed the title Add helper arg for addons to easily remove child item in core nav [4.x] Add helper arg for addons to easily remove child item in core nav Oct 25, 2023
@jesseleite
jesseleite marked this pull request as ready for review October 31, 2023 20:45
@jesseleite
jesseleite requested a review from jasonvarga October 31, 2023 20:53
@jasonvarga

Copy link
Copy Markdown
Member

Should min version requirement be mentioned in docs

Nope

@jasonvarga
jasonvarga merged commit 366ff26 into 4.x Nov 1, 2023
@jasonvarga
jasonvarga deleted the features/add-arg-to-easily-remove-child-cp-nav-item branch November 1, 2023 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants