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.
Comments
Comment #1
sunComment #4
tim.plunkettNot actively part of the Blocks-Layouts work.
Comment #16
smustgrave commentedThank 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!
Comment #18
smustgrave commentedBased on the snippet and where we are in D11/12 not sure there's anything actionable here. If I'm wrong please re-open.
Thanks all