diff --git a/core/lib/Drupal/Core/Entity/ContentEntityForm.php b/core/lib/Drupal/Core/Entity/ContentEntityForm.php index 5420175..bc9331a 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityForm.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityForm.php @@ -282,7 +282,7 @@ public function updateFormLangcode($entity_type_id, EntityInterface $entity, arr * The entity updated with the submitted values. */ public function updateChangedTime(EntityInterface $entity) { - if ($entity->getEntityType()->isSubclassOf(EntityChangedInterface::class)) { + if ($entity instanceof EntityChangedInterface) { $entity->setChangedTime(REQUEST_TIME); } } diff --git a/core/lib/Drupal/Core/Entity/Controller/EntityController.php b/core/lib/Drupal/Core/Entity/Controller/EntityController.php index ebee7cc..af0c705 100644 --- a/core/lib/Drupal/Core/Entity/Controller/EntityController.php +++ b/core/lib/Drupal/Core/Entity/Controller/EntityController.php @@ -2,6 +2,7 @@ namespace Drupal\Core\Entity\Controller; +use Drupal\Core\Entity\EntityDescriptionInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityRepositoryInterface; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; @@ -307,7 +308,7 @@ protected function doGetEntity(RouteMatchInterface $route_match, EntityInterface * The expanded array of bundle information. */ protected function loadBundleDescriptions(array $bundles, EntityTypeInterface $bundle_entity_type) { - if (!$bundle_entity_type->isSubclassOf('\Drupal\Core\Entity\EntityDescriptionInterface')) { + if (!is_subclass_of($bundle_entity_type->getClass(), EntityDescriptionInterface::class)) { return $bundles; } $bundle_names = array_keys($bundles); diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php index 4de891a..c680787 100644 --- a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php @@ -122,7 +122,7 @@ public function __construct(array $values, $entity_type) { throw new \InvalidArgumentException('Missing required properties for an EntityDisplay entity.'); } - if (!$this->entityManager()->getDefinition($values['targetEntityType'])->isSubclassOf('\Drupal\Core\Entity\FieldableEntityInterface')) { + if (!is_subclass_of($this->entityManager()->getDefinition($values['targetEntityType'])->getClass(), FieldableEntityInterface::class)) { throw new \InvalidArgumentException('EntityDisplay entities can only handle fieldable entity types.'); } diff --git a/core/lib/Drupal/Core/Entity/EntityFieldManager.php b/core/lib/Drupal/Core/Entity/EntityFieldManager.php index 5337288..2677c7e 100644 --- a/core/lib/Drupal/Core/Entity/EntityFieldManager.php +++ b/core/lib/Drupal/Core/Entity/EntityFieldManager.php @@ -195,7 +195,7 @@ protected function buildBaseFieldDefinitions($entity_type_id) { $keys = array_filter($entity_type->getKeys()); // Fail with an exception for non-fieldable entity types. - if (!$entity_type->isSubclassOf(FieldableEntityInterface::class)) { + if (!is_subclass_of($class, FieldableEntityInterface::class)) { throw new \LogicException("Getting the base fields is not supported for entity type {$entity_type->getLabel()}."); } @@ -435,7 +435,7 @@ public function getFieldMap() { // bundles, and we do not expect to have so many different entity // types for this to become a bottleneck. foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { - if ($entity_type->isSubclassOf(FieldableEntityInterface::class)) { + if (is_subclass_of($entity_type->getClass(), FieldableEntityInterface::class)) { $bundles = array_keys($this->entityTypeBundleInfo->getBundleInfo($entity_type_id)); foreach ($this->getBaseFieldDefinitions($entity_type_id) as $field_name => $base_field_definition) { $this->fieldMap[$entity_type_id][$field_name] = [ diff --git a/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php index a63415b..09767fb 100644 --- a/core/lib/Drupal/Core/Entity/EntityType.php +++ b/core/lib/Drupal/Core/Entity/EntityType.php @@ -301,7 +301,7 @@ public function __construct($definition) { // Automatically add the EntityChanged constraint if the entity type tracks // the changed time. - if ($this->isSubclassOf('Drupal\Core\Entity\EntityChangedInterface') ) { + if (is_subclass_of($this->getClass(), EntityChangedInterface::class)) { $this->addConstraint('EntityChanged'); } diff --git a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php index 398347f..ed0b0da 100644 --- a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php @@ -359,6 +359,9 @@ public function setAccessClass($class); * * @return bool * TRUE if the entity type is a subclass of the class or interface. + * + * @deprecated in Drupal 8.2.x-dev and will be removed before Drupal 9.0.0. + * Use is_subclass_of() instead. */ public function isSubclassOf($class); diff --git a/core/lib/Drupal/Core/Entity/EntityTypeListener.php b/core/lib/Drupal/Core/Entity/EntityTypeListener.php index 91c156d..9468f2b 100644 --- a/core/lib/Drupal/Core/Entity/EntityTypeListener.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeListener.php @@ -74,7 +74,7 @@ public function onEntityTypeCreate(EntityTypeInterface $entity_type) { $this->eventDispatcher->dispatch(EntityTypeEvents::CREATE, new EntityTypeEvent($entity_type)); $this->entityLastInstalledSchemaRepository->setLastInstalledDefinition($entity_type); - if ($entity_type->isSubclassOf(FieldableEntityInterface::class)) { + if (is_subclass_of($entity_type->getClass(), FieldableEntityInterface::class)) { $this->entityLastInstalledSchemaRepository->setLastInstalledFieldStorageDefinitions($entity_type_id, $this->entityFieldManager->getFieldStorageDefinitions($entity_type_id)); } } diff --git a/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php index 9565e77..437ef5a 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php +++ b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php @@ -7,6 +7,7 @@ use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityReferenceSelection\SelectionWithAutocreateInterface; +use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem; use Drupal\Core\Form\FormStateInterface; @@ -157,7 +158,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta ); } - if ($entity_type->isSubclassOf('\Drupal\Core\Entity\FieldableEntityInterface')) { + if (is_subclass_of($entity_type->getClass(), FieldableEntityInterface::class)) { $fields = array(); foreach (array_keys($bundles) as $bundle) { $bundle_fields = array_filter($this->entityManager->getFieldDefinitions($entity_type_id, $bundle), function ($field_definition) { diff --git a/core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php b/core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php index b1f6abd..165e06b 100644 --- a/core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php +++ b/core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php @@ -309,7 +309,7 @@ protected function getDeleteFormRoute(EntityTypeInterface $entity_type) { * type does not support fields. */ protected function getEntityTypeIdKeyType(EntityTypeInterface $entity_type) { - if (!$entity_type->isSubclassOf(FieldableEntityInterface::class)) { + if (!is_subclass_of($entity_type->getClass(), FieldableEntityInterface::class)) { return NULL; } diff --git a/core/lib/Drupal/Core/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php index a903b8a..52b9af0 100644 --- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php @@ -218,7 +218,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) { if ($entity_type->getProvider() == $module) { $update_manager->installEntityType($entity_type); } - elseif ($entity_type->isSubclassOf(FieldableEntityInterface::CLASS)) { + elseif (is_subclass_of($entity_type->getClass(), FieldableEntityInterface::class)) { // The module being installed may be adding new fields to existing // entity types. Field definitions for any entity type defined by // the module are handled in the if branch. @@ -403,7 +403,7 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) { if ($entity_type->getProvider() == $module) { $update_manager->uninstallEntityType($entity_type); } - elseif ($entity_type->isSubclassOf(FieldableEntityInterface::CLASS)) { + elseif (is_subclass_of($entity_type->getClass(), FieldableEntityInterface::class)) { // The module being installed may be adding new fields to existing // entity types. Field definitions for any entity type defined by // the module are handled in the if branch. diff --git a/core/lib/Drupal/Core/Field/FieldModuleUninstallValidator.php b/core/lib/Drupal/Core/Field/FieldModuleUninstallValidator.php index d1adaa9..888160a 100644 --- a/core/lib/Drupal/Core/Field/FieldModuleUninstallValidator.php +++ b/core/lib/Drupal/Core/Field/FieldModuleUninstallValidator.php @@ -3,6 +3,7 @@ namespace Drupal\Core\Field; use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\FieldableEntityStorageInterface; use Drupal\Core\Extension\ModuleUninstallValidatorInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; @@ -43,7 +44,7 @@ public function validate($module_name) { // We skip entity types defined by the module as there must be no // content to be able to uninstall them anyway. // See \Drupal\Core\Entity\ContentUninstallValidator. - if ($entity_type->getProvider() != $module_name && $entity_type->isSubclassOf('\Drupal\Core\Entity\FieldableEntityInterface')) { + if ($entity_type->getProvider() != $module_name && is_subclass_of($entity_type->getClass(), FieldableEntityInterface::class)) { foreach ($this->entityManager->getFieldStorageDefinitions($entity_type_id) as $storage_definition) { if ($storage_definition->getProvider() == $module_name) { $storage = $this->entityManager->getStorage($entity_type_id); diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php index e8832f3..7eb2490 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php @@ -6,6 +6,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\TypedData\EntityDataDefinition; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemBase; @@ -66,7 +67,7 @@ public static function propertyDefinitions(FieldStorageDefinitionInterface $fiel $target_type_info = \Drupal::entityManager()->getDefinition($settings['target_type']); $target_id_data_type = 'string'; - if ($target_type_info->isSubclassOf('\Drupal\Core\Entity\FieldableEntityInterface')) { + if (is_subclass_of($target_type_info->getClass(), FieldableEntityInterface::class)) { $id_definition = \Drupal::entityManager()->getBaseFieldDefinitions($settings['target_type'])[$target_type_info->getKey('id')]; if ($id_definition->getType() === 'integer') { $target_id_data_type = 'integer'; @@ -114,7 +115,7 @@ public static function schema(FieldStorageDefinitionInterface $field_definition) $target_type = $field_definition->getSetting('target_type'); $target_type_info = \Drupal::entityManager()->getDefinition($target_type); $properties = static::propertyDefinitions($field_definition)['target_id']; - if ($target_type_info->isSubclassOf('\Drupal\Core\Entity\FieldableEntityInterface') && $properties->getDataType() === 'integer') { + if (is_subclass_of($target_type_info->getClass(), FieldableEntityInterface::class) && $properties->getDataType() === 'integer') { $columns = array( 'target_id' => array( 'description' => 'The ID of the target entity.', diff --git a/core/lib/Drupal/Core/ParamConverter/AdminPathConfigEntityConverter.php b/core/lib/Drupal/Core/ParamConverter/AdminPathConfigEntityConverter.php index 9420e8d..515a9e2 100644 --- a/core/lib/Drupal/Core/ParamConverter/AdminPathConfigEntityConverter.php +++ b/core/lib/Drupal/Core/ParamConverter/AdminPathConfigEntityConverter.php @@ -2,6 +2,7 @@ namespace Drupal\Core\ParamConverter; +use Drupal\Core\Config\Entity\ConfigEntityTypeInterface; use Drupal\Core\Routing\AdminContext; use Symfony\Component\Routing\Route; use Drupal\Core\Config\ConfigFactoryInterface; @@ -65,7 +66,7 @@ public function convert($value, $definition, $name, array $defaults) { // entity types will have performed this check in self::applies(). if (strpos($definition['type'], 'entity:{') === 0) { $entity_type = $this->entityManager->getDefinition($entity_type_id); - if (!$entity_type->isSubclassOf('\Drupal\Core\Config\Entity\ConfigEntityInterface')) { + if (!$entity_type instanceof ConfigEntityTypeInterface) { return parent::convert($value, $definition, $name, $defaults); } } @@ -93,7 +94,7 @@ public function applies($definition, $name, Route $route) { // As we only want to override EntityConverter for ConfigEntities, find // out whether the current entity is a ConfigEntity. $entity_type = $this->entityManager->getDefinition($entity_type_id); - if ($entity_type->isSubclassOf('\Drupal\Core\Config\Entity\ConfigEntityInterface')) { + if ($entity_type instanceof ConfigEntityTypeInterface) { return $this->adminContext->isAdminRoute($route); } } diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 40b4e40..e9aa5c5 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -340,7 +340,7 @@ function comment_form_field_storage_config_edit_form_alter(&$form, FormStateInte */ function comment_entity_storage_load($entities, $entity_type) { // Comments can only be attached to content entities, so skip others. - if (!\Drupal::entityManager()->getDefinition($entity_type)->isSubclassOf('Drupal\Core\Entity\FieldableEntityInterface')) { + if (!is_subclass_of(\Drupal::entityManager()->getDefinition($entity_type)->getClass(), FieldableEntityInterface::class)) { return; } // @todo Investigate in https://www.drupal.org/node/2527866 why we need that. diff --git a/core/modules/comment/comment.views.inc b/core/modules/comment/comment.views.inc index 5e31876..94d9afa 100644 --- a/core/modules/comment/comment.views.inc +++ b/core/modules/comment/comment.views.inc @@ -5,6 +5,8 @@ * Provide views data for comment.module. */ +use Drupal\Core\Entity\FieldableEntityInterface; + /** * Implements hook_views_data_alter(). */ @@ -20,16 +22,15 @@ function comment_views_data_alter(&$data) { ), ); - // Provide a integration for each entity type except comment. + // Provide a integration for each entity type with fields except comment. foreach (\Drupal::entityManager()->getDefinitions() as $entity_type_id => $entity_type) { - if ($entity_type_id == 'comment' || !$entity_type->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface') || !$entity_type->getBaseTable()) { + if ($entity_type_id == 'comment' || !is_subclass_of($entity_type->getClass(), FieldableEntityInterface::class) || !$entity_type->getBaseTable()) { continue; } - $fields = \Drupal::service('comment.manager')->getFields($entity_type_id); - $base_table = $entity_type->getDataTable() ?: $entity_type->getBaseTable(); - $args = array('@entity_type' => $entity_type_id); - if ($fields) { + if ($fields = \Drupal::service('comment.manager')->getFields($entity_type_id)) { + $base_table = $entity_type->getDataTable() ?: $entity_type->getBaseTable(); + $args = array('@entity_type' => $entity_type_id); $data[$base_table]['comments_link'] = array( 'field' => array( 'title' => t('Add comment link'), diff --git a/core/modules/comment/src/CommentManager.php b/core/modules/comment/src/CommentManager.php index fcec230..9740753 100644 --- a/core/modules/comment/src/CommentManager.php +++ b/core/modules/comment/src/CommentManager.php @@ -6,6 +6,7 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Routing\UrlGeneratorInterface; @@ -99,7 +100,8 @@ public function __construct(EntityManagerInterface $entity_manager, QueryFactory */ public function getFields($entity_type_id) { $entity_type = $this->entityManager->getDefinition($entity_type_id); - if (!$entity_type->isSubclassOf('\Drupal\Core\Entity\FieldableEntityInterface')) { + if (!is_subclass_of($entity_type->getClass(), FieldableEntityInterface::class)) { + // Early return, comments can only be attached to entities with fields. return array(); } diff --git a/core/modules/comment/src/CommentViewsData.php b/core/modules/comment/src/CommentViewsData.php index 2d9b021..63fa448 100644 --- a/core/modules/comment/src/CommentViewsData.php +++ b/core/modules/comment/src/CommentViewsData.php @@ -2,6 +2,7 @@ namespace Drupal\comment; +use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\views\EntityViewsData; /** @@ -182,9 +183,9 @@ public function getViewsData() { $entities_types = \Drupal::entityManager()->getDefinitions(); - // Provide a relationship for each entity type except comment. + // Provide a relationship for each entity type with fields except comment. foreach ($entities_types as $type => $entity_type) { - if ($type == 'comment' || !$entity_type->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface') || !$entity_type->getBaseTable()) { + if ($type == 'comment' || !is_subclass_of($entity_type->getClass(), FieldableEntityInterface::class) || !$entity_type->getBaseTable()) { continue; } if ($fields = \Drupal::service('comment.manager')->getFields($type)) { @@ -224,9 +225,9 @@ public function getViewsData() { // will go into this field by default. $data['comment_entity_statistics']['table']['group'] = $this->t('Comment Statistics'); - // Provide a relationship for each entity type except comment. + // Provide a relationship for each entity type with fields except comment. foreach ($entities_types as $type => $entity_type) { - if ($type == 'comment' || !$entity_type->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface') || !$entity_type->getBaseTable()) { + if ($type == 'comment' || !is_subclass_of($entity_type->getClass(), FieldableEntityInterface::class) || !$entity_type->getBaseTable()) { continue; } // This relationship does not use the 'field id' column, if the entity has diff --git a/core/modules/comment/tests/src/Unit/CommentManagerTest.php b/core/modules/comment/tests/src/Unit/CommentManagerTest.php index 7fe1c16..234c459 100644 --- a/core/modules/comment/tests/src/Unit/CommentManagerTest.php +++ b/core/modules/comment/tests/src/Unit/CommentManagerTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\comment\Unit; use Drupal\comment\CommentManager; +use Drupal\node\Entity\Node; use Drupal\Tests\UnitTestCase; /** @@ -21,11 +22,7 @@ public function testGetFields() { $entity_type = $this->getMock('Drupal\Core\Entity\ContentEntityTypeInterface'); $entity_type->expects($this->any()) ->method('getClass') - ->will($this->returnValue('Node')); - $entity_type->expects($this->any()) - ->method('isSubclassOf') - ->with('\Drupal\Core\Entity\FieldableEntityInterface') - ->will($this->returnValue(TRUE)); + ->will($this->returnValue(Node::class)); $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface'); diff --git a/core/modules/config/src/Form/ConfigSingleExportForm.php b/core/modules/config/src/Form/ConfigSingleExportForm.php index b6bc0e7..2af639a 100644 --- a/core/modules/config/src/Form/ConfigSingleExportForm.php +++ b/core/modules/config/src/Form/ConfigSingleExportForm.php @@ -3,6 +3,7 @@ namespace Drupal\config\Form; use Drupal\Component\Serialization\Yaml; +use Drupal\Core\Config\Entity\ConfigEntityTypeInterface; use Drupal\Core\Config\StorageInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityTypeInterface; @@ -73,7 +74,7 @@ public function getFormId() { */ public function buildForm(array $form, FormStateInterface $form_state, $config_type = NULL, $config_name = NULL) { foreach ($this->entityManager->getDefinitions() as $entity_type => $definition) { - if ($definition->isSubclassOf('Drupal\Core\Config\Entity\ConfigEntityInterface')) { + if ($definition instanceof ConfigEntityTypeInterface) { $this->definitions[$entity_type] = $definition; } } diff --git a/core/modules/config/src/Form/ConfigSingleImportForm.php b/core/modules/config/src/Form/ConfigSingleImportForm.php index 09bc6f2..f5272e4 100644 --- a/core/modules/config/src/Form/ConfigSingleImportForm.php +++ b/core/modules/config/src/Form/ConfigSingleImportForm.php @@ -9,6 +9,7 @@ use Drupal\Core\Config\ConfigImporterException; use Drupal\Core\Config\ConfigManagerInterface; use Drupal\Core\Config\StorageComparer; +use Drupal\Core\Config\Entity\ConfigEntityTypeInterface; use Drupal\Core\Config\StorageInterface; use Drupal\Core\Config\TypedConfigManagerInterface; use Drupal\Core\Entity\EntityManagerInterface; @@ -221,7 +222,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $entity_types = array(); foreach ($this->entityManager->getDefinitions() as $entity_type => $definition) { - if ($definition->isSubclassOf('Drupal\Core\Config\Entity\ConfigEntityInterface')) { + if ($definition instanceof ConfigEntityTypeInterface) { $entity_types[$entity_type] = $definition->getLabel(); } } diff --git a/core/modules/config_translation/config_translation.module b/core/modules/config_translation/config_translation.module index 9f0803d..73105c0 100644 --- a/core/modules/config_translation/config_translation.module +++ b/core/modules/config_translation/config_translation.module @@ -5,6 +5,7 @@ * Configuration Translation module. */ +use Drupal\Core\Config\Entity\ConfigEntityTypeInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\field\FieldConfigInterface; @@ -75,7 +76,7 @@ function config_translation_themes_uninstalled() { function config_translation_entity_type_alter(array &$entity_types) { /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ foreach ($entity_types as $entity_type_id => $entity_type) { - if ($entity_type->isSubclassOf('Drupal\Core\Config\Entity\ConfigEntityInterface')) { + if ($entity_type instanceof ConfigEntityTypeInterface) { if ($entity_type_id == 'block') { $class = 'Drupal\config_translation\Controller\ConfigTranslationBlockListBuilder'; } @@ -125,7 +126,7 @@ function config_translation_config_translation_info(&$info) { // Determine base path for entities automatically if provided via the // configuration entity. if ( - !$entity_type->isSubclassOf('Drupal\Core\Config\Entity\ConfigEntityInterface') || + !$entity_type instanceof ConfigEntityTypeInterface || !$entity_type->hasLinkTemplate('edit-form') ) { // Do not record this entity mapper if the entity type does not @@ -154,7 +155,7 @@ function config_translation_config_translation_info(&$info) { function config_translation_entity_operation(EntityInterface $entity) { $operations = array(); $entity_type = $entity->getEntityType(); - if ($entity_type->isSubclassOf('Drupal\Core\Config\Entity\ConfigEntityInterface') && + if ($entity_type instanceof ConfigEntityTypeInterface && $entity->hasLinkTemplate('config-translation-overview') && \Drupal::currentUser()->hasPermission('translate configuration')) { diff --git a/core/modules/content_translation/src/ContentTranslationHandler.php b/core/modules/content_translation/src/ContentTranslationHandler.php index 38d643b..bf00e66 100644 --- a/core/modules/content_translation/src/ContentTranslationHandler.php +++ b/core/modules/content_translation/src/ContentTranslationHandler.php @@ -4,6 +4,7 @@ use Drupal\Core\Access\AccessResult; use Drupal\Core\DependencyInjection\DependencySerializationTrait; +use Drupal\Core\Entity\EntityChangedInterface; use Drupal\Core\Entity\EntityHandlerInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; @@ -15,6 +16,7 @@ use Drupal\Core\Render\Element; use Drupal\Core\Session\AccountInterface; use Drupal\user\Entity\User; +use Drupal\user\EntityOwnerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -174,7 +176,7 @@ protected function hasAuthor() { // EntityOwnerInterface. This helps to exclude cases, where the uid is // defined as field name, but is not meant to be an owner field; for // instance, the User entity. - return $this->entityType->isSubclassOf('\Drupal\user\EntityOwnerInterface') && $this->checkFieldStorageDefinitionTranslatability('uid'); + return is_subclass_of($this->entityType->getClass(), EntityOwnerInterface::class) && $this->checkFieldStorageDefinitionTranslatability('uid'); } /** @@ -194,7 +196,7 @@ protected function hasPublishedStatus() { * TRUE if metadata is natively supported, FALSE otherwise. */ protected function hasChangedTime() { - return $this->entityType->isSubclassOf('Drupal\Core\Entity\EntityChangedInterface') && $this->checkFieldStorageDefinitionTranslatability('changed'); + return is_subclass_of($this->entityType->getClass(), EntityChangedInterface::class) && $this->checkFieldStorageDefinitionTranslatability('changed'); } /** diff --git a/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php b/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php index e9fff8d..c3b0e16 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php @@ -3,6 +3,7 @@ namespace Drupal\content_translation\Tests; use Drupal\Core\Cache\Cache; +use Drupal\Core\Entity\EntityChangedInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageInterface; @@ -553,7 +554,7 @@ protected function doTestTranslationChanged() { public function doTestChangedTimeAfterSaveWithoutChanges() { $entity = entity_load($this->entityTypeId, $this->entityId, TRUE); // Test only entities, which implement the EntityChangedInterface. - if ($entity->getEntityType()->isSubclassOf('Drupal\Core\Entity\EntityChangedInterface')) { + if ($entity instanceof EntityChangedInterface) { $changed_timestamp = $entity->getChangedTime(); $entity->save(); diff --git a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php index 78edb89..22a1afb 100644 --- a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php +++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php @@ -276,7 +276,7 @@ protected function getContentEntityPaths() { $this->contentEntityPaths = []; $entity_types = $this->entityManager->getDefinitions(); foreach ($entity_types as $entity_type_id => $entity_type) { - if ($entity_type->isSubclassOf(ContentEntityInterface::class)) { + if (is_subclass_of($entity_type->getClass(), ContentEntityInterface::class)) { $entity_paths = array_fill_keys($entity_type->getLinkTemplates(), $entity_type_id); $this->contentEntityPaths = array_merge($this->contentEntityPaths, $entity_paths); } diff --git a/core/modules/rest/src/LinkManager/TypeLinkManager.php b/core/modules/rest/src/LinkManager/TypeLinkManager.php index f767d06..d30388d 100644 --- a/core/modules/rest/src/LinkManager/TypeLinkManager.php +++ b/core/modules/rest/src/LinkManager/TypeLinkManager.php @@ -4,6 +4,7 @@ use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Entity\ContentEntityTypeInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Symfony\Component\HttpFoundation\RequestStack; @@ -110,7 +111,7 @@ protected function writeCache($context = array()) { foreach (entity_get_bundles() as $entity_type_id => $bundles) { // Only content entities are supported currently. // @todo Consider supporting config entities. - if ($entity_types[$entity_type_id]->isSubclassOf('\Drupal\Core\Config\Entity\ConfigEntityInterface')) { + if (!($entity_types[$entity_type_id] instanceof ContentEntityTypeInterface)) { continue; } foreach ($bundles as $bundle => $bundle_info) { diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php index 7cad93c..e971649 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php @@ -21,7 +21,6 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeRepositoryInterface; -use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Field\FieldDefinitionInterface; @@ -543,7 +542,6 @@ protected function setUpEntityWithFieldDefinition($custom_invoke_all = FALSE, $f $this->entityType->getClass()->willReturn($entity_class); $this->entityType->getKeys()->willReturn($entity_keys + ['default_langcode' => 'default_langcode']); - $this->entityType->isSubclassOf(FieldableEntityInterface::class)->willReturn(TRUE); $this->entityType->isTranslatable()->willReturn(FALSE); $this->entityType->getProvider()->willReturn('the_provider'); $this->entityType->id()->willReturn('the_entity_id'); @@ -652,13 +650,12 @@ public function testGetFieldMap() { $entity_type->getClass()->willReturn($entity_class); $entity_type->getKeys()->willReturn(['default_langcode' => 'default_langcode']); - $entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(TRUE); $entity_type->isTranslatable()->shouldBeCalled(); $entity_type->getProvider()->shouldBeCalled(); - $non_content_entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(FALSE); + $non_content_entity_type->getClass()->willReturn(EntityInterface::class); - $override_entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(FALSE); + $override_entity_type->getClass()->willReturn(EntityInterface::class); // Set up the entity type bundle info to return two bundles for the // fieldable entity type. @@ -753,11 +750,10 @@ public function testGetFieldMapByFieldType() { $entity_type->getClass()->willReturn($entity_class)->shouldBeCalled(); $entity_type->getKeys()->willReturn(['default_langcode' => 'default_langcode'])->shouldBeCalled(); - $entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(TRUE)->shouldBeCalled(); $entity_type->isTranslatable()->shouldBeCalled(); $entity_type->getProvider()->shouldBeCalled(); - $override_entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(FALSE)->shouldBeCalled(); + $override_entity_type->getClass()->willReturn(EntityInterface::class)->shouldBeCalled(); $integerFields = $this->entityFieldManager->getFieldMapByFieldType('integer'); $this->assertCount(1, $integerFields['test_entity_type']); diff --git a/core/tests/Drupal/Tests/Core/Entity/Routing/DefaultHtmlRouteProviderTest.php b/core/tests/Drupal/Tests/Core/Entity/Routing/DefaultHtmlRouteProviderTest.php index 7196652..383a4d8 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Routing/DefaultHtmlRouteProviderTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Routing/DefaultHtmlRouteProviderTest.php @@ -8,10 +8,11 @@ namespace Drupal\Tests\Core\Entity\Routing; use Drupal\Core\Config\Entity\ConfigEntityTypeInterface; +use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityFieldManagerInterface; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Tests\UnitTestCase; @@ -159,7 +160,7 @@ public function providerTestGetAddFormRoute() { $entity_type5->getBundleEntityType()->willReturn('the_bundle_entity_type_id'); $entity_type5->getLinkTemplate('add-form')->willReturn('/the/add/form/link/template/{the_bundle_entity_type_id}'); $bundle_entity_type = $this->getEntityType(); - $bundle_entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(FALSE); + $bundle_entity_type->getClass()->willReturn(EntityInterface::class); $route->setPath('/the/add/form/link/template/{the_bundle_entity_type_id}'); $route ->setDefault('bundle_parameter', 'the_bundle_entity_type_id') @@ -171,7 +172,7 @@ public function providerTestGetAddFormRoute() { $entity_type6 = $this->getEntityType($entity_type5); $bundle_entity_type = $this->getEntityType(); - $bundle_entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(TRUE); + $bundle_entity_type->getClass()->willReturn(ContentEntityInterface::class); $field_storage_definition = $this->prophesize(FieldStorageDefinitionInterface::class); $field_storage_definition->getType()->willReturn('integer'); $route->setRequirement('the_entity_type_id', '\d+'); @@ -179,7 +180,7 @@ public function providerTestGetAddFormRoute() { $entity_type7 = $this->getEntityType($entity_type6); $bundle_entity_type = $this->prophesize(ConfigEntityTypeInterface::class); - $bundle_entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(FALSE); + $bundle_entity_type->getClass()->willReturn(EntityInterface::class); $field_storage_definition = $this->prophesize(FieldStorageDefinitionInterface::class); $route // Unset the 'the_entity_type_id' requirement. @@ -223,7 +224,7 @@ public function providerTestGetCanonicalRoute() { $entity_type3->hasViewBuilderClass()->willReturn(TRUE); $entity_type3->id()->willReturn('the_entity_type_id'); $entity_type3->getLinkTemplate('canonical')->willReturn('/the/canonical/link/template'); - $entity_type3->isSubclassOf(FieldableEntityInterface::class)->willReturn(FALSE); + $entity_type3->getClass()->willReturn(EntityInterface::class); $route = (new Route('/the/canonical/link/template')) ->setDefaults([ '_entity_view' => 'the_entity_type_id.full', @@ -242,7 +243,7 @@ public function providerTestGetCanonicalRoute() { $data['id_key_type_null'] = [clone $route, $entity_type3->reveal()]; $entity_type4 = $this->getEntityType($entity_type3); - $entity_type4->isSubclassOf(FieldableEntityInterface::class)->willReturn(TRUE); + $entity_type4->getClass()->willReturn(ContentEntityInterface::class); $entity_type4->getKey('id')->willReturn('id'); $route->setRequirement('the_entity_type_id', '\d+'); $field_storage_definition = $this->prophesize(FieldStorageDefinitionInterface::class); @@ -257,7 +258,7 @@ public function providerTestGetCanonicalRoute() { */ public function testGetEntityTypeIdKeyType() { $entity_type = $this->prophesize(EntityTypeInterface::class); - $entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(TRUE); + $entity_type->getClass()->willReturn(ContentEntityInterface::class); $entity_type->id()->willReturn('the_entity_type_id'); $entity_type->getKey('id')->willReturn('id'); @@ -274,7 +275,7 @@ public function testGetEntityTypeIdKeyType() { */ public function testGetEntityTypeIdKeyTypeNotFieldable() { $entity_type = $this->prophesize(EntityTypeInterface::class); - $entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(FALSE); + $entity_type->getClass()->willReturn(EntityInterface::class); $this->entityFieldManager->getFieldStorageDefinitions(Argument::any())->shouldNotBeCalled(); $type = $this->routeProvider->getEntityTypeIdKeyType($entity_type->reveal());