How do you target a specific type of content?
You need to configure your moderate_node flag in either the UI or in configuration management.
In the flag module, a flag entity is defined by the entity type (i.e. node) and bundles (e.g. article, page, recipe) that are allowed on it. If no bundles are specified, then all bundles are allowed.
In your example code, $flag-&gt;getBundles() method will return the bundles that are allowed (empty means all). Once set, the $flag_service-&gt;flag method will kickback exceptions if you try to flag bundles that do not apply to that flag. You'll need to adjust the code accordingly to handle those scenarios.