You are here

public function EntityTypeInfo::getAmpEnabledTypes in Accelerated Mobile Pages (AMP) 8

Same name and namespace in other branches
  1. 8.3 src/EntityTypeInfo.php \Drupal\amp\EntityTypeInfo::getAmpEnabledTypes()
  2. 8.2 src/EntityTypeInfo.php \Drupal\amp\EntityTypeInfo::getAmpEnabledTypes()

Returns a list of AMP-enabled content types.

Return value

array An array of bundles that have AMP view modes enabled.

1 call to EntityTypeInfo::getAmpEnabledTypes()
EntityTypeInfo::getFormattedAmpEnabledTypes in src/EntityTypeInfo.php
Returns a formatted list of AMP-enabled content types.

File

src/EntityTypeInfo.php, line 67

Class

EntityTypeInfo
Service class for retrieving and manipulating entity type information.

Namespace

Drupal\amp

Code

public function getAmpEnabledTypes() {
  $enabled_types = [];
  if ($cache = $this->cache
    ->get('amp_enabled_types')) {
    $enabled_types = $cache->data;
  }
  else {

    // Get the list of node entities with AMP view mode enabled and store
    // their bundles.
    $ids = $this->entityTypeManager
      ->getStorage('entity_view_display')
      ->getQuery()
      ->condition('id', 'node.', 'STARTS_WITH')
      ->condition('mode', 'amp')
      ->condition('status', TRUE)
      ->execute();
    if ($ids) {
      foreach ($ids as $id) {
        $parts = explode('.', $id);
        $enabled_types[$parts[1]] = $parts[1];
      }
    }
    $this->cache
      ->set('amp_enabled_types', $enabled_types);
  }
  return $enabled_types;
}