public function getMessageTypes($action, Entity $entity) {
    // Init.
    $messagetypes = [];

    // We need the entitytype manager.
    $entity_type_manager = \Drupal::service('entity_type.manager');
    // Message type storage.
    $message_storage = $entity_type_manager->getStorage('message_template');

    // Check all enabled messages.
    foreach ($message_storage->loadByProperties(['status' => '1']) as $key => $messagetype) {
      $mt_entity_bundles = $messagetype->getThirdPartySetting('activity_logger', 'activity_bundle_entities', NULL);
      $mt_action = $messagetype->getThirdPartySetting('activity_logger', 'activity_action', NULL);
      $mt_context = $messagetype->getThirdPartySetting('activity_logger', 'activity_context', NULL);
      $mt_destinations = $messagetype->getThirdPartySetting('activity_logger', 'activity_destinations', NULL);
      $mt_entity_condition = $messagetype->getThirdPartySetting('activity_logger', 'activity_entity_condition', NULL);

      if (!empty($mt_entity_condition)) {
        $entity_condition_factory = \Drupal::service('plugin.manager.activity_entity_condition.processor');
        $entity_condition_plugin = $entity_condition_factory->createInstance($mt_entity_condition);
        $entity_condition = $entity_condition_plugin->isValidEntityCondition($entity);
      }
      else {
        $entity_condition = TRUE;
      }

      $activity_context_factory = \Drupal::service('plugin.manager.activity_context.processor');
      $context_plugin = $activity_context_factory->createInstance($mt_context);

      $entity_bundle_name = $entity->getEntityTypeId() . '-' . $entity->bundle();
      if (in_array($entity_bundle_name, $mt_entity_bundles)
        && $context_plugin->isValidEntity($entity)
        && $entity_condition
        && $action === $mt_action
      ) {
        $messagetypes[$key] = [
          'messagetype' => $messagetype,
          'bundle' => $entity_bundle_name,
          'destinations' => $mt_destinations,
          'context' => $mt_context,
        ];
      }
    }
    // Return the message types that belong to the requested action.
    return $messagetypes;
  }
public function getMessageTypes($action, Entity $entity) {
    // Init.
    $messagetypes = [];

    // We need the entitytype manager.
    $entity_type_manager = \Drupal::service('entity_type.manager');
    // Message type storage.
    $message_storage = $entity_type_manager->getStorage('message_template');

    // Check all enabled messages.
    foreach ($message_storage->loadByProperties(['status' => '1']) as $key => $messagetype) {
      $mt_entity_bundles = $messagetype->getThirdPartySetting('activity_logger', 'activity_bundle_entities', NULL);
      $mt_action = $messagetype->getThirdPartySetting('activity_logger', 'activity_action', NULL);
      $mt_context = $messagetype->getThirdPartySetting('activity_logger', 'activity_context', NULL);
      $mt_destinations = $messagetype->getThirdPartySetting('activity_logger', 'activity_destinations', NULL);
      $mt_entity_condition = $messagetype->getThirdPartySetting('activity_logger', 'activity_entity_condition', NULL);

      if (!empty($mt_entity_condition)) {
        $entity_condition_factory = \Drupal::service('plugin.manager.activity_entity_condition.processor');
        $entity_condition_plugin = $entity_condition_factory->createInstance($mt_entity_condition);
        $entity_condition = $entity_condition_plugin->isValidEntityCondition($entity);
      }
      else {
        $entity_condition = TRUE;
      }

      $activity_context_factory = \Drupal::service('plugin.manager.activity_context.processor');
      $context_plugin = $activity_context_factory->createInstance($mt_context);

      $entity_bundle_name = $entity->getEntityTypeId() . '-' . $entity->bundle();
      if (in_array($entity_bundle_name, $mt_entity_bundles)
        && $context_plugin->isValidEntity($entity)
        && $entity_condition
        && $action === $mt_action
      ) {
        $messagetypes[$key] = [
          'messagetype' => $messagetype,
          'bundle' => $entity_bundle_name,
          'destinations' => $mt_destinations,
          'context' => $mt_context,
        ];
      }
    }
    // Return the message types that belong to the requested action.
    return $messagetypes;
  }
public function getMessageTypes ( $ action , Entity $ entity ) { // Init. $ messagetypes = [ ] ; // We need the entitytype manager. $ entity_type_manager = \ Drupal :: service ( 'entity_type.manager' ) ; // Message type storage. $ message_storage = $ entity_type_manager -> getStorage ( 'message_template' ) ; // Check all enabled messages. foreach ( $ message_storage -> loadByProperties ( [ 'status' => '1' ] ) as $ key => $ messagetype ) { $ mt_entity_bundles = $ messagetype -> getThirdPartySetting ( 'activity_logger' , 'activity_bundle_entities' , NULL ) ; $ mt_action = $ messagetype -> getThirdPartySetting ( 'activity_logger' , 'activity_action' , NULL ) ; $ mt_context = $ messagetype -> getThirdPartySetting ( 'activity_logger' , 'activity_context' , NULL ) ; $ mt_destinations = $ messagetype -> getThirdPartySetting ( 'activity_logger' , 'activity_destinations' , NULL ) ; $ mt_entity_condition = $ messagetype -> getThirdPartySetting ( 'activity_logger' , 'activity_entity_condition' , NULL ) ; if ( ! empty ( $ mt_entity_condition ) ) { $ entity_condition_factory = \ Drupal :: service ( 'plugin.manager.activity_entity_condition.processor' ) ; $ entity_condition_plugin = $ entity_condition_factory -> createInstance ( $ mt_entity_condition ) ; $ entity_condition = $ entity_condition_plugin -> isValidEntityCondition ( $ entity ) ; } else { $ entity_condition = TRUE ; } $ activity_context_factory = \ Drupal :: service ( 'plugin.manager.activity_context.processor' ) ; $ context_plugin = $ activity_context_factory -> createInstance ( $ mt_context ) ; $ entity_bundle_name = $ entity -> getEntityTypeId ( ) . '-' . $ entity -> bundle ( ) ; if ( in_array ( $ entity_bundle_name , $ mt_entity_bundles ) && $ context_plugin -> isValidEntity ( $ entity ) && $ entity_condition && $ action === $ mt_action ) { $ messagetypes [ $ key ] = [ 'messagetype' => $ messagetype , 'bundle' => $ entity_bundle_name , 'destinations' => $ mt_destinations , 'context' => $ mt_context , ] ; } } // Return the message types that belong to the requested action. return $ messagetypes ; }
Get message templates for action and entity.

@param string $action
Action string, e.g. 'create'.
@param \Drupal\Core\Entity\Entity $entity
Entity object.

@return array
Array of message types.
Get message templates for action and entity .