January 20, 2022 at 9:42 am | blabbing.

If you need to preprocess a specific paragraph type for it’s content or fields but you need to know the node/entity type that the request is coming from you can use the following.

Make sure that you check to make sure the $node is not NULL before running methods against $node.

Here we are going to preprocess a PARAGRAPH_TYPE but only if that paragraph is part of a CUSTOMER node/entity type.

<?php

function MODULE_NAME_preprocess_paragraph__PARAGRAPH_TYPE(&$variables){

  // Get the paragraph
  $paragraph = $variables['paragraph'];

  // Get the Language
  $language = \Drupal::languageManager()->getCurrentLanguage()->getId();
  
  // Get the Node from the request.
  $node = Drupal::request()->attributes->get('node');

  // Check to make sure the node is NOT null before running something like $node->bundle();
  if($node != null && $node->bundle() == 'customer' ){
    // Code
  }
}