You are here

protected function ValidFacebookInstantArticles::enabledNodeBundlesSetValues in Facebook Instant Articles 8

Set the values for this filter to all node bundles that implement custom settings for the view mode

This uses an unreliable method for detecting custom settings for node bundles. The method is to check for a config Entity for the entity display settings, for the bundle/view mode. Essentially this looks for a yml file/record for the custom settings, and one is found, the bundle is considered FIA active.

1 call to ValidFacebookInstantArticles::enabledNodeBundlesSetValues()
ValidFacebookInstantArticles::query in src/Plugin/views/filter/ValidFacebookInstantArticles.php
Add this filter to the query.

File

src/Plugin/views/filter/ValidFacebookInstantArticles.php, line 84
Contains \Drupal\views\Plugin\views\filter\ImplementsViewMode.

Class

ValidFacebookInstantArticles
Simple filter that checks if a node implements the FIA custom view mode

Namespace

Drupal\fb_instant_articles\Plugin\views\filter

Code

protected function enabledNodeBundlesSetValues() {

  /**
   * @var \Drupal\Core\Entity\EntityTypeBundleInfo $entityBundleInfo
   *  entity_type.bundle.info
   */
  $entityBundleInfo = \Drupal::service('entity_type.bundle.info');

  /**
   * @var \Drupal\Core\Entity\EntityStorageInterface $entityStorage
   *   View Mode entity storage handler
   */
  $entityStorage = \Drupal::service('entity_type.manager')
    ->getStorage('entity_view_display');

  /**
   * @var string[] nodeTypes
   *   an array of node types that implement our custom view mode
   */
  $nodeTypes = [];
  foreach ($entityBundleInfo
    ->getBundleInfo('node') as $id => $bundle) {

    /**
     * @var string $viewModeId
     *   the string id for the view mode entity
     */
    $viewModeId = 'node.' . $id . '.' . static::FIA_VIEW_MODE;

    /**
     * @var \Drupal\Core\Entity\EntityInterface|null $viewMode
     *   Config entity for the view mode, if it exists
     */
    $viewMode = $entityStorage
      ->load($viewModeId);
    if ($viewMode instanceof EntityInterface) {
      $nodeTypes[$id] = $id;
    }
  }
  if (count($nodeTypes) > 0) {

    /**
     * Only set the value and operator if we have some valid node types, so
     * that we don't break the query.  Leaving them as they are will result
     * in an empty query, which is good
     */
    $this->value = $nodeTypes;
    $this->operator = "in";
  }
}