You are here

public function BackgroundImageManager::getEntityConfigArray in Background Image 8

Same name and namespace in other branches
  1. 2.x src/BackgroundImageManager.php \Drupal\background_image\BackgroundImageManager::getEntityConfigArray()
  2. 2.0.x src/BackgroundImageManager.php \Drupal\background_image\BackgroundImageManager::getEntityConfigArray()

Retrieves the entity configuration values from storage.

Parameters

string $entity_type: The entity type identifier.

string $bundle: The entity bundle identifier.

string $property: A nested property to pluck.

bool $filter: Flag indicating whether to filter empty results.

Return value

mixed

Overrides BackgroundImageManagerInterface::getEntityConfigArray

2 calls to BackgroundImageManager::getEntityConfigArray()
BackgroundImageManager::getEnabledEntityTypeBundles in src/BackgroundImageManager.php
Retrieves the enabled bundles for an entity type.
BackgroundImageManager::getEntityConfig in src/BackgroundImageManager.php
Retrieves an entity property value from the config.

File

src/BackgroundImageManager.php, line 473

Class

BackgroundImageManager

Namespace

Drupal\background_image

Code

public function getEntityConfigArray($entity_type = NULL, $bundle = NULL, $property = NULL, $filter = TRUE) {
  if ($entity_type instanceof EntityInterface) {
    $entity_type = $entity_type
      ->getEntityTypeId();
  }
  else {
    if ($entity_type instanceof EntityTypeInterface) {
      $entity_type = $entity_type
        ->id();
    }
  }
  $entity_type = (string) $entity_type;

  // Return with the config if no property was specified.
  if (!$property) {
    $keys = [
      'entities',
    ];
    if ($entity_type) {
      $keys[] = $entity_type;
      if ($bundle) {
        $keys[] = (string) $bundle;
      }
    }
    $config = $this->config
      ->get(implode('.', $keys)) ?: [];
    return $filter ? array_filter($config) : $config;
  }

  // Return a nested property if a property was specified.
  $properties = [];
  foreach ($this->config
    ->get('entities') as $t => $bundles) {
    if ($entity_type && $entity_type !== $t) {
      continue;
    }
    foreach ($bundles as $b => $data) {
      if ($bundle && $bundle !== $b) {
        continue;
      }
      foreach ($data as $key => $value) {
        if ($key === $property) {
          $properties[$t][$b] = $value;
        }
      }
      if ($filter) {
        $properties[$t] = array_filter($properties[$t]);
      }
    }
    if ($filter) {
      $properties = array_filter($properties);
    }
  }
  return $properties;
}