public function ConfigEntityBase::__sleep

public ConfigEntityBase::__sleep()

Overrides Entity::__sleep

File

core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php, line 353

Class

ConfigEntityBase
Defines a base configuration entity class.

Namespace

Drupal\Core\Config\Entity

Code

public function __sleep() {
  $keys_to_unset = [];
  if ($this instanceof EntityWithPluginCollectionInterface) {
    $vars = get_object_vars($this);
    foreach ($this->getPluginCollections() as $plugin_config_key => $plugin_collection) {
      // Save any changes to the plugin configuration to the entity.
      $this->set($plugin_config_key, $plugin_collection->getConfiguration());
      // If the plugin collections are stored as properties on the entity,
      // mark them to be unset.
      $keys_to_unset += array_filter($vars, function($value) use ($plugin_collection) {
        return $plugin_collection === $value;
      });
    }
  }

  $vars = parent::__sleep();

  if (!empty($keys_to_unset)) {
    $vars = array_diff($vars, array_keys($keys_to_unset));
  }
  return $vars;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Config!Entity!ConfigEntityBase.php/function/ConfigEntityBase::__sleep/8.1.x