Score:0

Override a access check but also pass control back to the primary controller under certain conditions?

cn flag

I use a contrib controller that has a _custom_access function that I need to override.

I add a RouteSubscriber, and point the access check to my own controller. Now I want something like:

if ($condition) {
  return $new_access_decision;
}
return $original_controller->accessCheck()

so I can contrinue to rely on the original logic for most cases, and just override for a small subset of cases.

I don't know how to inject the original controller into my mine though, and if I try to add it as a paramter to the RouteSubscriber service, I get

has dependency on a non-existing service [original controller]

which I take to mean that controllers aren't services.

Score:1
cn flag

Inject the class_resolver as a regular service, and then call

$this->class_resolver->getInstanceFromDefinition('\Drupal\example\ExampleController');
4uk4 avatar
cn flag
Normally you don't need two instances if there is an OOP way extending the class and instantiating only the new class which can call the parent method if necessary. You need only two instances if they have different states.
cn flag
Yeah, I guess a somewhat odd edge case. I suppose I could have solved the issue by extending the primart controller, but they are fairly different from one another, and it's inherited code that I'm not too keen on completely re-writing.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.