You are here

public function SeoManager::getEnabledBundles in Real-time SEO for Drupal 8.2

Returns an array of bundles that have a 'yoast_seo' field.

Return value

array A nested array of entities and bundles. The outer array is keyed by entity id. The inner array is keyed by bundle id and contains the bundle label. If an entity has no bundles then the inner array is keyed by entity id.

File

src/SeoManager.php, line 70

Class

SeoManager
Utility service for the Real-Time SEO module.

Namespace

Drupal\yoast_seo

Code

public function getEnabledBundles() {
  $entities = [];

  /** @var \Drupal\Core\Entity\EntityTypeInterface $definition */
  foreach ($this->entityTypeManager
    ->getDefinitions() as $definition) {
    $entity_id = $definition
      ->id();
    $bundles = $this->entityTypeBundleInfo
      ->getBundleInfo($entity_id);
    foreach ($bundles as $bundle_id => $bundle_metadata) {
      $bundle_label = $bundle_metadata['label'];
      $field_definitions = $this->entityFieldManager
        ->getFieldDefinitions($entity_id, $bundle_id);
      if (!empty($field_definitions['yoast_seo'])) {
        if (!isset($entities[$entity_id])) {
          $entities[$entity_id] = [];
        }
        $entities[$entity_id][$bundle_id] = $bundle_label;
      }
    }
  }
  return $entities;
}