You are here

public function ConfigEntityType::getPropertiesToExport in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php \Drupal\Core\Config\Entity\ConfigEntityType::getPropertiesToExport()
  2. 10 core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php \Drupal\Core\Config\Entity\ConfigEntityType::getPropertiesToExport()

Gets the config entity properties to export if declared on the annotation.

Falls back to determining the properties using configuration schema, if the config entity properties are not declared.

Parameters

string $id: The ID of the configuration entity. Used when checking schema instead of the annotation.

Return value

array|null The properties to export or NULL if they can not be determine from the config entity type annotation or the schema.

Overrides ConfigEntityTypeInterface::getPropertiesToExport

File

core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php, line 147

Class

ConfigEntityType
Provides an implementation of a configuration entity type and its metadata.

Namespace

Drupal\Core\Config\Entity

Code

public function getPropertiesToExport($id = NULL) {
  if (!empty($this->mergedConfigExport)) {
    return $this->mergedConfigExport;
  }
  if (!empty($this->config_export)) {

    // Always add default properties to be exported.
    $this->mergedConfigExport = [
      'uuid' => 'uuid',
      'langcode' => 'langcode',
      'status' => 'status',
      'dependencies' => 'dependencies',
      'third_party_settings' => 'third_party_settings',
      '_core' => '_core',
    ];
    foreach ($this->config_export as $property => $name) {
      if (is_numeric($property)) {
        $this->mergedConfigExport[$name] = $name;
      }
      else {
        $this->mergedConfigExport[$property] = $name;
      }
    }
  }
  else {

    // @todo https://www.drupal.org/project/drupal/issues/2949021 Deprecate
    //   fallback to schema.
    $config_name = $this
      ->getConfigPrefix() . '.' . $id;
    $definition = \Drupal::service('config.typed')
      ->getDefinition($config_name);
    if (!isset($definition['mapping'])) {
      return NULL;
    }
    @trigger_error(sprintf('Entity type "%s" is using config schema as a fallback for a missing `config_export` definition is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. See https://www.drupal.org/node/2949023.', $this
      ->id()), E_USER_DEPRECATED);
    $this->mergedConfigExport = array_combine(array_keys($definition['mapping']), array_keys($definition['mapping']));
  }
  return $this->mergedConfigExport;
}