Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
While it would be nice to have a UI to configure what blocks can be placed in panels (see #2764897: Make available layouts and blocks configurable, a simple starting point would be to define a hook that lets modules override what blocks are available for placement in the Panels IPE. It's a quick and dirty solution, but it would make it possible to optimise the user experience. The attached patch does just that.
Comment | File | Size | Author |
---|---|---|---|
#8 | panels-n2767087-8.patch | 2.08 KB | DamienMcKenna |
| |||
#8 | panels-n2767087-8.interdiff.txt | 593 bytes | DamienMcKenna |
Comments
Comment #2
muschpusch CreditAttribution: muschpusch at Factorial GmbH commentedWorks great but after removing some items the array key order needs to get restored. e.g. array_values($data); not sure if this should be part of the patch.
Comment #3
samuel.mortensonComment #4
samuel.mortensonRe-rolled the patch.
Comment #5
samuel.mortensonRealized this needs API documentation as well in panels_ipe.api.php
Comment #6
DamienMcKennaDocumentation.
Comment #7
DamienMcKennaComment #8
DamienMcKennaRenamed a variable but forgot to update all occurrences.
Comment #9
DamienMcKennaComment #10
japerryThis, in theory works for me. And it didn't seem to break anything. Committed.
Comment #12
hideaway CreditAttribution: hideaway commentedJust a quick note to not forget to reassign keys in
$blocks
array, if you unset any block before end of the list (blocks which are not at the end of an array). Otherwise the blocks wont be rendered in IPE. I have to put the following line before end of alter hook:$blocks = array_values($blocks);
I guess the response has some kind of problems if you unset key in indexed array and end up with something like this
In this example I unset block with index 2.
Probably the best way would be to put the fix directly after tiggering alter hooks. So we don't need to reassign keys in alter hooks. We would end up with the:
Comment #14
samuel.mortenson@hideaway Done - this was brought up in #2 but never addressed. I committed a quick follow-up based on your comment. Thanks!
Comment #17
dsnopekI just posed a follow-up to this issue to add some useful context to the hook:
#2886230: hook_panels_ipe_blocks_alter() should receive the PanelsDisplayVariant being editted