You are here

public function ConfigEntityBase::toArray in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php \Drupal\Core\Config\Entity\ConfigEntityBase::toArray()
  2. 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 245

Class

ConfigEntityBase

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", $entity_type
      ->getClass()));
  }
  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;
}