Update to Drupal 8.0.0-rc3. For more information, see https://www.drupal.org/node/2608078
This commit is contained in:
parent
6419a031d7
commit
4afb23bbd3
762 changed files with 20080 additions and 6368 deletions
|
@ -171,7 +171,7 @@ class BaseFieldDefinition extends ListDataDefinition implements FieldDefinitionI
|
|||
* settings are supplied.
|
||||
*/
|
||||
public function setSettings(array $settings) {
|
||||
// Assign settings individiually, in order to keep the current values
|
||||
// Assign settings individually, in order to keep the current values
|
||||
// of settings not specified in $settings.
|
||||
foreach ($settings as $setting_name => $setting) {
|
||||
$this->getItemDefinition()->setSetting($setting_name, $setting);
|
||||
|
|
|
@ -366,6 +366,7 @@ abstract class FieldConfigBase extends ConfigEntityBase implements FieldConfigIn
|
|||
*/
|
||||
public function setSetting($setting_name, $value) {
|
||||
$this->settings[$setting_name] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -535,6 +536,7 @@ abstract class FieldConfigBase extends ConfigEntityBase implements FieldConfigIn
|
|||
*/
|
||||
public function setConstraints(array $constraints) {
|
||||
$this->constraints = $constraints;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -542,6 +544,7 @@ abstract class FieldConfigBase extends ConfigEntityBase implements FieldConfigIn
|
|||
*/
|
||||
public function addConstraint($constraint_name, $options = NULL) {
|
||||
$this->constraints[$constraint_name] = $options;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
152
core/lib/Drupal/Core/Field/FieldDefinitionListener.php
Normal file
152
core/lib/Drupal/Core/Field/FieldDefinitionListener.php
Normal file
|
@ -0,0 +1,152 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Field\FieldDefinitionListener.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Field;
|
||||
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Entity\EntityFieldManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
|
||||
|
||||
/**
|
||||
* Reacts to field definition CRUD on behalf of the Entity system.
|
||||
*/
|
||||
class FieldDefinitionListener implements FieldDefinitionListenerInterface {
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The key-value factory.
|
||||
*
|
||||
* @var \Drupal\Core\KeyValueStore\KeyValueFactoryInterface
|
||||
*/
|
||||
protected $keyValueFactory;
|
||||
|
||||
/**
|
||||
* Cache backend instance.
|
||||
*
|
||||
* @var \Drupal\Core\Cache\CacheBackendInterface
|
||||
*/
|
||||
protected $cacheBackend;
|
||||
|
||||
/**
|
||||
* The entity field manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
|
||||
*/
|
||||
protected $entityFieldManager;
|
||||
|
||||
/**
|
||||
* Constructs a new FieldDefinitionListener.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
|
||||
* The entity field manager.
|
||||
* @param \Drupal\Core\KeyValueStore\KeyValueFactoryInterface $key_value_factory
|
||||
* The key-value factory.
|
||||
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
|
||||
* The cache backend.
|
||||
*/
|
||||
public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityFieldManagerInterface $entity_field_manager, KeyValueFactoryInterface $key_value_factory, CacheBackendInterface $cache_backend) {
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
$this->entityFieldManager = $entity_field_manager;
|
||||
$this->keyValueFactory = $key_value_factory;
|
||||
$this->cacheBackend = $cache_backend;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function onFieldDefinitionCreate(FieldDefinitionInterface $field_definition) {
|
||||
$entity_type_id = $field_definition->getTargetEntityTypeId();
|
||||
$bundle = $field_definition->getTargetBundle();
|
||||
$field_name = $field_definition->getName();
|
||||
|
||||
// Notify the storage about the new field.
|
||||
$this->entityTypeManager->getStorage($entity_type_id)->onFieldDefinitionCreate($field_definition);
|
||||
|
||||
// Update the bundle field map key value collection, add the new field.
|
||||
$bundle_field_map = $this->keyValueFactory->get('entity.definitions.bundle_field_map')->get($entity_type_id);
|
||||
if (!isset($bundle_field_map[$field_name])) {
|
||||
// This field did not exist yet, initialize it with the type and empty
|
||||
// bundle list.
|
||||
$bundle_field_map[$field_name] = [
|
||||
'type' => $field_definition->getType(),
|
||||
'bundles' => [],
|
||||
];
|
||||
}
|
||||
$bundle_field_map[$field_name]['bundles'][$bundle] = $bundle;
|
||||
$this->keyValueFactory->get('entity.definitions.bundle_field_map')->set($entity_type_id, $bundle_field_map);
|
||||
|
||||
// Delete the cache entry.
|
||||
$this->cacheBackend->delete('entity_field_map');
|
||||
|
||||
// If the field map is initialized, update it as well, so that calls to it
|
||||
// do not have to rebuild it again.
|
||||
if ($field_map = $this->entityFieldManager->getFieldMap()) {
|
||||
if (!isset($field_map[$entity_type_id][$field_name])) {
|
||||
// This field did not exist yet, initialize it with the type and empty
|
||||
// bundle list.
|
||||
$field_map[$entity_type_id][$field_name] = [
|
||||
'type' => $field_definition->getType(),
|
||||
'bundles' => [],
|
||||
];
|
||||
}
|
||||
$field_map[$entity_type_id][$field_name]['bundles'][$bundle] = $bundle;
|
||||
$this->entityFieldManager->setFieldMap($field_map);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function onFieldDefinitionUpdate(FieldDefinitionInterface $field_definition, FieldDefinitionInterface $original) {
|
||||
// Notify the storage about the updated field.
|
||||
$this->entityTypeManager->getStorage($field_definition->getTargetEntityTypeId())->onFieldDefinitionUpdate($field_definition, $original);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function onFieldDefinitionDelete(FieldDefinitionInterface $field_definition) {
|
||||
$entity_type_id = $field_definition->getTargetEntityTypeId();
|
||||
$bundle = $field_definition->getTargetBundle();
|
||||
$field_name = $field_definition->getName();
|
||||
|
||||
// Notify the storage about the field deletion.
|
||||
$this->entityTypeManager->getStorage($entity_type_id)->onFieldDefinitionDelete($field_definition);
|
||||
|
||||
// Unset the bundle from the bundle field map key value collection.
|
||||
$bundle_field_map = $this->keyValueFactory->get('entity.definitions.bundle_field_map')->get($entity_type_id);
|
||||
unset($bundle_field_map[$field_name]['bundles'][$bundle]);
|
||||
if (empty($bundle_field_map[$field_name]['bundles'])) {
|
||||
// If there are no bundles left, remove the field from the map.
|
||||
unset($bundle_field_map[$field_name]);
|
||||
}
|
||||
$this->keyValueFactory->get('entity.definitions.bundle_field_map')->set($entity_type_id, $bundle_field_map);
|
||||
|
||||
// Delete the cache entry.
|
||||
$this->cacheBackend->delete('entity_field_map');
|
||||
|
||||
// If the field map is initialized, update it as well, so that calls to it
|
||||
// do not have to rebuild it again.
|
||||
if ($field_map = $this->entityFieldManager->getFieldMap()) {
|
||||
unset($field_map[$entity_type_id][$field_name]['bundles'][$bundle]);
|
||||
if (empty($field_map[$entity_type_id][$field_name]['bundles'])) {
|
||||
unset($field_map[$entity_type_id][$field_name]);
|
||||
}
|
||||
$this->entityFieldManager->setFieldMap($field_map);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -122,11 +122,11 @@ interface FieldItemInterface extends ComplexDataInterface {
|
|||
* @param $property_name
|
||||
* The name of the property to get; e.g., 'title' or 'name'.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* If a not existing property is accessed.
|
||||
*
|
||||
* @return \Drupal\Core\TypedData\TypedDataInterface
|
||||
* The property object.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* If a not existing property is accessed.
|
||||
*/
|
||||
public function __get($property_name);
|
||||
|
||||
|
|
126
core/lib/Drupal/Core/Field/FieldStorageDefinitionListener.php
Normal file
126
core/lib/Drupal/Core/Field/FieldStorageDefinitionListener.php
Normal file
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Field\FieldStorageDefinitionListener.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Field;
|
||||
|
||||
use Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface;
|
||||
use Drupal\Core\Entity\EntityFieldManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
/**
|
||||
* Reacts to field storage definition CRUD on behalf of the Entity system.
|
||||
*
|
||||
* @see \Drupal\Core\Field\FieldStorageDefinitionEvents
|
||||
*/
|
||||
class FieldStorageDefinitionListener implements FieldStorageDefinitionListenerInterface {
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The event dispatcher.
|
||||
*
|
||||
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
|
||||
*/
|
||||
protected $eventDispatcher;
|
||||
|
||||
/**
|
||||
* The entity definition manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface
|
||||
*/
|
||||
protected $entityLastInstalledSchemaRepository;
|
||||
|
||||
/**
|
||||
* The entity field manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
|
||||
*/
|
||||
protected $entityFieldManager;
|
||||
|
||||
/**
|
||||
* Constructs a new FieldStorageDefinitionListener.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
|
||||
* The event dispatcher.
|
||||
* @param \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository
|
||||
* The entity last installed schema repository.
|
||||
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
|
||||
* The entity field manager.
|
||||
*/
|
||||
public function __construct(EntityTypeManagerInterface $entity_type_manager, EventDispatcherInterface $event_dispatcher, EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository, EntityFieldManagerInterface $entity_field_manager) {
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
$this->eventDispatcher = $event_dispatcher;
|
||||
$this->entityLastInstalledSchemaRepository = $entity_last_installed_schema_repository;
|
||||
$this->entityFieldManager = $entity_field_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function onFieldStorageDefinitionCreate(FieldStorageDefinitionInterface $storage_definition) {
|
||||
$entity_type_id = $storage_definition->getTargetEntityTypeId();
|
||||
|
||||
// @todo Forward this to all interested handlers, not only storage, once
|
||||
// iterating handlers is possible: https://www.drupal.org/node/2332857.
|
||||
$storage = $this->entityTypeManager->getStorage($entity_type_id);
|
||||
if ($storage instanceof FieldStorageDefinitionListenerInterface) {
|
||||
$storage->onFieldStorageDefinitionCreate($storage_definition);
|
||||
}
|
||||
|
||||
$this->eventDispatcher->dispatch(FieldStorageDefinitionEvents::CREATE, new FieldStorageDefinitionEvent($storage_definition));
|
||||
|
||||
$this->entityLastInstalledSchemaRepository->setLastInstalledFieldStorageDefinition($storage_definition);
|
||||
$this->entityFieldManager->clearCachedFieldDefinitions();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) {
|
||||
$entity_type_id = $storage_definition->getTargetEntityTypeId();
|
||||
|
||||
// @todo Forward this to all interested handlers, not only storage, once
|
||||
// iterating handlers is possible: https://www.drupal.org/node/2332857.
|
||||
$storage = $this->entityTypeManager->getStorage($entity_type_id);
|
||||
if ($storage instanceof FieldStorageDefinitionListenerInterface) {
|
||||
$storage->onFieldStorageDefinitionUpdate($storage_definition, $original);
|
||||
}
|
||||
|
||||
$this->eventDispatcher->dispatch(FieldStorageDefinitionEvents::UPDATE, new FieldStorageDefinitionEvent($storage_definition, $original));
|
||||
|
||||
$this->entityLastInstalledSchemaRepository->setLastInstalledFieldStorageDefinition($storage_definition);
|
||||
$this->entityFieldManager->clearCachedFieldDefinitions();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $storage_definition) {
|
||||
$entity_type_id = $storage_definition->getTargetEntityTypeId();
|
||||
|
||||
// @todo Forward this to all interested handlers, not only storage, once
|
||||
// iterating handlers is possible: https://www.drupal.org/node/2332857.
|
||||
$storage = $this->entityTypeManager->getStorage($entity_type_id);
|
||||
if ($storage instanceof FieldStorageDefinitionListenerInterface) {
|
||||
$storage->onFieldStorageDefinitionDelete($storage_definition);
|
||||
}
|
||||
|
||||
$this->eventDispatcher->dispatch(FieldStorageDefinitionEvents::DELETE, new FieldStorageDefinitionEvent($storage_definition));
|
||||
|
||||
$this->entityLastInstalledSchemaRepository->deleteLastInstalledFieldStorageDefinition($storage_definition);
|
||||
$this->entityFieldManager->clearCachedFieldDefinitions();
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue