I want to programmatically decide whether to render a link or not. This should apply to all links e.g anchor tags (no wysywigs) Not only menu links.
I tried using hook_link_alter
.
/**
* Implements hook_link_alter().
*/
function mymodule_link_alter(&$variables) {
$my_logic = TRUE;
if ($my_logic) {
// Any way to not render the link?
// I tried:
// $variables = []; and unsetting keys with no luck
// $variables['options']['#access'] = FALSE; With no luck.
// I guess i could set a flag here and somewhere else process it, but where?
}
}
I can alter the structure, but I don't see any way to unset the element. What I want is basically to not render the element if $my_logic
.
I also tried to use a service with the path_processor_outbound tag, but I have the same problem. I can "access" all generated links but can just alter / modify the output of processOutbound()
but not to not process.
I think I can´t use a custom access check because i don´t want the url´s to be inaccessible if directly requested and I rather don´t want to do the check in a template