Commit 9ed3a5d1 authored by Berdir's avatar Berdir Committed by Berdir

Issue #3042589 by amarphule, Berdir, Sergiu Stici: Drupal 9 Deprecated Code Report

parent cc2494e1
......@@ -43,7 +43,7 @@ function entity_reference_revisions_field_views_data(FieldStorageConfigInterface
// Provide a reverse relationship for the entity type that is referenced by
// the field.
$args['@entity'] = $entity_type->getLabel();
$args['@label'] = $target_entity_type->getLowercaseLabel();
$args['@label'] = $target_entity_type->getSingularLabel();
$pseudo_field_name = 'reverse__' . $entity_type_id . '__' . $field_name;
/** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
$table_mapping = $entity_manager->getStorage($entity_type_id)->getTableMapping();
......
......@@ -423,8 +423,8 @@ class EntityReferenceRevisionsItem extends EntityReferenceItem implements Option
*/
public static function onDependencyRemoval(FieldDefinitionInterface $field_definition, array $dependencies) {
$changed = FALSE;
$entity_manager = \Drupal::entityManager();
$target_entity_type = $entity_manager->getDefinition($field_definition->getFieldStorageDefinition()
$entity_type_manager = \Drupal::entityTypeManager();
$target_entity_type = $entity_type_manager->getDefinition($field_definition->getFieldStorageDefinition()
->getSetting('target_type'));
$handler_settings = $field_definition->getSetting('handler_settings');
......@@ -432,7 +432,7 @@ class EntityReferenceRevisionsItem extends EntityReferenceItem implements Option
// has been removed.
if (!empty($handler_settings['target_bundles'])) {
if ($bundle_entity_type_id = $target_entity_type->getBundleEntityType()) {
if ($storage = $entity_manager->getStorage($bundle_entity_type_id)) {
if ($storage = $entity_type_manager->getStorage($bundle_entity_type_id)) {
foreach ($storage->loadMultiple($handler_settings['target_bundles']) as $bundle) {
if (isset($dependencies[$bundle->getConfigDependencyKey()][$bundle->getConfigDependencyName()])) {
unset($handler_settings['target_bundles'][$bundle->id()]);
......
......@@ -2,7 +2,6 @@
namespace Drupal\entity_reference_revisions\Plugin\Field\FieldWidget;
use Drupal\Core\Entity\Entity;
use Drupal\Core\Field\Plugin\Field\FieldWidget\EntityReferenceAutocompleteWidget;
use Drupal\Core\Form\FormStateInterface;
......
......@@ -2,7 +2,7 @@
namespace Drupal\entity_reference_revisions\Plugin\migrate\destination;
use Drupal\Component\Plugin\ConfigurablePluginInterface;
use Drupal\Component\Plugin\ConfigurableInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\TypedData\TranslatableInterface;
use Drupal\migrate\MigrateException;
......@@ -23,7 +23,7 @@ use Drupal\migrate\Row;
* deriver = "Drupal\entity_reference_revisions\Plugin\Derivative\MigrateEntityReferenceRevisions"
* )
*/
class EntityReferenceRevisions extends EntityRevision implements ConfigurablePluginInterface {
class EntityReferenceRevisions extends EntityRevision implements ConfigurableInterface {
/**
* {@inheritdoc}
......
......@@ -2,6 +2,7 @@
namespace Drupal\entity_reference_revisions\Plugin\views\display;
use Drupal\Core\Database\Query\Condition;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
/**
......@@ -123,13 +124,13 @@ class EntityReferenceRevisions extends DisplayPluginBase {
// Restrict the autocomplete options based on what's been typed already.
if (isset($options['match'])) {
$style_options = $this->getOption('style');
$value = db_like($options['match']) . '%';
$value = \Drupal::database()->escapeLike($options['match']) . '%';
if ($options['match_operator'] != 'STARTS_WITH') {
$value = '%' . $value;
}
// Multiple search fields are OR'd together.
$conditions = db_or();
$conditions = new Condition('OR');
// Build the condition using the selected search fields.
foreach ($style_options['options']['search_fields'] as $field_alias) {
......
......@@ -122,40 +122,40 @@ class EntityReferenceRevisionsCompositeTest extends EntityKernelTestBase {
// Assert that there is only 1 revision when creating a node.
$node_revisions_count = \Drupal::entityQuery('node')->condition('nid', $node->id())->allRevisions()->count()->execute();
$this->assertEqual($node_revisions_count, 1);
$this->assertEquals(1, $node_revisions_count);
// Assert there is no new composite revision after creating a host entity.
$composite_revisions_count = \Drupal::entityQuery('entity_test_composite')->condition('uuid', $composite->uuid())->allRevisions()->count()->execute();
$this->assertEquals(1, $composite_revisions_count);
// Verify the value of parent type and id after create a node.
$composite = EntityTestCompositeRelationship::load($composite->id());
$this->assertEqual($composite->parent_type->value, $node->getEntityTypeId());
$this->assertEqual($composite->parent_id->value, $node->id());
$this->assertEqual($composite->parent_field_name->value, 'composite_reference');
$this->assertEquals($node->getEntityTypeId(), $composite->parent_type->value);
$this->assertEquals($node->id(), $composite->parent_id->value);
$this->assertEquals('composite_reference', $composite->parent_field_name->value);
// Create second revision of the node.
$original_composite_revision = $node->composite_reference[0]->target_revision_id;
$original_node_revision = $node->getRevisionId();
$node->setTitle('2nd revision');
$node->setNewRevision();
$node->save();
$node = node_load($node->id(), TRUE);
$node = Node::load($node->id());
// Check the revision of the node.
$this->assertEqual('2nd revision', $node->getTitle(), 'New node revision has changed data.');
$this->assertNotEqual($original_composite_revision, $node->composite_reference[0]->target_revision_id, 'Composite entity got new revision when its host did.');
$this->assertEquals('2nd revision', $node->getTitle(), 'New node revision has changed data.');
$this->assertNotEquals($original_composite_revision, $node->composite_reference[0]->target_revision_id, 'Composite entity got new revision when its host did.');
// Make sure that there are only 2 revisions.
$node_revisions_count = \Drupal::entityQuery('node')->condition('nid', $node->id())->allRevisions()->count()->execute();
$this->assertEqual($node_revisions_count, 2);
$this->assertEquals(2,$node_revisions_count);
// Revert to first revision of the node.
$node = $this->entityTypeManager->getStorage('node')->loadRevision($original_node_revision);
$node->setNewRevision();
$node->isDefaultRevision(TRUE);
$node->save();
$node = node_load($node->id(), TRUE);
$node = Node::load($node->id());
// Check the revision of the node.
$this->assertNotEqual('2nd revision', $node->getTitle(), 'Node did not keep changed title after reversion.');
$this->assertNotEqual($original_composite_revision, $node->composite_reference[0]->target_revision_id, 'Composite entity got new revision when its host reverted to an old revision.');
$this->assertNotEquals('2nd revision', $node->getTitle(), 'Node did not keep changed title after reversion.');
$this->assertNotEquals($original_composite_revision, $node->composite_reference[0]->target_revision_id, 'Composite entity got new revision when its host reverted to an old revision.');
$node_storage = $this->entityTypeManager->getStorage('node');
// Test that removing composite references results in translation changes.
......@@ -249,9 +249,9 @@ class EntityReferenceRevisionsCompositeTest extends EntityKernelTestBase {
// Verify the value of parent type and id after create a node.
$composite = EntityTestCompositeRelationship::load($composite->id());
$this->assertEqual($composite->parent_type->value, $node->getEntityTypeId());
$this->assertEqual($composite->parent_id->value, $node->id());
$this->assertEqual($composite->parent_field_name->value, 'composite_reference');
$this->assertEquals($node->getEntityTypeId(), $composite->parent_type->value);
$this->assertEquals($node->id(), $composite->parent_id->value);
$this->assertEquals('composite_reference', $composite->parent_field_name->value);
$this->assertTrue($composite->hasTranslation('de'));
// Test that the composite entity is not deleted when the german translation
......@@ -305,9 +305,9 @@ class EntityReferenceRevisionsCompositeTest extends EntityKernelTestBase {
// Verify the value of parent type and id after create a node.
$composite = EntityTestCompositeRelationship::load($composite->id());
$this->assertEqual($composite->parent_type->value, $node->getEntityTypeId());
$this->assertEqual($composite->parent_id->value, $node->id());
$this->assertEqual($composite->parent_field_name->value, 'composite_reference');
$this->assertEquals($node->getEntityTypeId(), $composite->parent_type->value);
$this->assertEquals($node->id(), $composite->parent_id->value);
$this->assertEquals('composite_reference', $composite->parent_field_name->value);
// Test that the composite entity is not deleted when the German parent
// translation is removed.
......@@ -349,15 +349,15 @@ class EntityReferenceRevisionsCompositeTest extends EntityKernelTestBase {
$composite = EntityTestCompositeRelationship::load($composite->id());
$composite_original_revision_id = $composite->getRevisionId();
$node_original_revision_id = $node->getRevisionId();
$this->assertEqual($composite->parent_type->value, $node->getEntityTypeId());
$this->assertEqual($composite->parent_id->value, $node->id());
$this->assertEqual($composite->parent_field_name->value, 'composite_reference');
$this->assertEquals($node->getEntityTypeId(), $composite->parent_type->value);
$this->assertEquals($node->id(), $composite->parent_id->value);
$this->assertEquals('composite_reference', $composite->parent_field_name->value);
$node->setNewRevision(TRUE);
$node->save();
// Ensure that we saved a new revision ID.
$composite = EntityTestCompositeRelationship::load($composite->id());
$this->assertNotEqual($composite->getRevisionId(), $composite_original_revision_id);
$this->assertNotEquals($composite_original_revision_id, $composite->getRevisionId());
// Test that deleting the first revision does not delete the composite.
$this->entityTypeManager->getStorage('node')->deleteRevision($node_original_revision_id);
......
......@@ -8,7 +8,7 @@ use Drupal\field\Entity\FieldStorageConfig;
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\simpletest\UserCreationTrait;
use Drupal\Tests\user\Traits\UserCreationTrait;
/**
* @coversDefaultClass \Drupal\entity_reference_revisions\Plugin\Field\FieldFormatter\EntityReferenceRevisionsEntityFormatter
......
......@@ -4,7 +4,6 @@ namespace Drupal\Tests\entity_reference_revisions\Kernel\Plugin\Derivative;
use Drupal\entity_reference_revisions\Plugin\migrate\destination\EntityReferenceRevisions;
use Drupal\KernelTests\KernelTestBase;
use Drupal\migrate\Plugin\MigrationPluginManager;
use Drupal\migrate\Plugin\MigrateDestinationPluginManager;
/**
......
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