/**
  * {@inheritdoc}
  */
 public function __sleep()
 {
     // Get the values of instantiated field objects, only serialize the values.
     foreach ($this->fields as $name => $fields) {
         foreach ($fields as $langcode => $field) {
             $this->values[$name][$langcode] = $field->getValue();
         }
     }
     $this->fields = array();
     $this->fieldDefinitions = NULL;
     $this->languages = NULL;
     $this->clearTranslationCache();
     return parent::__sleep();
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 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;
 }