localgovdrupal / localgov_subsites_extras

GNU General Public License v2.0
0 stars 0 forks source link

Allow other modules to set the subsite homepage. #15

Closed Polynya closed 1 month ago

Polynya commented 2 months ago

The module currently expects all items in the subsites menu to be nodes but there may be other links such as Views pages. Also, the menu may be wanted on pages that are not in the menu.

This PR adds an alter hook so other modules can set the home page. An event may be better way, https://github.com/localgovdrupal/localgov_subsites_extras/pull/14

Example usage

/**
 * Implements hook_localgov_subsites_extras_homepage_alter().
 */
function example_localgov_subsites_extras_homepage_alter(?NodeInterface &$homepage) {
  if (!$homepage) {
    $url = \Drupal::request()->getRequestUri();
    if (str_starts_with($url, '/mysubsite')) {
      $homepage = \Drupal::entityTypeManager()->getStorage('node')->load(999);
    }
  }
}
Polynya commented 2 months ago

I think this can be closed as it's very similar to https://github.com/localgovdrupal/localgov_subsites_extras/issues/2

markconroy commented 1 month ago

Let's close this in favour of #2, which has a PR attached to it a well.