You are here

public function TcaSettingsManager::loadSettingsAsConfig in Token Content Access 8

Same name and namespace in other branches
  1. 2.0.x src/TcaSettingsManager.php \Drupal\tca\TcaSettingsManager::loadSettingsAsConfig()

Load settings for an entity or bundle, or load the defaults.

Load TCA settings appropriate to the given config or default settings if not available.

Parameters

string $entity_type_id: The entity type (e.g. node) as a string.

string $entity_id: The entity ID as a string.

Return value

\Drupal\Core\Config\ImmutableConfig The TcaSettings Config object.

Overrides TcaSettingsManagerInterface::loadSettingsAsConfig

File

src/TcaSettingsManager.php, line 82

Class

TcaSettingsManager
Class TcaSettingsManager.

Namespace

Drupal\tca

Code

public function loadSettingsAsConfig($entity_type_id, $entity_id) {

  // Load real entity if it has settings.
  $entity = $this
    ->getEntity($entity_type_id, $entity_id);
  if ($entity) {
    $config = $this->configFactory
      ->get('tca.tca_settings.default');
    $settings = $config
      ->getRawData();
    foreach ($settings as $key => $value) {
      $field = 'tca_' . $key;
      if ($entity
        ->hasField($field)) {
        if (isset($entity
          ->get($field)->value)) {
          $settings[$key] = $entity
            ->get($field)->value;
        }
      }
    }
    return $config
      ->initWithData($settings);
  }
  else {
    $id = $this
      ->generateSettingsFullId($entity_type_id, $entity_id);
    $actual = $this->configFactory
      ->get('tca.tca_settings.' . $id);
    if (!$actual
      ->isNew()) {
      return $actual;
    }
    else {
      return $this->configFactory
        ->get('tca.tca_settings.default');
    }
  }
}