July Drupal contributions round-up

TLDR: July: lots of debugging, three comments linking a few issues together, and a sandbox module that I hope will soon be obsolete.

Layout builder

I had a Drupal project the other day involving layout builder and inline blocks. One such block had a media field that non-admins weren’t able to set until the page itself (and the block) had been saved first.

You shouldn’t need permission to create blocks in order to use layout builder. Except seemingly you do if you want layout builder and media to play nice together.

There’s an open issue about it. However, the suggested workaround fudges the answer to “can I create this thing?” depending on the circumstances:

// paraphrased:
function hook_ENTITY_TYPE_create_access() {
  if (/* inside a media library route? */) {
    return TRUE;
  }
  else {
    return /* whatever normally happens */;
  }
}

I don’t like that, it feels like a second bug trying to cancel out the first.

In this project there was no actual risk in granting the editors a few extra permissions. They are trusted and there isn’t any damage they can do with it. So the pragmatic thing to do is just to grant them and forget about it.

Group

But later we came across the same issue with the group module. You can’t use a media field properly if you don’t have permission to create entities of that field’s type.

There’s an open issue about that too, with an eerily similar workaround:

// paraphrased:
function hook_ENTITY_TYPE_create_access() {
  if (/* inside a media library route? */) {
    return TRUE;
  }
  else {
    return /* whatever normally happens */;
  }
}

This time there is no easy way out: we aren’t able to just grant permissions and forget about it. We don’t want people creating things outside of their group.

Media library

I’ve tracked the bug down to the media library module, and lo and behold there is another open issue about that too. This one identifies the root cause, so any way forward is going to be a clumsy workaround.

I’ve at least been able to tie these three issues together. Hopefully that will give other people who find these issues a bit of direction and prevent them going down rabbit holes. I’ve also created a sandbox module as a temporary measure until the main issue can be resolved properly.