Unverified Commit 28bf970d authored by alexpott's avatar alexpott
Browse files

Issue #3028656 by Berdir, martin107: Add @trigger_error() to deprecated...

Issue #3028656 by Berdir, martin107: Add @trigger_error() to deprecated EntityManager listener methods
parent e69e249d
......@@ -61,7 +61,7 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti
foreach ($entities as $entity) {
$entity->deleteDisplays();
\Drupal::entityManager()->onBundleDelete($entity->id(), $entity->getEntityType()->getBundleOf());
\Drupal::service('entity_bundle.listener')->onBundleDelete($entity->id(), $entity->getEntityType()->getBundleOf());
}
}
......
......@@ -258,6 +258,7 @@ public function getFieldMapByFieldType($field_type) {
* @see https://www.drupal.org/node/2549139
*/
public function onFieldDefinitionCreate(FieldDefinitionInterface $field_definition) {
@trigger_error('EntityManagerInterface::onFieldDefinitionCreate() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Field\FieldDefinitionListenerInterface::onFieldDefinitionCreate() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
$this->container->get('field_definition.listener')->onFieldDefinitionCreate($field_definition);
}
......@@ -271,6 +272,7 @@ public function onFieldDefinitionCreate(FieldDefinitionInterface $field_definiti
* @see https://www.drupal.org/node/2549139
*/
public function onFieldDefinitionUpdate(FieldDefinitionInterface $field_definition, FieldDefinitionInterface $original) {
@trigger_error('EntityManagerInterface::onFieldDefinitionUpdate() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Field\FieldDefinitionListenerInterface::onFieldDefinitionUpdate() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
$this->container->get('field_definition.listener')->onFieldDefinitionUpdate($field_definition, $original);
}
......@@ -284,6 +286,7 @@ public function onFieldDefinitionUpdate(FieldDefinitionInterface $field_definiti
* @see https://www.drupal.org/node/2549139
*/
public function onFieldDefinitionDelete(FieldDefinitionInterface $field_definition) {
@trigger_error('EntityManagerInterface::onFieldDefinitionDelete() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Field\FieldDefinitionListenerInterface::onFieldDefinitionDelete() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
$this->container->get('field_definition.listener')->onFieldDefinitionDelete($field_definition);
}
......@@ -535,6 +538,7 @@ public function getEntityTypeFromClass($class_name) {
* {@inheritdoc}
*/
public function onEntityTypeCreate(EntityTypeInterface $entity_type) {
@trigger_error('EntityManagerInterface::onEntityTypeCreate() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityTypeListenerInterface::onEntityTypeCreate() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
$this->container->get('entity_type.listener')->onEntityTypeCreate($entity_type);
}
......@@ -548,6 +552,7 @@ public function onEntityTypeCreate(EntityTypeInterface $entity_type) {
* @see https://www.drupal.org/node/2549139
*/
public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original) {
@trigger_error('EntityManagerInterface::onEntityTypeUpdate() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityTypeListenerInterface::onEntityTypeUpdate() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
$this->container->get('entity_type.listener')->onEntityTypeUpdate($entity_type, $original);
}
......@@ -574,6 +579,7 @@ public function onFieldableEntityTypeUpdate(EntityTypeInterface $entity_type, En
* @see https://www.drupal.org/node/2549139
*/
public function onEntityTypeDelete(EntityTypeInterface $entity_type) {
@trigger_error('EntityManagerInterface::onEntityTypeDelete() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityTypeListenerInterface::onEntityTypeDelete() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
$this->container->get('entity_type.listener')->onEntityTypeDelete($entity_type);
}
......@@ -587,6 +593,7 @@ public function onEntityTypeDelete(EntityTypeInterface $entity_type) {
* @see https://www.drupal.org/node/2549139
*/
public function onFieldStorageDefinitionCreate(FieldStorageDefinitionInterface $storage_definition) {
@trigger_error('EntityManagerInterface::onFieldStorageDefinitionCreate() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Field\FieldStorageDefinitionListenerInterface::onFieldStorageDefinitionCreate() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
$this->container->get('field_storage_definition.listener')->onFieldStorageDefinitionCreate($storage_definition);
}
......@@ -600,6 +607,7 @@ public function onFieldStorageDefinitionCreate(FieldStorageDefinitionInterface $
* @see https://www.drupal.org/node/2549139
*/
public function onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) {
@trigger_error('EntityManagerInterface::onFieldStorageDefinitionUpdate() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Field\FieldStorageDefinitionListenerInterface::onFieldStorageDefinitionUpdate() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
$this->container->get('field_storage_definition.listener')->onFieldStorageDefinitionUpdate($storage_definition, $original);
}
......@@ -613,6 +621,7 @@ public function onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $
* @see https://www.drupal.org/node/2549139
*/
public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $storage_definition) {
@trigger_error('EntityManagerInterface::onFieldStorageDefinitionDelete() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Field\FieldStorageDefinitionListenerInterface::onFieldStorageDefinitionDelete() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
$this->container->get('field_storage_definition.listener')->onFieldStorageDefinitionDelete($storage_definition);
}
......@@ -626,6 +635,7 @@ public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $
* @see https://www.drupal.org/node/2549139
*/
public function onBundleCreate($bundle, $entity_type_id) {
@trigger_error('EntityManagerInterface::onBundleCreate() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityBundleListenerInterface::onBundleCreate() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
$this->container->get('entity_bundle.listener')->onBundleCreate($bundle, $entity_type_id);
}
......@@ -639,6 +649,7 @@ public function onBundleCreate($bundle, $entity_type_id) {
* @see https://www.drupal.org/node/2549139
*/
public function onBundleDelete($bundle, $entity_type_id) {
@trigger_error('EntityManagerInterface::onBundleDelete() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityBundleListenerInterface::onBundleDelete() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
$this->container->get('entity_bundle.listener')->onBundleDelete($bundle, $entity_type_id);
}
......
......@@ -394,7 +394,7 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
foreach ($entity_manager->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type->getProvider() == $module) {
foreach (array_keys($entity_manager->getBundleInfo($entity_type_id)) as $bundle) {
$entity_manager->onBundleDelete($bundle, $entity_type_id);
\Drupal::service('entity_bundle.listener')->onBundleDelete($bundle, $entity_type_id);
}
}
}
......
......@@ -211,9 +211,9 @@ public function preSave(EntityStorageInterface $storage) {
* {@inheritdoc}
*/
public static function postDelete(EntityStorageInterface $storage, array $field_overrides) {
$entity_manager = \Drupal::entityManager();
$entity_type_manager = \Drupal::entityTypeManager();
// Clear the cache upfront, to refresh the results of getBundles().
$entity_manager->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
/** @var \Drupal\Core\Field\Entity\BaseFieldOverride $field_override */
foreach ($field_overrides as $field_override) {
// Inform the system that the field definition is being updated back to
......@@ -221,7 +221,7 @@ public static function postDelete(EntityStorageInterface $storage, array $field_
// @todo This assumes that there isn't a non-config-based override that
// we're returning to, but that might not be the case:
// https://www.drupal.org/node/2321071.
$entity_manager->getStorage($field_override->getTargetEntityTypeId())->onFieldDefinitionUpdate($field_override->getBaseFieldDefinition(), $field_override);
$entity_type_manager->getStorage($field_override->getTargetEntityTypeId())->onFieldDefinitionUpdate($field_override->getBaseFieldDefinition(), $field_override);
}
}
......
......@@ -9,8 +9,8 @@
* Implements hook_install().
*/
function contact_storage_test_install() {
$entity_manager = \Drupal::entityManager();
$entity_type = $entity_manager->getDefinition('contact_message');
$entity_type_manager = \Drupal::entityTypeManager();
$entity_type = $entity_type_manager->getDefinition('contact_message');
// Recreate the original entity type definition, in order to notify the
// manager of what changed. The change of storage backend will trigger
......@@ -19,5 +19,5 @@ function contact_storage_test_install() {
$original = clone $entity_type;
$original->setStorageClass('Drupal\Core\Entity\ContentEntityNullStorage');
$entity_manager->onEntityTypeUpdate($entity_type, $original);
\Drupal::service('entity_type.listener')->onEntityTypeUpdate($entity_type, $original);
}
......@@ -162,7 +162,7 @@ public function preSave(EntityStorageInterface $storage) {
if ($this->isNew()) {
// Notify the entity storage.
$entity_manager->onFieldDefinitionCreate($this);
\Drupal::service('field_definition.listener')->onFieldDefinitionCreate($this);
}
else {
// Some updates are always disallowed.
......@@ -176,7 +176,7 @@ public function preSave(EntityStorageInterface $storage) {
throw new FieldException("Cannot change an existing field's storage.");
}
// Notify the entity storage.
$entity_manager->onFieldDefinitionUpdate($this, $this->original);
\Drupal::service('field_definition.listener')->onFieldDefinitionUpdate($this, $this->original);
}
parent::preSave($storage);
......@@ -223,12 +223,12 @@ public static function preDelete(EntityStorageInterface $storage, array $fields)
*/
public static function postDelete(EntityStorageInterface $storage, array $fields) {
// Clear the cache upfront, to refresh the results of getBundles().
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
// Notify the entity storage.
foreach ($fields as $field) {
if (!$field->deleted) {
\Drupal::entityManager()->onFieldDefinitionDelete($field);
\Drupal::service('field_definition.listener')->onFieldDefinitionDelete($field);
}
}
......
......@@ -337,7 +337,7 @@ protected function preSaveNew(EntityStorageInterface $storage) {
$this->module = $field_type['provider'];
// Notify the entity manager.
$entity_manager->onFieldStorageDefinitionCreate($this);
\Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionCreate($this);
}
/**
......@@ -366,7 +366,6 @@ public function calculateDependencies() {
*/
protected function preSaveUpdated(EntityStorageInterface $storage) {
$module_handler = \Drupal::moduleHandler();
$entity_manager = \Drupal::entityManager();
// Some updates are always disallowed.
if ($this->getType() != $this->original->getType()) {
......@@ -383,7 +382,7 @@ protected function preSaveUpdated(EntityStorageInterface $storage) {
// Notify the entity manager. A listener can reject the definition
// update as invalid by raising an exception, which stops execution before
// the definition is written to config.
$entity_manager->onFieldStorageDefinitionUpdate($this, $this->original);
\Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionUpdate($this, $this->original);
}
/**
......@@ -436,7 +435,7 @@ public static function postDelete(EntityStorageInterface $storage, array $fields
// Notify the storage.
foreach ($fields as $field) {
if (!$field->deleted) {
\Drupal::entityManager()->onFieldStorageDefinitionDelete($field);
\Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionDelete($field);
$field->deleted = TRUE;
}
}
......
......@@ -88,7 +88,7 @@ function entity_schema_test_entity_bundle_create($entity_type_id, $bundle) {
if ($entity_type_id == 'entity_test' && $bundle == 'custom') {
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($entity_type_id, $bundle);
// Notify the entity storage that we just created a new field.
\Drupal::entityManager()->onFieldDefinitionCreate($field_definitions['custom_bundle_field']);
\Drupal::service('field_definition.listener')->onFieldDefinitionCreate($field_definitions['custom_bundle_field']);
}
}
......@@ -99,7 +99,7 @@ function entity_schema_test_entity_bundle_delete($entity_type_id, $bundle) {
if ($entity_type_id == 'entity_test' && $bundle == 'custom') {
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($entity_type_id, $bundle);
// Notify the entity storage that our field is gone.
\Drupal::entityManager()->onFieldDefinitionDelete($field_definitions['custom_bundle_field']);
\Drupal::entityManager()->onFieldStorageDefinitionDelete($field_definitions['custom_bundle_field']->getFieldStorageDefinition());
\Drupal::service('field_definition.listener')->onFieldDefinitionDelete($field_definitions['custom_bundle_field']);
\Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionDelete($field_definitions['custom_bundle_field']->getFieldStorageDefinition());
}
}
......@@ -192,7 +192,7 @@ function entity_test_create_bundle($bundle, $text = NULL, $entity_type = 'entity
$bundles += [$bundle => ['label' => $text ? $text : $bundle]];
\Drupal::state()->set($entity_type . '.bundles', $bundles);
\Drupal::entityManager()->onBundleCreate($bundle, $entity_type);
\Drupal::service('entity_bundle.listener')->onBundleCreate($bundle, $entity_type);
}
/**
......@@ -209,7 +209,7 @@ function entity_test_delete_bundle($bundle, $entity_type = 'entity_test') {
unset($bundles[$bundle]);
\Drupal::state()->set($entity_type . '.bundles', $bundles);
\Drupal::entityManager()->onBundleDelete($bundle, $entity_type);
\Drupal::service('entity_bundle.listener')->onBundleDelete($bundle, $entity_type);
}
/**
......
......@@ -754,27 +754,27 @@ public function testDefinitionEvents() {
$event_subscriber->enableEventTracking();
// Test field storage definition events.
$storage_definition = current($this->entityManager->getFieldStorageDefinitions('entity_test_rev'));
$storage_definition = current(\Drupal::service('entity_field.manager')->getFieldStorageDefinitions('entity_test_rev'));
$this->assertFalse($event_subscriber->hasEventFired(FieldStorageDefinitionEvents::DELETE), 'Entity type delete was not dispatched yet.');
$this->entityManager->onFieldStorageDefinitionDelete($storage_definition);
\Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionDelete($storage_definition);
$this->assertTrue($event_subscriber->hasEventFired(FieldStorageDefinitionEvents::DELETE), 'Entity type delete event successfully dispatched.');
$this->assertFalse($event_subscriber->hasEventFired(FieldStorageDefinitionEvents::CREATE), 'Entity type create was not dispatched yet.');
$this->entityManager->onFieldStorageDefinitionCreate($storage_definition);
\Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionCreate($storage_definition);
$this->assertTrue($event_subscriber->hasEventFired(FieldStorageDefinitionEvents::CREATE), 'Entity type create event successfully dispatched.');
$this->assertFalse($event_subscriber->hasEventFired(FieldStorageDefinitionEvents::UPDATE), 'Entity type update was not dispatched yet.');
$this->entityManager->onFieldStorageDefinitionUpdate($storage_definition, $storage_definition);
\Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionUpdate($storage_definition, $storage_definition);
$this->assertTrue($event_subscriber->hasEventFired(FieldStorageDefinitionEvents::UPDATE), 'Entity type update event successfully dispatched.');
// Test entity type events.
$entity_type = $this->entityManager->getDefinition('entity_test_rev');
$entity_type = $this->entityTypeManager->getDefinition('entity_test_rev');
$this->assertFalse($event_subscriber->hasEventFired(EntityTypeEvents::CREATE), 'Entity type create was not dispatched yet.');
$this->entityManager->onEntityTypeCreate($entity_type);
\Drupal::service('entity_type.listener')->onEntityTypeCreate($entity_type);
$this->assertTrue($event_subscriber->hasEventFired(EntityTypeEvents::CREATE), 'Entity type create event successfully dispatched.');
$this->assertFalse($event_subscriber->hasEventFired(EntityTypeEvents::UPDATE), 'Entity type update was not dispatched yet.');
$this->entityManager->onEntityTypeUpdate($entity_type, $entity_type);
\Drupal::service('entity_type.listener')->onEntityTypeUpdate($entity_type, $entity_type);
$this->assertTrue($event_subscriber->hasEventFired(EntityTypeEvents::UPDATE), 'Entity type update event successfully dispatched.');
$this->assertFalse($event_subscriber->hasEventFired(EntityTypeEvents::DELETE), 'Entity type delete was not dispatched yet.');
$this->entityManager->onEntityTypeDelete($entity_type);
\Drupal::service('entity_type.listener')->onEntityTypeDelete($entity_type);
$this->assertTrue($event_subscriber->hasEventFired(EntityTypeEvents::DELETE), 'Entity type delete event successfully dispatched.');
}
......
......@@ -35,15 +35,15 @@ protected function setUp() {
public function testCustomFieldCreateDelete() {
// Install the module which adds the field.
$this->installModule('entity_schema_test');
$storage_definitions = $this->entityManager->getFieldStorageDefinitions('entity_test');
$storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions('entity_test');
$this->assertNotNull($storage_definitions['custom_base_field'], 'Base field definition found.');
$this->assertNotNull($storage_definitions['custom_bundle_field'], 'Bundle field definition found.');
// Make sure the field schema can be created.
$this->entityManager->onFieldStorageDefinitionCreate($storage_definitions['custom_base_field']);
$this->entityManager->onFieldStorageDefinitionCreate($storage_definitions['custom_bundle_field']);
\Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionCreate($storage_definitions['custom_base_field']);
\Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionCreate($storage_definitions['custom_bundle_field']);
/** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
$table_mapping = $this->entityManager->getStorage('entity_test')->getTableMapping();
$table_mapping = $this->entityTypeManager->getStorage('entity_test')->getTableMapping();
$base_table = current($table_mapping->getTableNames());
$base_column = current($table_mapping->getColumnNames('custom_base_field'));
$this->assertTrue($this->database->schema()->fieldExists($base_table, $base_column), 'Table column created');
......@@ -51,8 +51,8 @@ public function testCustomFieldCreateDelete() {
$this->assertTrue($this->database->schema()->tableExists($table), 'Table created');
// Make sure the field schema can be deleted.
$this->entityManager->onFieldStorageDefinitionDelete($storage_definitions['custom_base_field']);
$this->entityManager->onFieldStorageDefinitionDelete($storage_definitions['custom_bundle_field']);
\Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionDelete($storage_definitions['custom_base_field']);
\Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionDelete($storage_definitions['custom_bundle_field']);
$this->assertFalse($this->database->schema()->fieldExists($base_table, $base_column), 'Table column dropped');
$this->assertFalse($this->database->schema()->tableExists($table), 'Table dropped');
}
......@@ -69,7 +69,7 @@ protected function updateEntityType($alter) {
$this->entityTypeManager->clearCachedDefinitions();
$this->state->set('entity_schema_update', $alter);
$entity_type = $this->entityManager->getDefinition($entity_test_id);
$this->entityManager->onEntityTypeUpdate($entity_type, $original);
\Drupal::service('entity_type.listener')->onEntityTypeUpdate($entity_type, $original);
}
/**
......@@ -77,9 +77,9 @@ protected function updateEntityType($alter) {
*/
public function testEntitySchemaUpdate() {
$this->installModule('entity_schema_test');
$storage_definitions = $this->entityManager->getFieldStorageDefinitions('entity_test');
$this->entityManager->onFieldStorageDefinitionCreate($storage_definitions['custom_base_field']);
$this->entityManager->onFieldStorageDefinitionCreate($storage_definitions['custom_bundle_field']);
$storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions('entity_test');
\Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionCreate($storage_definitions['custom_base_field']);
\Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionCreate($storage_definitions['custom_bundle_field']);
$schema_handler = $this->database->schema();
$tables = ['entity_test', 'entity_test_revision', 'entity_test_field_data', 'entity_test_field_revision'];
$dedicated_tables = ['entity_test__custom_bundle_field', 'entity_test_revision__custom_bundle_field'];
......
......@@ -735,14 +735,13 @@ protected function installSchema($module, $tables) {
* The ID of the entity type.
*/
protected function installEntitySchema($entity_type_id) {
/** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */
$entity_manager = $this->container->get('entity.manager');
$entity_type = $entity_manager->getDefinition($entity_type_id);
$entity_manager->onEntityTypeCreate($entity_type);
$entity_type_manager = \Drupal::entityTypeManager();
$entity_type = $entity_type_manager->getDefinition($entity_type_id);
\Drupal::service('entity_type.listener')->onEntityTypeCreate($entity_type);
// For test runs, the most common storage backend is a SQL database. For
// this case, ensure the tables got created.
$storage = $entity_manager->getStorage($entity_type_id);
$storage = $entity_type_manager->getStorage($entity_type_id);
if ($storage instanceof SqlEntityStorageInterface) {
$tables = $storage->getTableMapping()->getTableNames();
$db_schema = $this->container->get('database')->schema();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment