How do you target a specific type of content? I have the content type (node), article, page, recipe.
The code below can be used to flag any type of content.
How do you target a specific type of content ?
For example I only want to flag the article and recipe content type.
&lt;?php

/**
 * @file
 * Holds hook implementation for the Admin Task Notify module.
 */

use Drupal\flag\FlaggingInterface;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\user\Entity\User;
use Drupal\comment\Entity\Comment;

/**
 * Implements hook_node_update().
 */
function admin_task_notify_node_update(Node $node) {

    $flag_id = 'moderate_node';
    $flag_service = \Drupal::service('flag');
    $flag = $flag_service-&gt;getFlagById($flag_id);
    $account = \Drupal\user\Entity\User::load(1);
    $flag_service-&gt;flag($flag, $node, $account);

}
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.