Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add layout builder support for the Services blocks #116

Open
andybroomfield opened this issue Jun 1, 2021 · 2 comments · May be fixed by #236
Open

Add layout builder support for the Services blocks #116

andybroomfield opened this issue Jun 1, 2021 · 2 comments · May be fixed by #236
Assignees

Comments

@andybroomfield
Copy link
Contributor

When using layout builder with service content types, there's a case for adding the blocks into the layout (although custom field formatters would be better).

The Service CTA blocks, Related topics and Related links blocks don't work correctly inside layout builder. They rely on the current page route to work out the node id, without this the blocks fail as $this->node is not set and an empty check is needed to avoid a WSOD when adding the block.

A node context should be provided for these blocks (in ServiceBlockBase?) This allows the blocks to work with live preview and layout builder instead of displaying 'placeholder for'

Screenshot 2021-06-01 at 10 54 54 pm

.
andybroomfield added a commit that referenced this issue Jun 4, 2021
Ref #116

Add the node context to the service blocks, this allows them to be used
with layout builder
@andybroomfield andybroomfield self-assigned this Oct 12, 2021
@andybroomfield
Copy link
Contributor Author

Going to try and revive this one post beta to work out what the blockers where.
I think we need to get an update hook for the existing blocks so they add the node context so will still display in the block screen, but that might just be a load and save operation.

andybroomfield added a commit that referenced this issue Dec 3, 2023
Ref #116

Add the node context to the service blocks, this allows them to be used
with layout builder
@andybroomfield
Copy link
Contributor Author

andybroomfield commented Dec 5, 2023

So the blocker will be that sites block config for service blocks will need to be updated and resaved to add the context.
See https://drupal.stackexchange.com/a/297721 for how.

$entity_type_manager = \Drupal::entityTypeManager();
$blocks = $entity_type_manager->getStorage('block')->loadByProperties([
  'plugin' => 'SERVICE_BLOCK_PLUGIN_ID',
]);

foreach ($blocks as $block) {
  if ($block->getRegion() == 'my_region') {
    $settings = $block->get('settings');
    // modify settings
    $block->set('settings', $settings);
    $block->save();
  }
}

It needs node: '@node.node_route_context:node' adding as a context mapping eg.

settings:
  id: localgov_services_related_links_block
  label: 'Service page related links'
  label_display: '0'
  provider: localgov_services_page
  context_mapping:
    node: '@node.node_route_context:node'

andybroomfield added a commit that referenced this issue Dec 18, 2024
Ref #116

Add the node context to the service blocks, this allows them to be used
with layout builder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant