Avoid sending email (content moderation) when node updated programatically

I have a csv import function which also will have to update the "moderation_state" field.
Once csv import is ran, email will be triggered by content_moderation module.
Is there a way to disable this when updating nodes programatically?

8 – What is the status code for “Draft” in content moderation?

I implemented Content moderation workflow for my headless D8 project and created workflows and enabled for all content types. Salesforce is the fronend application which uses graphql to get the content from headless drupal. Currently I’m able to show published content on salesforce application. But when I try to query draft content from salesforce graphql, getting error message “moderation_state” not found in Drupal logs.
Can someone please help! Below is the example query.

”’graphQlQuery Testquery :{“query”:”{nodeQuery(filter: { conditions: ({field:”title”,value:”Test-Test”,operator:EQUAL},{field:”type”,value:”XXXX_content_type”,operator:EQUAL},
{field:”status”,value:”0″,operator:EQUAL},
{field:”moderation_state”,value:”draft,”,operator:EQUAL},)})
{count entities{entityTranslation(language:EN)
{… on NodeXXXXContentType{fieldXXXX body{processed summaryProcessed }title uuid }}}}}”}”’

8 – Show latest changes in node “View” tab while using Content Moderation

I had been trying a lot to display latest revision into view tab irrespective of its state, so if a node is in “Draft” state I still want it to be displayed under “View” Tab rather than “Latest version”. I had tried using hook_ENTITY_TYPE_view, hook_ENTITY_TYPE_view_alter and even tried in template_preprocess_node hook but no luck. I was able to load latest revision but not able to set it using below code in preprocess,

function mytheme_preprocess_node(&$variables) {
  if ($variables('node')->getType() == 'news' && $variables('elements')('#view_mode') = 'full') {
    $node = $variables('elements')('#node');
    $vid = Drupal::entityTypeManager()->getStorage('node')->getLatestRevisionId($node->id());
    $node = Drupal::entityTypeManager()->getStorage('node')->loadRevision($vid);
    $variables('elements')('#node')  = $node;
  }
}

Also tried with below code from a custom module,

function mymodule_node_view(array &$build, DrupalCoreEntityEntityInterface $entity, DrupalCoreEntityDisplayEntityViewDisplayInterface $display, $view_mode) {
  
  $node = Node::load($build('#node')->id());
  


  if ($entity->bundle() == 'article' && $view_mode = 'full') {
    $revision_ids = Drupal::entityTypeManager()->getStorage('node')->revisionIds($node);
    $latest_rev_id  =  end($revision_ids);
    $node_new = node_revision_load($latest_rev_id);
                   
    $view_builder = Drupal::entityTypeManager()->getViewBuilder($entity->getEntityTypeId());
    $storage = Drupal::entityTypeManager()->getStorage($entity->getEntityTypeId());
    //$node = $storage->load($build('#node')->id());
    $build_new = $view_builder->view($node_new, $view_mode);
    //$output = render($build);
     
    $build('#node') =  $build_new('#node');                 
  }

}

Please if anyone can point me in a right direction it will be very helpful.
Thanks in advance.

theming – Drupal 8 Show latest changes in node “View” tab while using Content Moderation

I had been trying a lot to display latest revision into view tab irrespective of its state, so if a node is in “Draft” state I still want it to be displayed under “View” Tab rather than “Latest version”. I had tried using hook_ENTITY_TYPE_view, hook_ENTITY_TYPE_view_alter and even tried in template_preprocess_node hook but no luck. I was able to load latest revision but not able to set it using below code in preprocess,

function mytheme_preprocess_node(&$variables) {
  if ($variables('node')->getType() == 'news' && $variables('elements')('#view_mode') = 'full') {
    $node = $variables('elements')('#node');
    $vid = Drupal::entityTypeManager()->getStorage('node')->getLatestRevisionId($node->id());
    $node = Drupal::entityTypeManager()->getStorage('node')->loadRevision($vid);
    $variables('elements')('#node')  = $node;
  }
}

Also tried with below code from a custom module,

function mymodule_node_view(array &$build, DrupalCoreEntityEntityInterface $entity, DrupalCoreEntityDisplayEntityViewDisplayInterface $display, $view_mode) {
  
  $node = Node::load($build('#node')->id());
  


  if ($entity->bundle() == 'article' && $view_mode = 'full') {
    $revision_ids = Drupal::entityTypeManager()->getStorage('node')->revisionIds($node);
    $latest_rev_id  =  end($revision_ids);
    $node_new = node_revision_load($latest_rev_id);
                   
    $view_builder = Drupal::entityTypeManager()->getViewBuilder($entity->getEntityTypeId());
    $storage = Drupal::entityTypeManager()->getStorage($entity->getEntityTypeId());
    //$node = $storage->load($build('#node')->id());
    $build_new = $view_builder->view($node_new, $view_mode);
    //$output = render($build);
     
    $build('#node') =  $build_new('#node');                 
  }

}

Please if anyone can point me in a right direction it will be very helpful.
Thanks in advance.

8 – Condition on current moderation state

The following reaction rule will do what you asked. Import this configuration then enable the rule at /admin/config/workflow/rules

Note it is not sufficient just to check the current moderation state; if your goal is to show a message when the moderation state is changed to Published then you need to check the state before the update and compare it to the current state – you only want to send the message when the current state is Published and the previous state was NOT Published.

There IS a debug log now in D8 Rules, but it wasn’t available when you asked your question.

In the future, please include an export of your Rule – it is impossible to know exactly what you configured wrong without seeing the export.

langcode: en
status: true
dependencies:
  module:
    - content_moderation
  enforced:
    module:
      - content_moderation
id: content_moderation_state_is_changed_to_published
label: 'Show a message when content moderation state is changed to Published'
events:
  -
    event_name: 'rules_entity_update:node'
description: 'This Reaction Rule displays a system message when the moderation state of any piece of content is changed to Published'
tags: {  }
config_version: '3'
expression:
  id: rules_rule
  uuid: 563de663-2c5a-4bad-892d-017e322b67ba
  weight: 0
  conditions:
    id: rules_and
    uuid: c65b7edb-5f6b-41b8-8775-8a880e66b8c0
    weight: 0
    conditions:
      -
        id: rules_condition
        uuid: 384eb508-4970-4210-b427-b9c2d09f25a4
        weight: 0
        context_values:
          operation: '=='
        context_mapping:
          data: node.moderation_state.value
          value: node_unchanged.moderation_state.value
        context_processors:
          operation:
            rules_tokens: {  }
        provides_mapping: {  }
        condition_id: rules_data_comparison
        negate: true
      -
        id: rules_condition
        uuid: 5528f7d4-302c-4a72-b583-943dacb4c117
        weight: 0
        context_values:
          operation: '=='
          value: published
        context_mapping:
          data: node.moderation_state.value
        context_processors:
          operation:
            rules_tokens: {  }
          value:
            rules_tokens: {  }
        provides_mapping: {  }
        condition_id: rules_data_comparison
        negate: false
  actions:
    id: rules_action_set
    uuid: 6cd47db2-335b-4647-8083-b0c0d90b63bf
    weight: 0
    actions:
      -
        id: rules_action
        uuid: 5520606c-4d0f-4af1-9c55-c95f910477ac
        weight: 0
        context_values:
          message: 'Content moderation state was changed to Published'
          type: status
          repeat: false
        context_mapping: {  }
        context_processors:
          message:
            rules_tokens: {  }
          type:
            rules_tokens: {  }
          repeat:
            rules_tokens: {  }
        provides_mapping: {  }
        action_id: rules_system_message

8 – Programmatically add a translation with proper content moderation state

I am trying to add a node translation programmatically when a node is created (using hook_ENTITY_TYPE_insert). My code works fine except that the translation doesn’t really have a content moderation state. My code is the following.

function mymodule_add_translation($node) {
  // get the current language, and determine the translation language
  $lang = Drupal::languageManager()->getCurrentLanguage()->getId();
  $langcode = ($lang == 'en') ? 'fr' : $lang;
  $node->setRevisionTranslationAffected(TRUE);
  $node->addTranslation($langcode, ('title' => $node->getTitle()))->save();
}

This is what the content_moderation_state_field_revision table looks like for two nodes; one was manually translated it and the other one was translated using the above code.

content_moderation_state_field_revision table

I am clearly doing something incorrect. Any suggestion would be really appreciated.

hooks – D8: Add a translation programmatically with proper content moderation state

I am trying to add a node translation programmatically when a node is created (using hook_ENTITY_TYPE_insert). My code works fine except that the translation doesn’t really have a content moderation state. My code is as follows:

  function mymodule_add_translation($node) {
    // get the current language, and determine the translation language
    $lang = Drupal::languageManager()->getCurrentLanguage()->getId();
    $langcode = ($lang == 'en') ? 'fr' : $lang;
    $node->setRevisionTranslationAffected(TRUE);
    $node->addTranslation($langcode, ('title' => $node->getTitle()))->save();
  }

Here is what the content_moderation_state_field_revision table looks like for two nodes nid:13 I created the node and translated manually and nid:14 I automatically translated using the above code.

content_moderation_state_field_revision table

I am clearly doing something incorrect, any suggestions would be really appreciated!

users – “Update to a version prior to 9.0.0 first” for Content Moderation?

i get this problem

(error) The installed version of the /Content Moderation/ module is
too old to update. Update to a version prior to 9.0.0 first (missing
updates: content_moderation_post_update_update_cms_default_revisions,
content_moderation_post_update_set_default_moderation_state,
content_moderation_post_update_set_views_filter_latest_translation_affected_revision,
content_moderation_post_update_entity_display_dependencies,
content_moderation_post_update_views_field_plugin_id).

Please help me

add blacklist moderation list inside pre_comment_approved filter plugin

i am using Comment Whitelist plugin to create a whitelist of email domains for autoapporing comments. It seems that the plugin overrides wordpress : Settings->Discussion options->moderation blacklist. My settings are here .

The plugin works as expected,autoapproving comments from a whitelist of domains. But i would like to include also to it the protection from spam that WordPress offers with wp_check_comment_disallowed_list()

The main idea inside the plugin is

function comment_whitelist__pre_comment_approved( $approved ) {
    global $wpdb, $current_user;
    
    // Si esta aprobado ...
    if ( $approved == '1' ) {
        
        // Pues sigue aprobado!! ;-))
        return $approved;
    }else{
        
        $mod_keys = trim( get_option('whitelist_keys') );
        
        // Si no tengo lista blanca ...
        if ( empty($mod_keys) ) {
            // Devuelvo lo que tenia!!
            return $approved;
        }else{
            
            // Continuo probando...
            $words = explode("n", $mod_keys );
            // Si no tenemos elementos ...
            if ( !sizeof($words) ) {
                // Devolvemos lo que nos habia llegado de origen
                return $approved;
            }else{
                
                // Revisamos cada entrada de la lista blanca
                foreach ( (array) $words as $word ) {
                    $word = trim($word);
                    
                    // Skip empty lines
                    if ( empty($word) ) { continue; }
                    
                    // Do some escaping magic so that '#' chars in the
                    // spam words don't break things:
                    $word = preg_quote($word, '#');
                    
                    $pattern = "#$word#i";
                    if ( preg_match($pattern, $_REQUEST('email')) ) {
                        // Esta incluido en la lista blanca, nos da igual, le aprobamos.
                        return '1';
                    }
                }
                
                // NO Esta incluido en la lista blanca, le moderamos si no lo estaba, si es SPAM le dejamos.
                return ( $approved == '1' ) ? '0' : $approved;
                
            }
        }
    }
    
    die('fin');
    return $approved;
}
add_filter('pre_comment_approved', 'comment_whitelist__pre_comment_approved');

How could i also include the wp_check_comment_disallowed_list() hook so that i can still keep comments in moderation if spam words are included in the comment?

I have tried to set to the plugins filter priority 11 , but this didn’t work.

theming – How to show content of a node render using view in content moderation in draft mode Drupal 8

I am using content moderation module and it working for normal fields of the content type but if I render the content with view then its not visible in the latest revision if the node saved as draft So I have a node with having fields.

title
body
primary section title
primary section desc
Primary section image
Secondary fields

in the above fields i am using below fields in view as slideshow to render in the page( more clear – all the above used in the node but to make the slider functionality I have render these fields content with view). Now I see when I made the change of below fields in my node these fields value does not show in latest revision in the node when I save them draft its working fine in published.

primary section title
primary section desc
Primary section image