modules/acm_promotion/src/Plugin/Block/AcmPromotionBlock.php
protected function getPromotionNodes($view_mode) {
    $nodes = [];

    // Default to loading all enabled (published) nodes.
    $query = \Drupal::entityQuery('node')
      ->condition('type', 'acm_promotion')
      ->condition('status', NodeInterface::PUBLISHED);

    if ($view_mode === 'sku_limit') {
      $viewing_node = \Drupal::routeMatch()->getParameter('node');

      if (
        !is_null($viewing_node)
        && $viewing_node->hasField('field_skus')
        && !empty($viewing_node->get('field_skus')->getValue())
      ) {

        $sku_field = $viewing_node->get('field_skus')->getValue();
        $skus = [];
        foreach ($sku_field as $sku) {
          $skus[] = $sku['value'];
        }

        $query->condition('field_skus', $skus, 'IN');
      }
    }

    // TODO Consider adding a module alter hook here for $query.
    $nids = $query->execute();
    $nodes = Node::loadMultiple($nids);

    // TODO Consider adding a module alter hook here for $nodes.
    return $nodes;
  }
protected function getPromotionNodes($view_mode) {
    $nodes = [];

    // Default to loading all enabled (published) nodes.
    $query = \Drupal::entityQuery('node')
      ->condition('type', 'acm_promotion')
      ->condition('status', NodeInterface::PUBLISHED);

    if ($view_mode === 'sku_limit') {
      $viewing_node = \Drupal::routeMatch()->getParameter('node');

      if (
        !is_null($viewing_node)
        && $viewing_node->hasField('field_skus')
        && !empty($viewing_node->get('field_skus')->getValue())
      ) {

        $sku_field = $viewing_node->get('field_skus')->getValue();
        $skus = [];
        foreach ($sku_field as $sku) {
          $skus[] = $sku['value'];
        }

        $query->condition('field_skus', $skus, 'IN');
      }
    }

    // TODO Consider adding a module alter hook here for $query.
    $nids = $query->execute();
    $nodes = Node::loadMultiple($nids);

    // TODO Consider adding a module alter hook here for $nodes.
    return $nodes;
  }
protected function getPromotionNodes ( $ view_mode ) { $ nodes = [ ] ; // Default to loading all enabled (published) nodes. $ query = \ Drupal :: entityQuery ( 'node' ) -> condition ( 'type' , 'acm_promotion' ) -> condition ( 'status' , NodeInterface :: PUBLISHED ) ; if ( $ view_mode === 'sku_limit' ) { $ viewing_node = \ Drupal :: routeMatch ( ) -> getParameter ( 'node' ) ; if ( ! is_null ( $ viewing_node ) && $ viewing_node -> hasField ( 'field_skus' ) && ! empty ( $ viewing_node -> get ( 'field_skus' ) -> getValue ( ) ) ) { $ sku_field = $ viewing_node -> get ( 'field_skus' ) -> getValue ( ) ; $ skus = [ ] ; foreach ( $ sku_field as $ sku ) { $ skus [ ] = $ sku [ 'value' ] ; } $ query -> condition ( 'field_skus' , $ skus , 'IN' ) ; } } // TODO Consider adding a module alter hook here for $query. $ nids = $ query -> execute ( ) ; $ nodes = Node :: loadMultiple ( $ nids ) ; // TODO Consider adding a module alter hook here for $nodes. return $ nodes ; }
Gets the relavent promotion nodes to be displayed.

This method loads the active promotion nodes.

@return Drupal\node\Entity\Node[]
The promotion node for the user's session.
Gets the relavent promotion nodes to be displayed .