Commit 145044ac authored by webchick's avatar webchick
Browse files

Issue #1824484 by tim.plunkett: Allow config storage controllers to define their own properties.

parent 97b5c6d7
......@@ -281,13 +281,9 @@ public function save(EntityInterface $entity) {
$this->preSave($entity);
$this->invokeHook('presave', $entity);
// Configuration objects do not have a schema. Extract all key names from
// class properties.
$class_info = new \ReflectionClass($entity);
$properties = $class_info->getProperties(\ReflectionProperty::IS_PUBLIC);
foreach ($properties as $property) {
$name = $property->getName();
$config->set($name, $entity->$name);
// Retrieve the desired properties and set them in config.
foreach ($this->getProperties($entity) as $key => $value) {
$config->set($key, $value);
}
if (!$config->isNew()) {
......@@ -309,6 +305,29 @@ public function save(EntityInterface $entity) {
return $return;
}
/**
* Retrieves the exportable properties of an entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity being saved.
*
* @return array
* An array of exportable properties and their values.
*
* @see \Drupal\Core\Config\Entity\ConfigStorageController::save()
*/
protected function getProperties(EntityInterface $entity) {
// Configuration objects do not have a schema. Extract all key names from
// class properties.
$class_info = new \ReflectionClass($entity);
$properties = array();
foreach ($class_info->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
$name = $property->getName();
$properties[$name] = $entity->$name;
}
return $properties;
}
/**
* Acts on an entity before the presave hook is invoked.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment