Skip to content
Snippets Groups Projects
Commit 3aebfb8a authored by Rashmi's avatar Rashmi Committed by Patrick Fey
Browse files

Issue #3335044 by samit.310@gmail.com, Rashmisoni, FeyP, apaderno,...

Issue #3335044 by samit.310@gmail.com, Rashmisoni, FeyP, apaderno, Ranjit1032002: Fix the issues reported by phpcs
parent 3a605ea9
Branches
Tags
No related merge requests found
......@@ -9,7 +9,9 @@
# INTRODUCTION
The *Language Switcher Menu* module allows you to add the language switch links generated by the `language` module of Drupal Core as menu link items to one of your menus.
The *Language Switcher Menu* module allows you to add the language switch
links generated by the `language` module of Drupal Core as menu link items
to one of your menus.
For a full description of the module, visit the project page:
https://www.drupal.org/language_switcher_menu
......@@ -29,11 +31,20 @@ This module depends on the `language` module provided by Drupal Core.
# CONFIGURATION
* Review the permissions provided by the module. There is one permission to configure the module and (for now, see below) a permission to view language switcher menu links added by the module.
* Go to the configuration page of the module at Configuration > Regional and language > Language Switcher Menu.
* Review the permissions provided by the module. There is one permission to
configure the module and (for now, see below) a permission to view language
switcher menu links added by the module.
* Go to the configuration page of the module at Configuration > Regional
and language > Language Switcher Menu.
* Select the language type you want to use to generate the links.
* Select a parent menu item. The language switcher links will be added below that menu item. As usual, you may select the name of a menu to add the links to the root level. You may select the *Disabled* option, if you want to (temporarily) disable the functionality of the module without uninstalling it.
* Select the weight of the first language switcher link to be added to the menu. For any additional language switcher links, the weight will be increased by 1.
* Select a parent menu item. The language switcher links will be added
below that menu item. As usual, you may select the name of a menu
to add the links to the root level. You may select the *Disabled*
option, if you want to (temporarily) disable the functionality of
the module without uninstalling it.
* Select the weight of the first language switcher link to be added
to the menu. For any additional language switcher links, the weight
will be increased by 1.
* Click *Save configuration*.
### Important note
......@@ -45,11 +56,22 @@ Due to [an issue in Drupal Core](https://www.drupal.org/project/drupal/issues/30
## How can I alter the generated links?
You may implement `hook_language_switch_links_alter()` provided by Drupal Core in a custom module or use any other contributed module that implements that hook to alter the language switcher links. Alternatively, you may override `menu.html.twig` in your custom theme (see below) or implement a preprocess function.
You may implement `hook_language_switch_links_alter()` provided by Drupal Core
in a custom module or use any other contributed module that implements that
hook to alter the language switcher links. Alternatively, you may
override `menu.html.twig` in your custom theme (see below) or implement
a preprocess function.
## How do I target the links in Twig templates?
You can check, if the id of the menu link starts with `language_switcher_menu.language_switcher_link:`. `item.original_link.class` or `item.original_link.provider` are also a good candidates to check, whether the links have been generated by Language Switcher Menu module. If needed, you can get the language object using `item.original_link.getOptions()['language']`. Below is an example of a custom `menu.html.twig` template that uses custom markup for language switcher links:
You can check, if the id of the menu link starts with
`language_switcher_menu.language_switcher_link:`. `item.original_link.class`
or `item.original_link.provider` are also a good candidates to check,
whether the links have been generated by Language Switcher Menu module.
If needed, you can get the language object using
`item.original_link.getOptions()['language']`. Below is an example of
a custom `menu.html.twig` template that uses custom markup for
language switcher links:
```twig
{#
......@@ -95,9 +117,13 @@ You can check, if the id of the menu link starts with `language_switcher_menu.la
item.in_active_trail ? 'in-active-trail',
] %}
<li{{ item.attributes.addClass(classes) }}>
{% if id starts with 'language_switcher_menu.language_switcher_link:' %}
{% if id starts with 'language_switcher_menu.language_switcher_link:'
%}
{% set language = item.original_link.getOptions()['language'] %}
<a href="{{ item.url }}" lang="{{ language.getId() }}" class="language-switcher-link"><abbr title="{{ item.title }}">{{ language.getId() }}</abbr></a>
<a href="{{ item.url }}" lang="{{ language.getId() }}"
class="language-switcher-link">
<abbr title="{{ item.title }}">{{ language.getId() }}</abbr>
</a>
{% else %}
{{ link(item.title, item.url, { 'class':['menu__link']}) }}
{% endif %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment