Right now, domain_block_view_switcher()
returns a block renderable array, but the content is itself just pre-rendered #markup
. One of our clients wants to be able to e.g. add domains to the switcher that are actually hosted outside of Drupal (some countries have opted into Drupal; others haven't!)
At any rate, it would be useful to be able to alter the list of domains (re-order them? disable some?) rather than rendering the markup too early. I think it's best practice to expose the contents of blocks to hooks like hook_block_view_alter()
and hook_page_alter()
if possible.
Will attach a patch for this in the first comment.
Comment | File | Size | Author |
---|---|---|---|
#5 | domain-switcher-and-nav-links-as-renderable-array-1885378-5.patch | 3.21 KB | jp.stacey |
#1 | domain-switcher-links-as-renderable-array-1885378-1.patch | 952 bytes | jp.stacey |
Comments
Comment #1
jp.stacey CreditAttribution: jp.stacey commentedPatch attached to return renderable array of element type
'#theme' => 'links'
.Comment #2
jp.stacey CreditAttribution: jp.stacey commentedExample of how this patch is helping us:
Comment #3
agentrickardRemember that this is really just for admin users. Domain Nav is provided for end users and should be more flexible.
But these are really great examples and a great report and patch!
Looking at the code, we might pass the entire $domain instead of just the id in the $links array.
Comment #4
agentrickardWe should look at Domain Alias as well, which provides its own block.
Comment #5
jp.stacey CreditAttribution: jp.stacey commentedSorry for the delay, @agentrickard: other projects got in the way. We're not using the navigation directly any more - the client has asked for enough customizations that we've gone for a rich-text box :( - so this work is of limited use to us, but I've re-rolled the patch based on what you mention above. To respond to your comments specifically:
Incidentally, seeing as you mentioned its navigational elements, I've also fixed
domain_nav
in this new patch, to return a theme array instead, and that's rolled into this patch too. It would've been really easy to do directly, but: thedomain_nav_render()
function is assumed an exposed call, so I couldn't alter that directly without possibly breaking people's themes.So to protect legacy code, I did as follows:
domain_nav_render()
as a private function_domain_nav_theme_array()
domain_nav_block_view()
call this new private functiondomain_nav_render()
, which also calls this new private function, then runstheme()
on the resulting array and returns the markup.So please find attached a patch that gets both
domain_block_view_switcher()
anddomain_nav_block_view()
returning theme arrays.Comment #6
agentrickardComment #6.0
agentrickardForgot to complete a sentence!