function ConfigEntityBase::__sleep

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

Overrides EntityBase::__sleep

1 call to ConfigEntityBase::__sleep()
View::__sleep in core/modules/views/src/Entity/View.php
4 methods override ConfigEntityBase::__sleep()
EntityDisplayBase::__sleep in core/lib/Drupal/Core/Entity/EntityDisplayBase.php
FieldConfigBase::__sleep in core/lib/Drupal/Core/Field/FieldConfigBase.php
Implements the magic __sleep() method.
FieldStorageConfig::__sleep in core/modules/field/src/Entity/FieldStorageConfig.php
Implements the magic __sleep() method.
View::__sleep in core/modules/views/src/Entity/View.php

File

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

Class

ConfigEntityBase
Defines a base configuration entity class.

Namespace

Drupal\Core\Config\Entity

Code

public function __sleep() {
    $keys_to_unset = [];
    if ($this instanceof EntityWithPluginCollectionInterface) {
        // Get the plugin collections first, so that the properties are
        // initialized in $vars and can be found later.
        $plugin_collections = $this->getPluginCollections();
        $vars = get_object_vars($this);
        foreach ($plugin_collections 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;
}

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