The hook_language_switch_links_alter() should provide information on whether a link is from the language switcher block or the node links, which it doesn't from all I can tell now. I've been searching and asking around for how to do this, but to no avail, so I'm considering this a flaw in the API. If not, it's a feature suggestion for D8.

See also #1005144: Doesn't differentiate between node and language switcher blocks.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

plach’s picture

Component: locale.module » language system

Well, language_negotiation_get_switch_links can be called in any context so it shouldn't make assumptions on who's calling it.

Perhaps we should change locale_block_view to return a renderable array, so it can be hook_block_alter'ed.

klonos’s picture

klonos’s picture

...any progress on this? Any of Francesco's suggestions thought of? I guess for the second one to happen a separate issue needs to be filed in core. Right?

plach’s picture

Title: hook_language_switch_links_alter() does not differentiate between switch block and node links » Make locale_block_view return a renderable array instead of HTML
Category: bug » task

I'd say that locale_block_view should return a renderable array anyway to allow a format-agnostic theming. Let's fix this and see if it's enough to make Language Icons work.

Freso’s picture

We already have the data used in locale_block_view() available via hook_language_switch_links_alter(). I doubt changing locale_block_view() will help with the context awareness needed to have Language icons figure out how to treat branch. I'll try and make a patch that does as you describe shortly.

ps. Sorry about any uncomprehensionality. It's very late and I'm heading to bed now, just wanted this answered first. :)

plach’s picture

@Freso:

What I mean is that if we return a renderable array instead of a flat string its content may be altered through hook_block_alter. Node links are already alterable through hook_node_view_alter, so we should be able to tell the context in both cases.

plach’s picture

Devin Carlson’s picture

Status: Active » Needs review
FileSize
1.05 KB

A patch to make locale_block_view() return a renderable array.

klonos’s picture

The patch in #8 can be (manually) applied to D7 too, but I wouldn't know what to do with it :/

@Freso: Hey Frederik, any chance you can take a look at it and see if you can work something out with #1005144: Doesn't differentiate between node and language switcher blocks??

plach’s picture

+++ b/core/modules/locale/locale.module
@@ -982,10 +982,19 @@ function locale_block_view($type) {
+        '#theme' => 'links',

Shouldn't this be using 'links__locale_block' instead?

19 days to next Drupal core point release.

Freso’s picture

I'll try and give this a look/review this week, if time allows. *crosses fingers*

batigol’s picture

cool

Devin Carlson’s picture

Reroll of #8 using links__locale_block (which is correct but might not provide any benefit anyway after reading #48 from #588148: theme_links() is not really themeable).

The patch is now smaller as the changes are now made to language.module and no longer include any attached CSS or JS.

steinmb’s picture

Getting old. If this still is valid, It prob. need a re-roll.

Devin Carlson’s picture

Version: 8.x-dev » 7.x-dev
Issue tags: -Needs backport to D7, -Needs reroll
FileSize
1.04 KB

The language switcher block was converted to a render array around the time that blocks were converted to plugins.

I believe that this is a D7-only issue now.

mitokens’s picture