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 // 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 just alter processOutbound()
but not to not process.
Does anybody have any idea?