diff --git a/core/lib/Drupal/Core/Config/TypedConfigManager.php b/core/lib/Drupal/Core/Config/TypedConfigManager.php index ae74387..8e52dcb 100644 --- a/core/lib/Drupal/Core/Config/TypedConfigManager.php +++ b/core/lib/Drupal/Core/Config/TypedConfigManager.php @@ -123,7 +123,7 @@ public function createInstance($plugin_id, array $configuration, $name = NULL, $ if (!isset($class)) { throw new PluginException(sprintf('The plugin (%s) did not specify an instance class.', $plugin_id)); } - if (class_implements($class, '\Drupal\Core\Plugin\ContainerFactoryPluginInterface')) { + if (in_array('Drupal\Core\Plugin\ContainerFactoryPluginInterface', class_implements($class))) { return $class::create(\Drupal::getContainer(), $configuration, $name, $type_definition, $parent); } else { diff --git a/core/lib/Drupal/Core/DependencyInjection/DependencySerialization.php b/core/lib/Drupal/Core/DependencyInjection/DependencySerialization.php index feb50f1..1964e8f 100644 --- a/core/lib/Drupal/Core/DependencyInjection/DependencySerialization.php +++ b/core/lib/Drupal/Core/DependencyInjection/DependencySerialization.php @@ -30,7 +30,7 @@ public function __sleep() { // If a class member was instantiated by the dependency injection // container, only store its ID so it can be used to get a fresh object // on unserialization. - $this->_serviceIds[$key] = $value->_serviceId; + $this->_serviceIds += array($key => $value->_serviceId); unset($vars[$key]); } } diff --git a/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php b/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php index 45de6a7..2bfcf65 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php @@ -32,7 +32,7 @@ public function __construct(array $definition, $name = NULL, TypedDataInterface // with the whole item. foreach ($this->getPropertyDefinitions() as $name => $definition) { if (!empty($definition['computed'])) { - $this->properties[$name] = \Drupal::typedData()->getPropertyInstance($this, $name); + $this->properties[$name] = $this->typedDataManager->getPropertyInstance($this, $name); } } } @@ -187,7 +187,7 @@ public function getConstraints() { // If property constraints are present add in a ComplexData constraint for // applying them. if (!empty($this->definition['property_constraints'])) { - $constraints[] = \Drupal::typedData()->getValidationConstraintManager() + $constraints[] = $this->typedDataManager->getValidationConstraintManager() ->create('ComplexData', $this->definition['property_constraints']); } return $constraints; diff --git a/core/lib/Drupal/Core/Language/LanguageManager.php b/core/lib/Drupal/Core/Language/LanguageManager.php index dc65633..7bc716d 100644 --- a/core/lib/Drupal/Core/Language/LanguageManager.php +++ b/core/lib/Drupal/Core/Language/LanguageManager.php @@ -13,7 +13,7 @@ /** * Class responsible for initializing each language type. */ -class LanguageManager implements \Serializable { +class LanguageManager { /** * A request object. @@ -308,26 +308,4 @@ public static function getStandardLanguageList() { ); } - /** - * {@inheritdoc} - */ - public function serialize() { - $manager = clone $this; - // Clear the request file bag. - if (!empty($manager->request->files)) { - $manager->request->files->replace(array()); - } - return serialize(get_object_vars($manager)); - } - - /** - * {@inheritdoc} - */ - public function unserialize($serialized) { - $data = unserialize($serialized); - foreach ($data as $key => $value) { - $this->{$key} = $value; - } - } - } diff --git a/core/lib/Drupal/Core/TypedData/TypedData.php b/core/lib/Drupal/Core/TypedData/TypedData.php index 6341831..610878b 100644 --- a/core/lib/Drupal/Core/TypedData/TypedData.php +++ b/core/lib/Drupal/Core/TypedData/TypedData.php @@ -10,6 +10,7 @@ use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\TypedData\TypedDataManager; +use Drupal\Core\DependencyInjection\DependencySerialization; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -18,7 +19,7 @@ * Classes deriving from this base class have to declare $value * or override getValue() or setValue(). */ -abstract class TypedData implements TypedDataInterface, PluginInspectionInterface, ContainerFactoryPluginInterface, \Serializable { +abstract class TypedData extends DependencySerialization implements TypedDataInterface, PluginInspectionInterface, ContainerFactoryPluginInterface { /** * The data definition. @@ -64,7 +65,7 @@ * * @see Drupal\Core\TypedData\TypedDataManager::create() */ - public function __construct(array $definition, $name = NULL, TypedDataInterface $parent = NULL, TypedDataManager $typed_data_manager) { + public function __construct(array $definition, $name = NULL, TypedDataInterface $parent = NULL, TypedDataManager $typed_data_manager = NULL) { $this->definition = $definition; $this->parent = $parent; $this->name = $name; @@ -220,28 +221,4 @@ public function getParent() { return $this->parent; } - /** - * {@inheritdoc} - */ - public function serialize() { - $values = array( - 'value' => $this->value, - 'definition' => $this->definition, - 'name' => $this->name, - 'parent' => $this->parent, - ); - return serialize($values); - } - - /** - * {@inheritdoc} - */ - public function unserialize($serialized) { - $data = unserialize($serialized); - foreach ($data as $key => $value) { - $this->{$key} = $value; - } - $this->typedDataManager = \Drupal::typedData(); - } - } diff --git a/core/lib/Drupal/Core/TypedData/TypedDataManager.php b/core/lib/Drupal/Core/TypedData/TypedDataManager.php index daa8bb0..4678ead 100644 --- a/core/lib/Drupal/Core/TypedData/TypedDataManager.php +++ b/core/lib/Drupal/Core/TypedData/TypedDataManager.php @@ -93,7 +93,7 @@ public function createInstance($plugin_id, array $configuration, $name = NULL, $ if (!isset($class)) { throw new PluginException(sprintf('The plugin (%s) did not specify an instance class.', $plugin_id)); } - if (class_implements($class, '\Drupal\Core\Plugin\ContainerFactoryPluginInterface')) { + if (in_array('Drupal\Core\Plugin\ContainerFactoryPluginInterface', class_implements($class))) { return $class::create(\Drupal::getContainer(), $configuration, $name, $type_definition, $parent); } else { diff --git a/core/modules/email/lib/Drupal/email/Plugin/field/field_type/ConfigurableEmailItem.php b/core/modules/email/lib/Drupal/email/Plugin/field/field_type/ConfigurableEmailItem.php index b346c4b..7662004 100644 --- a/core/modules/email/lib/Drupal/email/Plugin/field/field_type/ConfigurableEmailItem.php +++ b/core/modules/email/lib/Drupal/email/Plugin/field/field_type/ConfigurableEmailItem.php @@ -56,7 +56,7 @@ public static function schema(FieldInterface $field) { * {@inheritdoc} */ public function getConstraints() { - $constraint_manager = \Drupal::typedData()->getValidationConstraintManager(); + $constraint_manager = $this->typedDataManager->getValidationConstraintManager(); $constraints = parent::getConstraints(); $constraints[] = $constraint_manager->create('ComplexData', array( diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php index 8702a67..22effae 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php @@ -9,8 +9,10 @@ use Drupal\Core\TypedData\TypedDataInterface; use Drupal\Core\TypedData\TypedDataManager; +use Drupal\field\Plugin\Type\Widget\WidgetPluginManager; use Drupal\Core\Entity\Field\Field; use Drupal\field\Field as FieldAPI; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Represents a configurable entity field. @@ -25,9 +27,17 @@ class ConfigField extends Field implements ConfigFieldInterface { protected $instance; /** + * The WidgetPluginManager + * + * @var WidgetPluginManager + */ + protected $WidgetPluginManager; + + /** * {@inheritdoc} */ - public function __construct(array $definition, $name = NULL, TypedDataInterface $parent = NULL, TypedDataManager $typed_data_manager) { + public function __construct(array $definition, $name = NULL, TypedDataInterface $parent = NULL, TypedDataManager $typed_data_manager, WidgetPluginManager $WidgetPluginManager) { + $this->WidgetPluginManager = $WidgetPluginManager; parent::__construct($definition, $name, $parent, $typed_data_manager); if (isset($definition['instance'])) { $this->instance = $definition['instance']; @@ -37,6 +47,19 @@ public function __construct(array $definition, $name = NULL, TypedDataInterface /** * {@inheritdoc} */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition, TypedDataInterface $parent = NULL) { + return new static( + $configuration, + $plugin_id, + $parent, + $container->get('typed_data'), + $container::service('plugin.manager.field.widget') + ); + } + + /** + * {@inheritdoc} + */ public function getFieldDefinition() { if (!isset($this->instance) && $parent = $this->getParent()) { $instances = FieldAPI::fieldInfo()->getBundleInstances($parent->entityType(), $parent->bundle()); @@ -55,8 +78,7 @@ public function getConstraints() { // widgets. $cardinality = $this->getFieldDefinition()->getFieldCardinality(); if ($cardinality != FIELD_CARDINALITY_UNLIMITED) { - $constraints[] = \Drupal::typedData() - ->getValidationConstraintManager() + $constraints[] = $this->typedDataManager->getValidationConstraintManager() ->create('Count', array( 'max' => $cardinality, 'maxMessage' => t('%name: this field cannot hold more than @count values.', array('%name' => $this->getFieldDefinition()->getFieldLabel(), '@count' => $cardinality)), @@ -148,7 +170,7 @@ protected function defaultValueWidget(array &$form_state) { $entity_form_display = entity_get_form_display($entity->entityType(), $entity->bundle(), 'default'); $widget = $entity_form_display->getRenderer($this->getFieldDefinition()->getFieldName()); if (!$widget) { - $widget = \Drupal::service('plugin.manager.field.widget')->getInstance(array('field_definition' => $this->getFieldDefinition())); + $widget = $this->WidgetPluginManager->getInstance(array('field_definition' => $this->getFieldDefinition())); } $form_state['default_value_widget'] = $widget; diff --git a/core/modules/locale/lib/Drupal/locale/LocaleConfigManager.php b/core/modules/locale/lib/Drupal/locale/LocaleConfigManager.php index 9a2f69f..7d87f75 100644 --- a/core/modules/locale/lib/Drupal/locale/LocaleConfigManager.php +++ b/core/modules/locale/lib/Drupal/locale/LocaleConfigManager.php @@ -10,7 +10,6 @@ use Drupal\Core\Language\Language; use Drupal\Core\Config\TypedConfigManager; use Drupal\Core\Config\StorageInterface; -use Drupal\Core\TypedData\TypedDataManager; /** * Manages localized configuration type plugins. @@ -56,15 +55,12 @@ class LocaleConfigManager extends TypedConfigManager { * data. * @param \Drupal\locale\StringStorageInterface $localeStorage * The locale storage to use for reading string translations. - * @param \Drupal\Core\TypedData\TypedDataManager $typed_data_manager - * The typed data manager service. */ - public function __construct(StorageInterface $configStorage, StorageInterface $schemaStorage, StorageInterface $installStorage, StringStorageInterface $localeStorage, TypedDataManager $typed_data_manager) { + public function __construct(StorageInterface $configStorage, StorageInterface $schemaStorage, StorageInterface $installStorage, StringStorageInterface $localeStorage) { // Note we use the install storage for the parent constructor. parent::__construct($configStorage, $schemaStorage); $this->installStorage = $installStorage; $this->localeStorage = $localeStorage; - $this->typedDataManager = $typed_data_manager; } /** @@ -85,7 +81,7 @@ public function get($name) { $definition = $this->getDefinition($name); // Unless the configuration has a explicit language code we assume English. $langcode = isset($default['langcode']) ? $default['langcode'] : 'en'; - $wrapper = new LocaleTypedConfig($definition, $name, $langcode, $this, $this->typedDataManager); + $wrapper = new LocaleTypedConfig($definition, $name, $langcode, $this); $wrapper->setValue($data); return $wrapper; } diff --git a/core/modules/locale/lib/Drupal/locale/LocaleTypedConfig.php b/core/modules/locale/lib/Drupal/locale/LocaleTypedConfig.php index 226d104..0e6acc4 100644 --- a/core/modules/locale/lib/Drupal/locale/LocaleTypedConfig.php +++ b/core/modules/locale/lib/Drupal/locale/LocaleTypedConfig.php @@ -12,6 +12,7 @@ use Drupal\Core\TypedData\TypedDataManager; use Drupal\Core\Config\Schema\Element; use Drupal\Core\Config\Schema\ArrayElement; +use Drupal\locale\LocaleConfigManager; /** * Defines the locale configuration wrapper object. @@ -53,8 +54,8 @@ class LocaleTypedConfig extends Element { * @param \Drupal\Core\TypedData\TypedDataManager $typed_data_manager * The typed data plugin manager. */ - public function __construct(array $definition, $name, $langcode, \Drupal\locale\LocaleConfigManager $localeConfig, TypedDataManager $typed_data_manager) { - parent::__construct($definition, $name, NULL, $typed_data_manager); + public function __construct(array $definition, $name, $langcode, LocaleConfigManager $localeConfig) { + parent::__construct($definition, $name, NULL, NULL); $this->langcode = $langcode; $this->localeConfig = $localeConfig; } diff --git a/core/modules/locale/locale.services.yml b/core/modules/locale/locale.services.yml index 64dc3fc..f632704 100644 --- a/core/modules/locale/locale.services.yml +++ b/core/modules/locale/locale.services.yml @@ -6,7 +6,7 @@ services: arguments: ['@language_manager', '@config.context'] locale.config.typed: class: Drupal\locale\LocaleConfigManager - arguments: ['@config.storage', '@config.storage.schema', '@config.storage.installer', '@locale.storage', '@typed_data'] + arguments: ['@config.storage', '@config.storage.schema', '@config.storage.installer', '@locale.storage'] locale.storage: class: Drupal\locale\StringDatabaseStorage arguments: ['@database'] diff --git a/core/modules/number/lib/Drupal/number/Plugin/field/field_type/NumberItemBase.php b/core/modules/number/lib/Drupal/number/Plugin/field/field_type/NumberItemBase.php index 1d83bb7..a1d96f7 100644 --- a/core/modules/number/lib/Drupal/number/Plugin/field/field_type/NumberItemBase.php +++ b/core/modules/number/lib/Drupal/number/Plugin/field/field_type/NumberItemBase.php @@ -74,7 +74,7 @@ public function isEmpty() { * {@inheritdoc} */ public function getConstraints() { - $constraint_manager = \Drupal::typedData()->getValidationConstraintManager(); + $constraint_manager = $this->typedDataManager->getValidationConstraintManager(); $constraints = parent::getConstraints(); $settings = $this->getFieldSettings(); diff --git a/core/modules/telephone/lib/Drupal/telephone/Plugin/field/field_type/TelephoneItem.php b/core/modules/telephone/lib/Drupal/telephone/Plugin/field/field_type/TelephoneItem.php index efe2bcf..47b8083 100644 --- a/core/modules/telephone/lib/Drupal/telephone/Plugin/field/field_type/TelephoneItem.php +++ b/core/modules/telephone/lib/Drupal/telephone/Plugin/field/field_type/TelephoneItem.php @@ -72,7 +72,7 @@ public function isEmpty() { * {@inheritdoc} */ public function getConstraints() { - $constraint_manager = \Drupal::typedData()->getValidationConstraintManager(); + $constraint_manager = $this->typedDataManager->getValidationConstraintManager(); $constraints = parent::getConstraints(); $max_length = 256; diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItem.php b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItem.php index 644a2a9..7d8662f 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItem.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItem.php @@ -63,7 +63,7 @@ public static function schema(FieldInterface $field) { * {@inheritdoc} */ public function getConstraints() { - $constraint_manager = \Drupal::typedData()->getValidationConstraintManager(); + $constraint_manager = $this->typedDataManager->getValidationConstraintManager(); $constraints = parent::getConstraints(); if ($max_length = $this->getFieldSetting('max_length')) {