Improve DX around setting the theme when adding a (custom) block

Created on 18 February 2013, over 12 years ago
Updated 26 August 2025, about 2 months ago

Follow up for #1871772-108: Convert custom blocks to content entities β†’

Problem/Motivation

+++ b/core/modules/block/custom_block/custom_block.pages.inc
@@ -0,0 +1,153 @@
+function custom_block_add_page() {
...
+ $request = drupal_container()->get('request');
+ if (($theme = $request->attributes->get('theme')) && in_array($theme, array_keys(list_themes()))) {
+ // We have navigated to this page from the block library and will keep track
+ // of the theme for redirecting the user to the configuration page for the
+ // newly created block in the given theme.
+ $options = array(
+ 'query' => array('theme' => $theme)
+ );
+ }
...
+function custom_block_add(CustomBlockType $block_type) {
...
+ $request = drupal_container()->get('request');
+ if (($theme = $request->attributes->get('theme')) && in_array($theme, array_keys(list_themes()))) {
+ // We have navigated to this page from the block library and will keep track
+ // of the theme for redirecting the user to the configuration page for the
+ // newly created block in the given theme.
+ $block->setTheme($theme);
+ }
+ return entity_get_form($block);
This definitely needs a follow-up issue to improve the DX/API situation.

My prediction is that there will be many more custom_block-alike modules in contrib in D8, and we really do not want them to have to repeat this request-futzing weirdness. :)

Proposed resolution

Investigate and improve DX of setting a theme for a block instance.

Remaining tasks

Investigate and improve DX of setting a theme for a block instance.

πŸ“Œ Task
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

block.module

Created by

πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

Live updates comments and jobs are added and updated live.
  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for creating this issue to improve Drupal.

    We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

Production build 0.71.5 2024