You are here

public function ConfigHelper::getEntity in Lightning Core 8.5

Same name and namespace in other branches
  1. 8 src/ConfigHelper.php \Drupal\lightning_core\ConfigHelper::getEntity()
  2. 8.2 src/ConfigHelper.php \Drupal\lightning_core\ConfigHelper::getEntity()
  3. 8.3 src/ConfigHelper.php \Drupal\lightning_core\ConfigHelper::getEntity()
  4. 8.4 src/ConfigHelper.php \Drupal\lightning_core\ConfigHelper::getEntity()

Transparently loads a config entity from the extension's config.

Parameters

string $entity_type: The entity type ID.

string $id: The entity ID.

bool $force: (optional) If TRUE, the entity is read from config even if it already exists. Defaults to FALSE.

Return value

\Drupal\Core\Entity\EntityInterface|null The config entity, or NULL if it doesn't exist.

1 call to ConfigHelper::getEntity()
ConfigHelper::delete in src/ConfigHelper.php
Overrides Drupal\Core\Config\FileStorage::delete().

File

src/ConfigHelper.php, line 91

Class

ConfigHelper
A facade to assist with manipulating default config.

Namespace

Drupal\lightning_core

Code

public function getEntity($entity_type, $id, $force = FALSE) {
  $storage = $this->entityTypeManager
    ->getStorage($entity_type);
  $entity = $storage
    ->load($id);
  if ($entity && empty($force)) {
    return $entity;
  }
  $prefixes = $this
    ->getConfigPrefixes();
  return $storage
    ->create($this
    ->read($prefixes[$entity_type] . '.' . $id));
}