From 0fd4bdcb16ca339c06e0eb6a8b30a4b13a810793 Mon Sep 17 00:00:00 2001 From: catch <6915-catch@users.noreply.drupalcode.org> Date: Mon, 29 Jul 2024 20:32:27 +0900 Subject: [PATCH] Issue #3094865 by quietone, _utsavsharma, hchonov, Berdir, smustgrave, catch: Fix references to the deprecated Entity class --- core/core.api.php | 4 ++-- .../Core/Config/Entity/ConfigEntityBase.php | 2 +- .../Drupal/Core/Entity/EntityDisplayModeBase.php | 3 --- .../Drupal/Core/Entity/EntityTypeInterface.php | 2 +- .../Core/Entity/EntityTypeRepositoryInterface.php | 4 ++-- core/lib/Drupal/Core/Entity/entity.api.php | 4 +++- .../EntityReferenceLabelFormatter.php | 9 +++++---- .../Field/FieldFormatter/StringFormatter.php | 2 +- core/modules/block/src/Entity/Block.php | 4 ++-- core/modules/field/src/Entity/FieldConfig.php | 2 +- .../field/src/Entity/FieldStorageConfig.php | 2 +- .../EntityReferenceFormatterTest.php | 4 +--- .../file/tests/src/Functional/FileListingTest.php | 3 +-- .../node/tests/src/Kernel/NodeOwnerTest.php | 2 +- .../EntityResourcePostRouteSubscriber.php | 2 +- .../EntityResource/EntityResourceTestBase.php | 3 ++- .../Normalizer/FieldableEntityNormalizerTrait.php | 3 ++- core/modules/shortcut/src/Entity/Shortcut.php | 6 +++--- core/modules/views/src/EntityViewsData.php | 2 +- .../Drupal/Tests/Core/Entity/EntityLinkTest.php | 2 +- .../Drupal/Tests/Core/Entity/EntityUnitTest.php | 15 ++++++++------- 21 files changed, 40 insertions(+), 40 deletions(-) diff --git a/core/core.api.php b/core/core.api.php index 34e699b36bd8..5bd73fda9501 100644 --- a/core/core.api.php +++ b/core/core.api.php @@ -559,8 +559,8 @@ * the ability to override any of the default behavior if needed. * See \Drupal\Core\Cache\CacheableDependencyInterface::getCacheTags(), * \Drupal\Core\Entity\EntityTypeInterface::getListCacheTags(), - * \Drupal\Core\Entity\Entity::invalidateTagsOnSave() and - * \Drupal\Core\Entity\Entity::invalidateTagsOnDelete(). + * \Drupal\Core\Entity\EntityBase::invalidateTagsOnSave() and + * \Drupal\Core\Entity\EntityBase::invalidateTagsOnDelete(). * * @section context Cache contexts * diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 0c91c17127f5..702e1744dbe0 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -140,7 +140,7 @@ public function setOriginalId($id) { } /** - * Overrides Entity::isNew(). + * Overrides EntityBase::isNew(). * * EntityInterface::enforceIsNew() is only supported for newly created * configuration entities but has no effect after saving, since each diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayModeBase.php b/core/lib/Drupal/Core/Entity/EntityDisplayModeBase.php index 0e21b7f6d49a..1e19838ff6f2 100644 --- a/core/lib/Drupal/Core/Entity/EntityDisplayModeBase.php +++ b/core/lib/Drupal/Core/Entity/EntityDisplayModeBase.php @@ -34,9 +34,6 @@ abstract class EntityDisplayModeBase extends ConfigEntityBase implements EntityD /** * The entity type this form or view mode is used for. * - * This is not to be confused with EntityDisplayModeBase::$entityType which is - * inherited from Entity::$entityType. - * * @var string */ protected $targetEntityType; diff --git a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php index abe043273d3f..7b04a6a5eaa4 100644 --- a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php @@ -424,7 +424,7 @@ public function getPermissionGranularity(); * placeholder of {node_type} used on the Node class. * * Specific entity types may also expand upon this list by overriding the - * Entity::urlRouteParameters() method. + * EntityBase::urlRouteParameters() method. * * @link http://www.iana.org/assignments/link-relations/link-relations.xml @endlink * @link http://tools.ietf.org/html/rfc6570 @endlink diff --git a/core/lib/Drupal/Core/Entity/EntityTypeRepositoryInterface.php b/core/lib/Drupal/Core/Entity/EntityTypeRepositoryInterface.php index 0d05bc967322..8cc7fcce0e7d 100644 --- a/core/lib/Drupal/Core/Entity/EntityTypeRepositoryInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeRepositoryInterface.php @@ -39,8 +39,8 @@ public function getEntityTypeLabels($group = FALSE); * @throws \Drupal\Core\Entity\Exception\NoCorrespondingEntityClassException * Thrown when no entity class corresponds to the called class. * - * @see \Drupal\Core\Entity\Entity::load() - * @see \Drupal\Core\Entity\Entity::loadMultiple() + * @see \Drupal\Core\Entity\EntityBase::load() + * @see \Drupal\Core\Entity\EntityBase::loadMultiple() */ public function getEntityTypeFromClass($class_name); diff --git a/core/lib/Drupal/Core/Entity/entity.api.php b/core/lib/Drupal/Core/Entity/entity.api.php index 4af6932e45f4..09853d9adcac 100644 --- a/core/lib/Drupal/Core/Entity/entity.api.php +++ b/core/lib/Drupal/Core/Entity/entity.api.php @@ -136,7 +136,9 @@ * $entity->save(); * @endcode * There is also a shortcut method on entity classes, which creates an entity - * with an array of provided property values: \Drupal\Core\Entity::create(). + * with an array of provided property values. It is the create method. To create + * an Action entity one would use Drupal\system\Entity\Action::create(). For a + * custom entity use $yourEntityTypeClass::create(). * * Hooks invoked during the create operation: * - hook_ENTITY_TYPE_create() diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php index 3090314a5971..ef033cd46657 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php @@ -69,10 +69,11 @@ public function viewElements(FieldItemListInterface $items, $langcode) { $uri = $entity->toUrl(); } catch (UndefinedLinkTemplateException) { - // This exception is thrown by \Drupal\Core\Entity\Entity::urlInfo() - // and it means that the entity type doesn't have a link template nor - // a valid "uri_callback", so don't bother trying to output a link for - // the rest of the referenced entities. + // This exception is thrown by + // \Drupal\Core\Entity\EntityInterface::toUrl() and it means that the + // entity type doesn't have a link template nor a valid + // "uri_callback", so don't bother trying to output a link for the + // rest of the referenced entities. $output_as_link = FALSE; } } diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php index ca9ac2ddd7e6..32f5c20d6ec1 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php @@ -177,7 +177,7 @@ protected function viewValue(FieldItemInterface $item) { protected function getEntityUrl(EntityInterface $entity) { // For the default revision, the 'revision' link template falls back to // 'canonical'. - // @see \Drupal\Core\Entity\Entity::toUrl() + // @see \Drupal\Core\Entity\EntityBase::toUrl() $rel = $entity->getEntityType()->hasLinkTemplate('revision') ? 'revision' : 'canonical'; return $entity->toUrl($rel); } diff --git a/core/modules/block/src/Entity/Block.php b/core/modules/block/src/Entity/Block.php index bbec5849b999..3bc7da26afcf 100644 --- a/core/modules/block/src/Entity/Block.php +++ b/core/modules/block/src/Entity/Block.php @@ -248,8 +248,8 @@ public function calculateDependencies() { public function postSave(EntityStorageInterface $storage, $update = TRUE) { parent::postSave($storage, $update); - // Entity::postSave() calls Entity::invalidateTagsOnSave(), which only - // handles the regular cases. The Block entity has one special case: a + // EntityBase::postSave() calls EntityBase::invalidateTagsOnSave(), which + // only handles the regular cases. The Block entity has one special case: a // newly created block may *also* appear on any page in the current theme, // so we must invalidate the associated block's cache tag (which includes // the theme cache tag). diff --git a/core/modules/field/src/Entity/FieldConfig.php b/core/modules/field/src/Entity/FieldConfig.php index 5bb7189cad62..09db516b174a 100644 --- a/core/modules/field/src/Entity/FieldConfig.php +++ b/core/modules/field/src/Entity/FieldConfig.php @@ -153,7 +153,7 @@ public function postCreate(EntityStorageInterface $storage) { } /** - * Overrides \Drupal\Core\Entity\Entity::preSave(). + * Overrides \Drupal\Core\Entity\EntityBase::preSave(). * * @throws \Drupal\Core\Field\FieldException * If the field definition is invalid. diff --git a/core/modules/field/src/Entity/FieldStorageConfig.php b/core/modules/field/src/Entity/FieldStorageConfig.php index e5d68f9fced9..c399cd5392ae 100644 --- a/core/modules/field/src/Entity/FieldStorageConfig.php +++ b/core/modules/field/src/Entity/FieldStorageConfig.php @@ -307,7 +307,7 @@ public function postCreate(EntityStorageInterface $storage) { } /** - * Overrides \Drupal\Core\Entity\Entity::preSave(). + * Overrides \Drupal\Core\Entity\EntityBase::preSave(). * * @throws \Drupal\Core\Field\FieldException * If the field definition is invalid. diff --git a/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php index 640b19ae3d50..9f554f110288 100644 --- a/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php +++ b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php @@ -393,9 +393,7 @@ public function testLabelFormatter(): void { $this->assertEquals($this->referencedEntity->label(), $build[0]['#plain_text'], sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter)); $this->assertEquals($this->unsavedReferencedEntity->label(), $build[1]['#plain_text'], sprintf('The markup returned by the %s formatter is correct for an item with a unsaved entity.', $formatter)); - // Test an entity type that doesn't have any link templates, which means - // \Drupal\Core\Entity\EntityInterface::urlInfo() will throw an exception - // and the label formatter will output only the label instead of a link. + // Test an entity type that doesn't have any link templates. $field_storage_config = FieldStorageConfig::loadByName($this->entityType, $this->fieldName); $field_storage_config->setSetting('target_type', 'entity_test_label'); $field_storage_config->save(); diff --git a/core/modules/file/tests/src/Functional/FileListingTest.php b/core/modules/file/tests/src/Functional/FileListingTest.php index 740505df9699..27e33681d194 100644 --- a/core/modules/file/tests/src/Functional/FileListingTest.php +++ b/core/modules/file/tests/src/Functional/FileListingTest.php @@ -250,8 +250,7 @@ public function testFileListingUsageNoLink(): void { $this->drupalGet('admin/content/files/usage/' . $file->id()); $this->assertSession()->statusCodeEquals(200); - // Entity name should be displayed, but not linked if Entity::toUrl - // throws an exception + // Entity name should be displayed. $this->assertSession()->pageTextContains($entity_name); $this->assertSession()->linkNotExists($entity_name, 'Linked entity name not added to file usage listing.'); $this->assertSession()->linkExists($node->getTitle()); diff --git a/core/modules/node/tests/src/Kernel/NodeOwnerTest.php b/core/modules/node/tests/src/Kernel/NodeOwnerTest.php index 9bf8f9d2c963..a00bfbfd9203 100644 --- a/core/modules/node/tests/src/Kernel/NodeOwnerTest.php +++ b/core/modules/node/tests/src/Kernel/NodeOwnerTest.php @@ -73,7 +73,7 @@ public function testOwner(): void { $german->set('uid', ['target_id' => NULL]); $italian->set('uid', ['target_id' => NULL]); - // Entity::save() saves all translations! + // This saves all translations! $italian->save(); $this->assertEquals(0, $english->getOwnerId()); diff --git a/core/modules/rest/src/EventSubscriber/EntityResourcePostRouteSubscriber.php b/core/modules/rest/src/EventSubscriber/EntityResourcePostRouteSubscriber.php index 02a4a14e3d6b..91c6db7d3968 100644 --- a/core/modules/rest/src/EventSubscriber/EntityResourcePostRouteSubscriber.php +++ b/core/modules/rest/src/EventSubscriber/EntityResourcePostRouteSubscriber.php @@ -54,7 +54,7 @@ public function onDynamicRouteEvent(RouteBuildEvent $event) { // Create a route for the 'create' link relation type for this entity // type that uses the same route definition as the REST 'POST' route // which use that entity type. - // @see \Drupal\Core\Entity\Entity::toUrl() + // @see \Drupal\Core\Entity\EntityBase::toUrl() $entity_create_route_name = "entity.$entity_type_id.create"; $route_collection->add($entity_create_route_name, $rest_post_route); } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php index 9ef8b61a4536..b7c3cc936f7a 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php @@ -1235,7 +1235,8 @@ protected function getEntityResourceUrl() { $has_canonical_url = $this->entity->hasLinkTemplate('canonical'); // Note that the 'canonical' link relation type must be specified explicitly // in the call to ::toUrl(). 'canonical' is the default for - // \Drupal\Core\Entity\Entity::toUrl(), but ConfigEntityBase overrides this. + // \Drupal\Core\Entity\EntityBase::toUrl(), but ConfigEntityBase overrides + // this. return $has_canonical_url ? $this->entity->toUrl('canonical') : Url::fromUri('base:entity/' . static::$entityTypeId . '/' . $this->entity->id()); } diff --git a/core/modules/serialization/src/Normalizer/FieldableEntityNormalizerTrait.php b/core/modules/serialization/src/Normalizer/FieldableEntityNormalizerTrait.php index fd90df500096..159324ec1632 100644 --- a/core/modules/serialization/src/Normalizer/FieldableEntityNormalizerTrait.php +++ b/core/modules/serialization/src/Normalizer/FieldableEntityNormalizerTrait.php @@ -201,7 +201,8 @@ protected function getEntityTypeManager() { * The context passed into the Normalizer. * * @return mixed - * The value to use in Entity::setValue(). + * The value to use in \Drupal\Core\Field\FieldItemBase::setValue() or a + * subclass. */ protected function constructValue($data, $context) { $field_item = $context['target_instance']; diff --git a/core/modules/shortcut/src/Entity/Shortcut.php b/core/modules/shortcut/src/Entity/Shortcut.php index 5398c561cf55..3d591b3ada3e 100644 --- a/core/modules/shortcut/src/Entity/Shortcut.php +++ b/core/modules/shortcut/src/Entity/Shortcut.php @@ -99,9 +99,9 @@ public function getUrl() { public function postSave(EntityStorageInterface $storage, $update = TRUE) { parent::postSave($storage, $update); - // Entity::postSave() calls Entity::invalidateTagsOnSave(), which only - // handles the regular cases. The Shortcut entity has one special case: a - // newly created shortcut is *also* added to a shortcut set, so we must + // EntityBase::postSave() calls EntityBase::invalidateTagsOnSave(), which + // only handles the regular cases. The Shortcut entity has one special case: + // a newly created shortcut is *also* added to a shortcut set, so we must // invalidate the associated shortcut set's cache tag. if (!$update) { Cache::invalidateTags($this->getCacheTagsToInvalidate()); diff --git a/core/modules/views/src/EntityViewsData.php b/core/modules/views/src/EntityViewsData.php index 0550fb213eb6..67e30a95cf44 100644 --- a/core/modules/views/src/EntityViewsData.php +++ b/core/modules/views/src/EntityViewsData.php @@ -426,7 +426,7 @@ protected function addEntityLinks(array &$data) { * @param string $field_name * The name of the field to handle. * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition - * The field definition defined in Entity::baseFieldDefinitions() + * The field definition. * @param \Drupal\Core\Entity\Sql\TableMappingInterface $table_mapping * The table mapping information * @param array $table_data diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityLinkTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityLinkTest.php index 6e59c4270887..4299d1a41386 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityLinkTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityLinkTest.php @@ -56,7 +56,7 @@ protected function setUp(): void { } /** - * Tests for the Entity::toLink() method. + * Tests for the EntityBase::toLink() method. * * @covers ::toLink * diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php index 43816924d151..858efd232275 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php @@ -233,7 +233,7 @@ public function testLanguage(): void { */ public function setupTestLoad() { // Base our mocked entity on a real entity class so we can test if calling - // Entity::load() on the base class will bubble up to an actual entity. + // EntityBase::load() on the base class will bubble up to an actual entity. $this->entityTypeId = 'entity_test_mul'; $methods = get_class_methods(EntityTestMul::class); unset($methods[array_search('load', $methods)]); @@ -247,7 +247,7 @@ public function setupTestLoad() { } /** - * Tests Entity::load(). + * Tests EntityBase::load(). * * When called statically on a subclass of Entity. * @@ -277,12 +277,13 @@ public function testLoad(): void { \Drupal::getContainer()->set('entity_type.repository', $entity_type_repository); - // Call Entity::load statically and check that it returns the mock entity. + // Call EntityBase::load statically and check that it returns the mock + // entity. $this->assertSame($this->entity, $class_name::load(1)); } /** - * Tests Entity::loadMultiple(). + * Tests EntityBase::loadMultiple(). * * When called statically on a subclass of Entity. * @@ -312,8 +313,8 @@ public function testLoadMultiple(): void { \Drupal::getContainer()->set('entity_type.repository', $entity_type_repository); - // Call Entity::loadMultiple statically and check that it returns the mock - // entity. + // Call EntityBase::loadMultiple() statically and check that it returns the + // mock entity. $this->assertSame([1 => $this->entity], $class_name::loadMultiple([1])); } @@ -344,7 +345,7 @@ public function testCreate(): void { \Drupal::getContainer()->set('entity_type.repository', $entity_type_repository); - // Call Entity::create() statically and check that it returns the mock + // Call EntityBase::create() statically and check that it returns the mock // entity. $this->assertSame($this->entity, $class_name::create([])); } -- GitLab