When a user works on a photo album (node), all tabs are rendered in the frontend theme. Normally one would only expect this to happen for the "view" tab.

When working on an album, rendering the edit, photos, rearrange and delete tabs in the backend theme would be helpful for content editors because this is what they expect to see. Specifically this is about the /node/{node}/edit, /node/{node}/photos, /node/{node}/photos-rearrange and /node/{node}/delete paths in the system.

I found 2 files where the routes for the module are defined: /photos/photos.routing.yml and /photos/photos.links.task.yml. I tried adding the following to the respective routes, as suggested in https://www.drupal.org/node/2224207:

options:
_admin_route: TRUE

This unfortunately has no effect at all (yes, I rebuilt cache). Is there any way to render these paths using the backend theme?

CommentFileSizeAuthor
#6 photos-3226339-6.patch8.96 KBnathaniel

Comments

Frontmobe created an issue. See original summary.

nathaniel’s picture

This might be helpful:

https://www.drupal.org/docs/drupal-apis/routing-system/altering-existing...

protected function alterRoutes(RouteCollection $collection) {
    if ($route = $collection->get('photos.node.management')) {
      $route->setOption('_admin_route', TRUE);
    }
}

Another option is to set _node_operation_route: TRUE if you have the "Use the administration theme when editing or creating content" option enabled on /admin/appearance.

What you did should work in photos.routing.yml. I'm running a few tests and it looks like it doesn't change for existing content, but it does for new content - if I make the change then create a new album. Not sure what that is all about.

frontmobe’s picture

Thanks for your feedback!

I applied the documentation in https://www.drupal.org/docs/drupal-apis/routing-system/altering-existing... and this gives pretty weird results:

For existing albums nothing changes, but when creating a new album only the photos.node.management route renders in the backend theme but after that is alway renders in the frontend theme. For the edit, rearrange and delete routes nothing works.

When installing the exact same custom module I created in another site (with Photos installed), the edit and delete routes are already rendering in the backend theme before installing my custom module for existing albums. After installing, the photos.node.management and photos.node.rearrange routes also render in the backend theme for existing albums. All 4 routes then also work when creating new albums.

This second site uses a custom frontend theme based on Bootstrap, just like the initial site. The backend theme used is always the standard seven theme.

I will try to test on a "vanilla" site with the Bartik frontend theme to see what happens then, I expect it will work fine there too. Any ideas on the strange behaviour with a custom theme? This really puzzles me.

nathaniel’s picture

Tracked it down to photos_node_load in photos.module around line 460 $photos_album->getCover that is calling PhotosAlbum::getCover in src/PhotosAlbum.php on line 251:

This is causing the problem:

        $cover = \Drupal::entityTypeManager()
          ->getViewBuilder('photos_image')
          ->view($photos_image, 'cover');

I'm not sure exactly why yet.

          $photos_album = new PhotosAlbum($a->album_id);
          $info['album']['cover'] = $photos_album->getCover($a->cover_id);
          $nodes[$nid]->album = $info['album'];

Might need to just attached the cover_id and render the cover later on in the process.

nathaniel’s picture

Another note. In Drupal core it looks like EntityViewBuilder calls $this->themeRegistry->getRuntime() and that causes the issue. Not sure why yet and I haven't been able to find an easy workaround yet.

nathaniel’s picture

StatusFileSize
new8.96 KB

Working on a patch to render the album cover later in the process so it can be removed from photos_node_load. If you have time to test it, please let me know if you notice any issues with the album cover.

nathaniel’s picture

Status: Active » Needs review
frontmobe’s picture

I applied the patch in #6 and can confirm the edit and delete paths now render in the backend theme by default. This happens in the site where we work with a custom built theme and in a vanilla site.

When using a custom module to render the photos and rearrange paths (as in #2) that now works perfectly too!

The album covers work fine in both sites as well, for new and existing albums.

The patch seems to do exactly what it needs to do, many thanks!

  • Nathaniel authored 313cbf6 on 6.0.x
    Issue #3226339 by Nathaniel: Render photo album tasks in backend theme
    
nathaniel’s picture

Status: Needs review » Fixed

Release note:

$node->album['cover'] was removed.

It can be rebuilt with:

$photos_album = new PhotosAlbum($node->id());
$album_cover = $photos_album->getCover($node->album['cover_id']);

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.