Removing dozens of Routes from a collection I am using a contrib module that is adding a local task to all entities, where I only want it to be added for Nodes.

So far, I have this written to handle the problem in the short term:

/**
 * Implements hook_local_tasks_alter().
 */
function mymodule_local_tasks_alter(&amp;$local_tasks) {
  foreach ($local_tasks as $key =&gt; $task) {
    if (preg_match('/access_by_entity/', $key) &amp;&amp; $key != 'access_by_entity.entities:node.access_tab') {
      unset($local_tasks[$key]);
    }
  }
}


Is there a better way to do this? Is this performant? I would rather just not have the routes exist at all, except for this one instance.
I think the way you're doing it is fine, although you could probably add a patch to the original module that adds the option of which entities to affect, so that instead of them being added and removed, it would only add them for the entity types you select.

Ah, I see you've already thought of this!