function ConfigEntityBase::toArray

Same name in other branches
  1. 9 core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php \Drupal\Core\Config\Entity\ConfigEntityBase::toArray()
  2. 8.9.x core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php \Drupal\Core\Config\Entity\ConfigEntityBase::toArray()
  3. 10 core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php \Drupal\Core\Config\Entity\ConfigEntityBase::toArray()

Overrides EntityBase::toArray

3 methods override ConfigEntityBase::toArray()
ConfigTest::toArray in core/modules/config/tests/config_test/src/Entity/ConfigTest.php
Gets an array of all property values.
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 252

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", $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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.