Get Hyrdrated List of Modules / Sections
Created 7 years ago by mattcdavis1

What is the best way to get a hydrated list of modules / sections? Looking through the core, everything seems to based on the idea that you'll only ever want this list for the currently active module. For example, here is the HrefGuesser code:

$module = $this->modules->active();

$href = $this->url->to('admin/' . $module->getSlug());

if ($index !== 0 && $module->getSlug() !== $section['slug']) {
    $href .= '/' . $section['slug'];
}

You can see it references the current module. For my purposes, i am trying to separate content and settings. I've created a "Manage" module that lists all the modules that i want assigned to this area. However, for some modules i want to have only certain sections of a module managed in my "Manage" module while others would show in the main nav. In order to do this, i need to generate a url for the first section of a module that is included in a given area (either main nav, top nav or manage module).

So, for example, when i display the "Dashboard" link from my "Manage" module, i want to generate a link to the "widgets" section. From what i can see there is no easy way to do this properly. Here is a screenshot of my module to provide a bit more context:

https://goo.gl/1XBhc6

ryanthompson  —  7 years ago

I don't have a utility to build sections but for the ones in the current module. I would certainly entertain it though. If you haven't already, create a PR!

PS forum is fixed 😊

mattcdavis1  —  7 years ago

@ryanthompson - what do you think about adding an $activeModule property to Anomaly\Streams\Platform\Ui\ControlPanel\ControlPanel, removing the $sections property and just always retrieving sections from modules? This seems simpler and more intuitive (since a module is the parent of a section). The only thing i'm not sure of if we went this approach is when/where to hydrate the sections (from arrays to Section objects) and deal with section authorization.

One option would be to add a getAuthorizedSections method and then have that return the Section objects which would be aware of their parent module and then the parent module could just be passed in to the HrefGuesser. Another option would be to return Section objects from getSections but if we did this, then i'm not sure how you would get the non-model (array) version of sections. Maybe a parameter? Or maybe a getRawSections to return the initial defined array while getSections would always return a collection of authorized Section objects.

Any thoughts on this general direction?