diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityNGBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityNGBase.php index 7a1397f..2363658 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityNGBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityNGBase.php @@ -27,31 +27,40 @@ protected $originalID; /** - * Overrides Entity::__construct(). + * Implements ConfigEntityInterface::getOriginalID(). */ - public function __construct(array $values, $entity_type) { - parent::__construct($values, $entity_type); + public function getOriginalID() { + return $this->originalID; + } - // Backup the original ID, if any. - // Configuration entity IDs are strings, and '0' is a valid ID. - $original_id = $this->id(); - if ($original_id !== NULL && $original_id !== '') { - $this->setOriginalID($original_id); - } + /** + * Implements ConfigEntityInterface::setOriginalID(). + */ + public function setOriginalID($id) { + $this->originalID = $id; } /** - * Implements ConfigEntityInterface::getOriginalID(). + * Implements \Drupal\Core\Config\Entity\ConfigEntityInterface::enable(). */ - public function getOriginalID() { - return $this->get('originalID')->value; + public function enable() { + $this->status = TRUE; + return $this; } /** - * Implements ConfigEntityInterface::setOriginalID(). + * Implements \Drupal\Core\Config\Entity\ConfigEntityInterface::disable(). */ - public function setOriginalID($id) { - $this->set('originalID', $id); + public function disable() { + $this->status = FALSE; + return $this; + } + + /** + * Implements \Drupal\Core\Config\Entity\ConfigEntityInterface::status(). + */ + public function status() { + return !empty($this->status); } /** @@ -100,7 +109,12 @@ public function getExportProperties() { $properties = array(); foreach ($class_info->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) { $name = $property->getName(); - $properties[$name] = $this->get($name); + if ($this->getPropertyDefinition($name)) { + $properties[$name] = $this->get($name); + } + else { + $properties[$name] = $this->{$name}; + } } return $properties; } diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageControllerNG.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageControllerNG.php index fe0fc89..ef8339d 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageControllerNG.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageControllerNG.php @@ -52,26 +52,9 @@ protected function buildQuery($ids, $revision_id = FALSE) { */ protected function attachLoad(&$queried_entities, $revision_id = FALSE) { // Map the loaded records into entity objects and according fields. - $queried_entities = $this->mapFromStorageRecords($queried_entities, $revision_id); - - parent::attachLoad($queried_entities, $revision_id); - } - - /** - * Maps from storage records to entity objects. - * - * @param array $records - * Associative array of query results, keyed on the entity ID. - * @param boolean $load_revision - * (optional) TRUE if the revision should be loaded, defaults to FALSE. - * - * @return array - * An array of entity objects implementing the EntityInterface. - */ - protected function mapFromStorageRecords(array $records, $load_revision = FALSE) { $class = $this->entityInfo['class']; $entities = array(); - foreach ($records as $id => $record) { + foreach ($queried_entities as $id => $record) { $values = array(); foreach ($record as $name => $value) { // Skip the item delta and item value levels but let the field assign @@ -81,15 +64,25 @@ protected function mapFromStorageRecords(array $records, $load_revision = FALSE) } // Turn the record into an entity class. $entities[$id] = new $class($values, $this->entityType); + $original_id = $entities[$id]->id(); + if ($original_id !== NULL && $original_id !== '') { + $entities[$id]->setOriginalID($original_id); + } } - return $entities; + $queried_entities = $entities; } /** * Overrides ConfigStorageController::create(). */ public function create(array $values) { - $entity = parent::create($values); + $class = $this->entityInfo['class']; + + $entity = new $class($values, $this->entityType); + // Mark this entity as new, so isNew() returns TRUE. This does not check + // whether a configuration entity with the same ID (if any) already exists. + $entity->enforceIsNew(); + // Assign a new UUID if there is none yet. if (!isset($entity->{$this->uuidKey}->value)) { @@ -102,6 +95,20 @@ public function create(array $values) { $entity->$name = $value; } + $original_id = $entity->id(); + if ($original_id !== NULL && $original_id !== '') { + $entity->setOriginalID($original_id); + } + + // Modules might need to add or change the data initially held by the new + // entity object, for instance to fill-in default values. + $this->invokeHook('create', $entity); + + // Default status to enabled. + if (!empty($this->statusKey) && !isset($entity->{$this->statusKey})) { + $entity->{$this->statusKey} = TRUE; + } + return $entity; } @@ -168,12 +175,7 @@ public function getFieldDefinitions(array $constraints) { * Implements \Drupal\Core\Entity\DataBaseStorageControllerNG::baseFieldDefinitions(). */ public function baseFieldDefinitions() { - $fields['originalID'] = array( - 'label' => t('Original ID'), - 'description' => t('The ID of the original entity.'), - 'type' => 'string_field', - ); - return $fields; + return array(); } } diff --git a/core/lib/Drupal/Core/Entity/EntityNG.php b/core/lib/Drupal/Core/Entity/EntityNG.php index 8763f6d..d7c2476 100644 --- a/core/lib/Drupal/Core/Entity/EntityNG.php +++ b/core/lib/Drupal/Core/Entity/EntityNG.php @@ -331,7 +331,7 @@ public function getTranslationLanguages($include_default = TRUE) { if (!$field->isEmpty()) { $translations[$langcode] = TRUE; } - if (isset($this->values[$name])) { + if (isset($this->values[$name]) && is_array($this->values[$name])) { foreach ($this->values[$name] as $langcode => $values) { // If a value is there but the field object is empty, it has been // unset, so we need to skip the field also. diff --git a/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php b/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php index 4159f04..7935484 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php @@ -105,7 +105,7 @@ public function getString() { foreach ($this->getProperties() as $property) { $strings[] = $property->getString(); } - return implode(', ', array_filter($strings)); + return implode(', ', $strings); } /** diff --git a/core/lib/Drupal/Core/Entity/Field/Type/Field.php b/core/lib/Drupal/Core/Entity/Field/Type/Field.php index 49418a0..9b3daa5 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/Field.php +++ b/core/lib/Drupal/Core/Entity/Field/Type/Field.php @@ -112,7 +112,7 @@ public function getString() { foreach ($this->list as $item) { $strings[] = $item->getString(); } - return implode(', ', array_filter($strings)); + return implode(', ', $strings); } } diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php index aad5ebc..bdfbbc1 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php @@ -179,7 +179,7 @@ function testCRUD() { // Test config entity prepopulation. state()->set('config_test.prepopulate', TRUE); $config_test = entity_create('config_test', array('foo' => 'bar')); - $this->assertEqual($config_test->get('foo'), 'baz', 'Initial value correctly populated'); + $this->assertEqual($config_test->foo, 'baz', 'Initial value correctly populated'); } /** diff --git a/core/modules/config/tests/config_test/config_test.module b/core/modules/config/tests/config_test/config_test.module index 677a066..843cfe0 100644 --- a/core/modules/config/tests/config_test/config_test.module +++ b/core/modules/config/tests/config_test/config_test.module @@ -156,7 +156,7 @@ function config_test_cache_flush() { */ function config_test_config_test_create(ConfigTest $config_test) { if (state()->get('config_test.prepopulate')) { - $config_test->set('foo', 'baz'); + $config_test->foo = 'baz'; } } diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigQueryTestStorageController.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigQueryTestStorageController.php deleted file mode 100644 index 35ae538..0000000 --- a/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigQueryTestStorageController.php +++ /dev/null @@ -1,34 +0,0 @@ - t('Number'), - 'description' => t('A number used by the sort tests.'), - 'type' => 'integer_field', - ); - $fields['array'] = array( - 'label' => t('Array'), - 'description' => t('An array used by the wildcard tests.'), - 'type' => 'string_field', - ); - return $fields; - } - -} - diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/Plugin/Core/Entity/ConfigQueryTest.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/Plugin/Core/Entity/ConfigQueryTest.php index 51d5df1..88e7583 100644 --- a/core/modules/config/tests/config_test/lib/Drupal/config_test/Plugin/Core/Entity/ConfigQueryTest.php +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/Plugin/Core/Entity/ConfigQueryTest.php @@ -17,7 +17,7 @@ * id = "config_query_test", * label = @Translation("Test configuration for query"), * module = "config_test", - * controller_class = "Drupal\config_test\ConfigQueryTestStorageController", + * controller_class = "Drupal\config_test\ConfigTestStorageController", * list_controller_class = "Drupal\Core\Config\Entity\ConfigEntityListController", * form_controller_class = { * "default" = "Drupal\config_test\ConfigTestFormController" diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/Plugin/Core/Entity/ConfigTest.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/Plugin/Core/Entity/ConfigTest.php index 8e31ce8..3391c14 100644 --- a/core/modules/config/tests/config_test/lib/Drupal/config_test/Plugin/Core/Entity/ConfigTest.php +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/Plugin/Core/Entity/ConfigTest.php @@ -78,7 +78,6 @@ protected function init() { unset($this->uuid); unset($this->style); unset($this->protected_property); - unset($this->originalID); } /**