When attempting to add the 'Site Branding' block to a panels variant, I get the following error:

Symfony\Component\Routing\Exception\InvalidParameterException: Parameter "theme" for route "system.theme_settings_theme" must match "[^/]++" ("" given) to generate a corresponding URL. in Drupal\Core\Routing\UrlGenerator->doGenerate() (line 199 of /core/lib/Drupal/Core/Routing/UrlGenerator.php).

Comments

jastraat created an issue. See original summary.

Anonymous’s picture

I get the same issue with 'Site Branding' block and module Context

redsky’s picture

I have a similar issue with when adding a "Site Branding" block, this message was in the log:

Symfony\Component\Routing\Exception\InvalidParameterException: Parameter "theme" for route "system.theme_settings_theme" must match "[^/]++" ("" given) to generate a corresponding URL. in Drupal\Core\Routing\UrlGenerator->doGenerate() (line 194 of core/lib/Drupal/Core/Routing/UrlGenerator.php).

szeidler’s picture

I also ran into the issue. For me it seems, that there is the problem, that the system is not aware of the theme, that should be used while placing it through panels. And the "Site Branding" block is tightly connected to the theme settings, because it defines the features and settings (e.g. logo) for the site branding block.

Context in in our case Panels don't know anything about the theme. And that's the big difference to the Block interface, where we always define the Block layout per theme.

I investigated the problem a little bit further and the source problem seems to be in /core/modules/system/src/Plugin/Block/SystemBrandingBlock.php line 76, where it tries to retrieve

$form_state->get('block_theme');

That form value is only available in the block admin UI and returns therefore NULL in all other contexts, like in Context or Panels. I tried to inject the "block_theme" setting into the "Add block" form from page_manager, but without any success.

Workaround

If you stuck into that issue, you can use the following workaround:

  1. Open /core/modules/system/src/Plugin/Block/SystemBrandingBlock.php
  2. Define your theme manually $theme = 'themename';
  3. Place the "Site branding" block into the panel variant
  4. Change the line back to the initial state

Another approach would be to check the returned value

$form_state->get('block_theme')

for NULL and set the default theme. So like:

if (empty($theme)) {
  $theme = \Drupal::config('system.theme')->get('default');
}

But that hacking core…

edmargomes’s picture

szeidler create the patch with your solution, it's work for me. Thanks.

if (empty($theme)) {
  $theme = \Drupal::config('system.theme')->get('default');
}

szeidler’s picture

Here is the requested core patch for those, who really need the workaround and can integrate the patch into their core update workflow.
In general the patch only needs to be applied in the moment you want to insert the branding block via page_manager/panels user interface.

If someone is interested to start a core issue on it, just reuse my investigation results. But I'm pretty sure, that it would require a more flexible solution (not just using the default theme as a fallback, but making the theme context selectable).

japerry’s picture

samuel.mortenson’s picture

Pretty sure we just need to add this code block from \Drupal\block\BlockForm::form to our Panels IPE and Panels forms. I'll work on a patch.

    // Store theme settings in $form_state for use below.
    if (!$theme = $entity->getTheme()) {
      $theme = $this->config('system.theme')->get('default');
    }
    $form_state->set('block_theme', $theme);
samuel.mortenson’s picture

Status: Active » Needs review
StatusFileSize
new1.58 KB

Here's a patch which provides a default value for block_theme, but I would agree that this is also a core issue and the branding block should prevent this error. I'm guessing the Context module will have to implement a similar fix.

One thing to consider is that modules like Page Manager can use Panels to display variants in different (non-default) themes, so we'll need to decide if this is urgent enough that we'll have to address that use case. We could do that in a follow-up issue as well.

japerry’s picture

hypertext200’s picture

Status: Needs review » Reviewed & tested by the community

This appeared to fix the issue.

japerry’s picture

Status: Reviewed & tested by the community » Fixed

Committed #9

Status: Fixed » Closed (fixed)

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