Flags are just config entities, so they're easy to load (and even easier than what we're doing in some cases: #2461549: use entity type hinting in routes).

So I'm not sure we need to have this code in a service. It's just as easy to load the flag entity, and then do:

$flag->getFlagTypePlugin()->flag(yadayada);

For that matter, we could add helper methods on the flag entity class.

Comments

socketwench’s picture

Status: Active » Closed (works as designed)

And then we'd need to bring in the event manager, and the module handler and the current user, and all of those other deps from the container...

I'd rather keep all that mess in FlagService where it does come together, rather than force all of that down the line. It's also a nice, central place to look for the flag and unflag methods. It's much easier to tell people \Drupal::service('flag')->flag() than Load the entity, then load the plugin, THEN flag stuff.