You are here

public function ConfigEntityBase::toArray in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 Entity::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 269
Contains \Drupal\Core\Config\Entity\ConfigEntityBase.

Class

ConfigEntityBase
Defines a base configuration entity class.

Namespace

Drupal\Core\Config\Entity

Code

public function toArray() {
  $properties = array();

  /** @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface $entity_type */
  $entity_type = $this
    ->getEntityType();
  $properties_to_export = $entity_type
    ->getPropertiesToExport();
  if (empty($properties_to_export)) {
    $config_name = $entity_type
      ->getConfigPrefix() . '.' . $this
      ->id();
    $definition = $this
      ->getTypedConfig()
      ->getDefinition($config_name);
    if (!isset($definition['mapping'])) {
      throw new SchemaIncompleteException("Incomplete or missing schema for {$config_name}");
    }
    $properties_to_export = array_combine(array_keys($definition['mapping']), array_keys($definition['mapping']));
  }
  $id_key = $entity_type
    ->getKey('id');
  foreach ($properties_to_export 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']);
  }
  return $properties;
}