pluginManager = \Drupal::service('plugin.manager.field.widget'); parent::__construct($values, $entity_type); } /** * {@inheritdoc} */ public function getRenderer($field_name) { if (isset($this->plugins[$field_name])) { return $this->plugins[$field_name]; } // Instantiate the widget object from the stored display properties. if (($configuration = $this->getComponent($field_name)) && isset($configuration['type']) && ($definition = $this->getFieldDefinition($field_name))) { $widget = $this->pluginManager->getInstance(array( 'field_definition' => $definition, 'form_mode' => $this->originalMode, // No need to prepare, defaults have been merged in setComponent(). 'prepare' => FALSE, 'configuration' => $configuration )); } else { $widget = NULL; } // Persist the widget object. $this->plugins[$field_name] = $widget; return $widget; } /** * {@inheritdoc} */ public function serialize() { // Only store the definition, not external objects or derived data. $data = $this->getExportProperties() + array('entityType' => $this->entityType()); return serialize($data); } /** * {@inheritdoc} */ public function unserialize($serialized) { $data = unserialize($serialized); $entity_type = $data['entityType']; unset($data['entityType']); $this->__construct($data, $entity_type); } }