function _environment_indicator_switcher_links in Environment Indicator 4.x
Same name and namespace in other branches
- 8.3 environment_indicator.module \_environment_indicator_switcher_links()
Helper function that generates the environment switcher links.
Return value
array A renderable array with the links.
2 calls to _environment_indicator_switcher_links()
- environment_indicator_page_top in ./
environment_indicator.module - Implements hook_page_top().
- _environment_indicator_switcher_toolbar_links in ./
environment_indicator.module - Helper function to get the links for the toolbar.
File
- ./
environment_indicator.module, line 288 - Module implementation file.
Code
function _environment_indicator_switcher_links() {
if (!($environment_entities = EnvironmentIndicator::loadMultiple())) {
return [];
}
$current = Url::fromRoute('<current>');
$current_path = $current
->toString();
$environment_entities = array_filter($environment_entities, function (EnvironmentIndicator $entity) {
return $entity
->status();
});
return array_map(function (EnvironmentIndicator $entity) use ($current_path) {
return [
'attributes' => [
'style' => 'color: ' . $entity
->getFgColor() . '; background-color: ' . $entity
->getBgColor() . ';',
'title' => t('Opens the current page in the selected environment.'),
],
'title' => t('Open in: @label', [
'@label' => $entity
->label(),
]),
'url' => Url::fromUri($entity
->getUrl() . $current_path),
'type' => 'link',
];
}, array_filter($environment_entities, function (EnvironmentIndicator $entity) {
return !empty($entity
->getUrl());
}));
}