statamic / ideas

💡Discussions on ideas and feature requests for Statamic
https://statamic.dev
31 stars 1 forks source link

Remove a collection from the collection listing #259

Open aerni opened 4 years ago

aerni commented 4 years ago

I'm working on an addon that has a Collection of Products. I would like to move this Products Collection to its own dedicated Nav and remove it from the regular Collections Nav and Collections Listing.

I was able to remove it from the Collections Nav already. But couldn't find a way to remove it from the Collections Listing as well.

Nav::extend(function ($nav) {
  $nav->content('Collections')
    ->children(function () {
      return Collection::all()->sortBy->title()->filter(function ($item) {
        return $item->handle() !== 'products';
      })->map(function ($collection) {
        return Nav::item($collection->title())
          ->url($collection->showUrl())
          ->can('view', $collection);
      });
    });
});

Nav::extend(function ($nav) {
  $nav->create('Products')
    ->section('Snipcart')
    ->route('collections.show', 'products')
    ->icon('drawer-file');
});
riasvdv commented 4 years ago

https://github.com/riasvdv/statamic-collection-groups 😊

jesseleite commented 4 years ago

There's a pretty good chance we'll be implementing pinned nav items. See the discussion in https://github.com/statamic/ideas/issues/74

aerni commented 4 years ago

That's not quite the same, is it? Pinned is great to use for certain collections for sure. But in this case, I'd like to create a whole new Section for an addon and add a collection there. Plus other custom menu items.

jesseleite commented 4 years ago

Yeah, your mileage is going to vary, as Nav::extend() isn't smart enough to deal with listing pages (and I'm not sure it should).

If you need to remove a collection from the Collections nav and listing, you might be able to extend CollectionRepository and bind your implementation to the container (see https://statamic.dev/extending/repositories). Could get messy though, especially within an addon where your end user (or another addon) might be intentionally binding their own CollectionRepository extension.

If there's a valid enough use case, it might be better to have some kind of hide: true or listable: false setting to a collection's yaml file, to hide the collection from nav and listings automatically. Would have to think through implications across the control panel though (ie. permissions, etc).

aerni commented 4 years ago

Yeah, something like listable: false could make sense.

jackabox commented 3 years ago

Hey, did you ever find a way to solve this? Wanting to remove a collection myself from the nav/collection overview page but failing.

aerni commented 3 years ago

No, there's currently no solution for this.