You are here

public function ConfigEntityBase::toArray in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php \Drupal\Core\Config\Entity\ConfigEntityBase::toArray()

Gets an array of all property values.

Return value

mixed[] An array of property values, keyed by property name.

Overrides EntityBase::toArray

2 calls to ConfigEntityBase::toArray()
EntityDisplayBase::toArray in core/lib/Drupal/Core/Entity/EntityDisplayBase.php
Gets an array of all property values.
FilterFormat::toArray in core/modules/filter/src/Entity/FilterFormat.php
Gets an array of all property values.
2 methods override ConfigEntityBase::toArray()
EntityDisplayBase::toArray in core/lib/Drupal/Core/Entity/EntityDisplayBase.php
Gets an array of all property values.
FilterFormat::toArray in core/modules/filter/src/Entity/FilterFormat.php
Gets an array of all property values.

File

core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php, line 243

Class

ConfigEntityBase
Defines a base configuration entity class.

Namespace

Drupal\Core\Config\Entity

Code

public function toArray() {
  $properties = [];

  /** @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface $entity_type */
  $entity_type = $this
    ->getEntityType();
  $id_key = $entity_type
    ->getKey('id');
  $property_names = $entity_type
    ->getPropertiesToExport($this
    ->id());
  if (empty($property_names)) {
    throw new SchemaIncompleteException(sprintf("Entity type '%s' is missing 'config_export' definition in its annotation", get_class($entity_type)));
  }
  foreach ($property_names as $property_name => $export_name) {

    // Special handling for IDs so that computed compound IDs work.
    // @see \Drupal\Core\Entity\EntityDisplayBase::id()
    if ($property_name == $id_key) {
      $properties[$export_name] = $this
        ->id();
    }
    else {
      $properties[$export_name] = $this
        ->get($property_name);
    }
  }
  if (empty($this->third_party_settings)) {
    unset($properties['third_party_settings']);
  }
  if (empty($this->_core)) {
    unset($properties['_core']);
  }
  return $properties;
}