modules/acm_promotion/src/AcmPromotionsManager.php
public function getPromotionByRuleId($rule_id, $rule_type) {
    $query = $this->nodeStorage->getQuery();
    $query->condition('type', 'acm_promotion');
    $query->condition('field_acm_promotion_rule_id', $rule_id);
    $query->condition('field_acm_promotion_type', $rule_type);
    $nids = $query->execute();

    if (empty($nids)) {
      return NULL;
    }
    else {
      // Log a message for admin to check errors in data.
      if (count($nids) > 1) {
        $this->logger->critical('Multiple nodes found for rule id @rule_id', ['@rule_id' => $rule_id]);
        return NULL;
      }

      // We only load the first node.
      /* @var $node \Drupal\node\NodeInterface */
      $node = $this->nodeStorage->load(reset($nids));
      $langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
      // Get the promotion with language fallback, if it did not have a
      // translation for $langcode.
      $node = $this->entityRepository->getTranslationFromContext($node, $langcode);
      return $node;
    }
  }
public function getPromotionByRuleId($rule_id, $rule_type) {
    $query = $this->nodeStorage->getQuery();
    $query->condition('type', 'acm_promotion');
    $query->condition('field_acm_promotion_rule_id', $rule_id);
    $query->condition('field_acm_promotion_type', $rule_type);
    $nids = $query->execute();

    if (empty($nids)) {
      return NULL;
    }
    else {
      // Log a message for admin to check errors in data.
      if (count($nids) > 1) {
        $this->logger->critical('Multiple nodes found for rule id @rule_id', ['@rule_id' => $rule_id]);
        return NULL;
      }

      // We only load the first node.
      /* @var $node \Drupal\node\NodeInterface */
      $node = $this->nodeStorage->load(reset($nids));
      $langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
      // Get the promotion with language fallback, if it did not have a
      // translation for $langcode.
      $node = $this->entityRepository->getTranslationFromContext($node, $langcode);
      return $node;
    }
  }
public function getPromotionByRuleId ( $ rule_id , $ rule_type ) { $ query = $ this -> nodeStorage -> getQuery ( ) ; $ query -> condition ( 'type' , 'acm_promotion' ) ; $ query -> condition ( 'field_acm_promotion_rule_id' , $ rule_id ) ; $ query -> condition ( 'field_acm_promotion_type' , $ rule_type ) ; $ nids = $ query -> execute ( ) ; if ( empty ( $ nids ) ) { return NULL ; } else { // Log a message for admin to check errors in data. if ( count ( $ nids ) > 1 ) { $ this -> logger -> critical ( 'Multiple nodes found for rule id @rule_id' , [ '@rule_id' => $ rule_id ] ) ; return NULL ; } // We only load the first node. /* @var $node \Drupal\node\NodeInterface */ $ node = $ this -> nodeStorage -> load ( reset ( $ nids ) ) ; $ langcode = $ this -> languageManager -> getCurrentLanguage ( LanguageInterface :: TYPE_CONTENT ) -> getId ( ) ; // Get the promotion with language fallback, if it did not have a // translation for $langcode. $ node = $ this -> entityRepository -> getTranslationFromContext ( $ node , $ langcode ) ; return $ node ; } }
Helper function to fetch promotion node given rule id.

@param int $rule_id
Rule id of the promotion to load.
@param string $rule_type
Rule type of the promotion to load.

@return \Drupal\node\NodeInterface|null
Return node if a promotion found associated with the rule id else Null.
Helper function to fetch promotion node given rule id .