diff --git a/core/lib/Drupal/Core/Entity/ContentEntityForm.php b/core/lib/Drupal/Core/Entity/ContentEntityForm.php index 29b0a9b..9e5bdf0 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->getEntityType()->entityClassImplements(EntityChangedInterface::class)) { $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 d65166e..776368e 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 (!$bundle_entity_type->entityClassImplements(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 eb93748..b6c73e5 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 (!$this->entityTypeManager()->getDefinition($values['targetEntityType'])->entityClassImplements(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..378a95c 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 (!$entity_type->entityClassImplements(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 ($entity_type->entityClassImplements(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 89b83cf..d89eed0 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 ($this->entityClassImplements(EntityChangedInterface::class) ) { $this->addConstraint('EntityChanged'); } @@ -425,8 +425,15 @@ public function setClass($class) { /** * {@inheritdoc} */ + public function entityClassImplements($interface) { + return is_subclass_of($this->getClass(), $interface); + } + + /** + * {@inheritdoc} + */ public function isSubclassOf($class) { - return is_subclass_of($this->getClass(), $class); + return $this->entityClassImplements($class); } /** diff --git a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php index c6336c9..49b0936 100644 --- a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php @@ -352,6 +352,17 @@ public function getAccessControlClass(); public function setAccessClass($class); /** + * Indicates if the entity type class implements the given interface. + * + * @param string $interface + * The class or interface to check. + * + * @return bool + * TRUE if the entity type class implements the given interface. + */ + public function entityClassImplements($interface); + + /** * Indicates if the entity type is a subclass of the given class or interface. * * @param string $class @@ -359,6 +370,10 @@ public function setAccessClass($class); * * @return bool * TRUE if the entity type is a subclass of the class or interface. + * + * @deprecated in Drupal 8.3.0 and will be removed before Drupal 9.0.0. + * Use Drupal\Core\Entity\EntityTypeInterface::entityClassImpelments() + * 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..4dc1e9c 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 ($entity_type->entityClassImplements(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..d924e1a 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 ($entity_type->entityClassImplements(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 1ac54bb..fd23018 100644 --- a/core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php +++ b/core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php @@ -341,7 +341,7 @@ protected function getCollectionRoute(EntityTypeInterface $entity_type) { * type does not support fields. */ protected function getEntityTypeIdKeyType(EntityTypeInterface $entity_type) { - if (!$entity_type->isSubclassOf(FieldableEntityInterface::class)) { + if (!$entity_type->entityClassImplements(FieldableEntityInterface::class)) { return NULL; } diff --git a/core/lib/Drupal/Core/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php index 0dfe322..c3dbcc8 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 ($entity_type->entityClassImplements(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 ($entity_type->entityClassImplements(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..2170b36 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 && $entity_type->entityClassImplements(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 63bd90d..3babf42 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 ($target_type_info->entityClassImplements(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 ($target_type_info->entityClassImplements(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..438eaf8 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\ConfigEntityInterface; 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->entityClassImplements(ConfigEntityInterface::class)) { 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->entityClassImplements(ConfigEntityInterface::class)) { return $this->adminContext->isAdminRoute($route); } } diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index b0f1550..aa61d7e 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -341,7 +341,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 (!\Drupal::entityManager()->getDefinition($entity_type)->entityClassImplements(FieldableEntityInterface::class)) { return; } // @todo Investigate in https://www.drupal.org/node/2527866 why we need that. diff --git a/core/modules/comment/comment.tokens.inc b/core/modules/comment/comment.tokens.inc index 4a935c2..5af2e6a 100644 --- a/core/modules/comment/comment.tokens.inc +++ b/core/modules/comment/comment.tokens.inc @@ -24,7 +24,7 @@ function comment_token_info() { $tokens = []; // Provide a integration for each entity type except comment. foreach (\Drupal::entityTypeManager()->getDefinitions() as $entity_type_id => $entity_type) { - if ($entity_type_id == 'comment' || !$entity_type->isSubclassOf(ContentEntityInterface::class)) { + if ($entity_type_id == 'comment' || !$entity_type->entityClassImplements(ContentEntityInterface::class)) { continue; } diff --git a/core/modules/comment/comment.views.inc b/core/modules/comment/comment.views.inc index 5e31876..1c00130 100644 --- a/core/modules/comment/comment.views.inc +++ b/core/modules/comment/comment.views.inc @@ -4,6 +4,7 @@ * @file * Provide views data for comment.module. */ +use Drupal\Core\Entity\ContentEntityInterface; /** * Implements hook_views_data_alter(). @@ -22,7 +23,7 @@ function comment_views_data_alter(&$data) { // Provide a integration for each entity type 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' || !$entity_type->entityClassImplements(ContentEntityInterface::class) || !$entity_type->getBaseTable()) { continue; } $fields = \Drupal::service('comment.manager')->getFields($entity_type_id); diff --git a/core/modules/comment/src/CommentManager.php b/core/modules/comment/src/CommentManager.php index fcec230..828b194 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,7 @@ 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 (!$entity_type->entityClassImplements(FieldableEntityInterface::class)) { return array(); } diff --git a/core/modules/comment/src/CommentViewsData.php b/core/modules/comment/src/CommentViewsData.php index 2d9b021..e4ca5b0 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\ContentEntityInterface; use Drupal\views\EntityViewsData; /** @@ -184,7 +185,7 @@ public function getViewsData() { // Provide a relationship for each entity type 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' || !$entity_type->entityClassImplements(ContentEntityInterface::class) || !$entity_type->getBaseTable()) { continue; } if ($fields = \Drupal::service('comment.manager')->getFields($type)) { @@ -226,7 +227,7 @@ public function getViewsData() { // Provide a relationship for each entity type 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' || !$entity_type->entityClassImplements(ContentEntityInterface::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..f93f807 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\Core\Entity\FieldableEntityInterface; use Drupal\Tests\UnitTestCase; /** @@ -23,8 +24,8 @@ public function testGetFields() { ->method('getClass') ->will($this->returnValue('Node')); $entity_type->expects($this->any()) - ->method('isSubclassOf') - ->with('\Drupal\Core\Entity\FieldableEntityInterface') + ->method('entityClassImplements') + ->with(FieldableEntityInterface::class) ->will($this->returnValue(TRUE)); $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 9df8069..86f1047 100644 --- a/core/modules/config/src/Form/ConfigSingleExportForm.php +++ b/core/modules/config/src/Form/ConfigSingleExportForm.php @@ -2,6 +2,7 @@ namespace Drupal\config\Form; +use Drupal\Core\Config\Entity\ConfigEntityInterface; 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->entityClassImplements(ConfigEntityInterface::class)) { $this->definitions[$entity_type] = $definition; } } diff --git a/core/modules/config/src/Form/ConfigSingleImportForm.php b/core/modules/config/src/Form/ConfigSingleImportForm.php index 1393906..e217957 100644 --- a/core/modules/config/src/Form/ConfigSingleImportForm.php +++ b/core/modules/config/src/Form/ConfigSingleImportForm.php @@ -7,6 +7,7 @@ use Drupal\Core\Config\ConfigImporter; use Drupal\Core\Config\ConfigImporterException; use Drupal\Core\Config\ConfigManagerInterface; +use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Config\StorageComparer; use Drupal\Core\Config\StorageInterface; use Drupal\Core\Config\TypedConfigManagerInterface; @@ -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->entityClassImplements(ConfigEntityInterface::class)) { $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..d018d64 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\ConfigEntityInterface; 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->entityClassImplements(ConfigEntityInterface::class)) { 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->entityClassImplements(ConfigEntityInterface::class) || !$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->entityClassImplements(ConfigEntityInterface::class) && $entity->hasLinkTemplate('config-translation-overview') && \Drupal::currentUser()->hasPermission('translate configuration')) { diff --git a/core/modules/content_moderation/src/Routing/EntityModerationRouteProvider.php b/core/modules/content_moderation/src/Routing/EntityModerationRouteProvider.php index f953d80..6e0b2b9 100644 --- a/core/modules/content_moderation/src/Routing/EntityModerationRouteProvider.php +++ b/core/modules/content_moderation/src/Routing/EntityModerationRouteProvider.php @@ -111,7 +111,7 @@ protected function getLatestVersionRoute(EntityTypeInterface $entity_type) { * type does not support fields. */ protected function getEntityTypeIdKeyType(EntityTypeInterface $entity_type) { - if (!$entity_type->isSubclassOf(FieldableEntityInterface::class)) { + if (!$entity_type->entityClassImplements(FieldableEntityInterface::class)) { return NULL; } diff --git a/core/modules/content_translation/src/ContentTranslationHandler.php b/core/modules/content_translation/src/ContentTranslationHandler.php index 6fd2254..4671f19 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 $this->entityType->entityClassImplements(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 $this->entityType->entityClassImplements(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 3c50983..5989051 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; @@ -599,7 +600,7 @@ public function doTestChangedTimeAfterSaveWithoutChanges() { $storage->resetCache([$this->entityId]); $entity = $storage->load($this->entityId); // Test only entities, which implement the EntityChangedInterface. - if ($entity->getEntityType()->isSubclassOf('Drupal\Core\Entity\EntityChangedInterface')) { + if ($entity->getEntityType()->entityClassImplements(EntityChangedInterface::class)) { $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 4f4c7d4..9218899 100644 --- a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php +++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php @@ -263,7 +263,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 ($entity_type->entityClassImplements(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 6752f62..3b0c8a2 100644 --- a/core/modules/rest/src/LinkManager/TypeLinkManager.php +++ b/core/modules/rest/src/LinkManager/TypeLinkManager.php @@ -5,6 +5,7 @@ use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Symfony\Component\HttpFoundation\RequestStack; @@ -127,7 +128,7 @@ protected function writeCache($context = array()) { foreach ($this->bundleInfoService->getAllBundleInfo() 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]->entityClassImplements(ConfigEntityInterface::class)) { 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..9d4fc95 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php @@ -543,7 +543,7 @@ 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->entityClassImplements(FieldableEntityInterface::class)->willReturn(TRUE); $this->entityType->isTranslatable()->willReturn(FALSE); $this->entityType->getProvider()->willReturn('the_provider'); $this->entityType->id()->willReturn('the_entity_id'); @@ -652,13 +652,13 @@ 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->entityClassImplements(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->entityClassImplements(FieldableEntityInterface::class)->willReturn(FALSE); - $override_entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(FALSE); + $override_entity_type->entityClassImplements(FieldableEntityInterface::class)->willReturn(FALSE); // Set up the entity type bundle info to return two bundles for the // fieldable entity type. @@ -753,11 +753,11 @@ 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->entityClassImplements(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->entityClassImplements(FieldableEntityInterface::class)->willReturn(FALSE)->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 a6675ec0..170d0c1 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Routing/DefaultHtmlRouteProviderTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Routing/DefaultHtmlRouteProviderTest.php @@ -159,7 +159,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->entityClassImplements(FieldableEntityInterface::class)->willReturn(FALSE); $route->setPath('/the/add/form/link/template/{the_bundle_entity_type_id}'); $route ->setDefault('bundle_parameter', 'the_bundle_entity_type_id') @@ -171,7 +171,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->entityClassImplements(FieldableEntityInterface::class)->willReturn(TRUE); $field_storage_definition = $this->prophesize(FieldStorageDefinitionInterface::class); $field_storage_definition->getType()->willReturn('integer'); $route->setRequirement('the_entity_type_id', '\d+'); @@ -179,7 +179,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->entityClassImplements(FieldableEntityInterface::class)->willReturn(FALSE); $field_storage_definition = $this->prophesize(FieldStorageDefinitionInterface::class); $route // Unset the 'the_entity_type_id' requirement. @@ -223,7 +223,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->entityClassImplements(FieldableEntityInterface::class)->willReturn(FALSE); $route = (new Route('/the/canonical/link/template')) ->setDefaults([ '_entity_view' => 'the_entity_type_id.full', @@ -242,7 +242,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->entityClassImplements(FieldableEntityInterface::class)->willReturn(TRUE); $entity_type4->getKey('id')->willReturn('id'); $route->setRequirement('the_entity_type_id', '\d+'); $field_storage_definition = $this->prophesize(FieldStorageDefinitionInterface::class); @@ -283,7 +283,7 @@ public function providerTestGetCollectionRoute() { $entity_type4->id()->willReturn('the_entity_type_id'); $entity_type4->getLabel()->willReturn('The entity type'); $entity_type4->getLinkTemplate('collection')->willReturn('/the/collection/link/template'); - $entity_type4->isSubclassOf(FieldableEntityInterface::class)->willReturn(FALSE); + $entity_type4->entityClassImplements(FieldableEntityInterface::class)->willReturn(FALSE); $route = (new Route('/the/collection/link/template')) ->setDefaults([ '_entity_list' => 'the_entity_type_id', @@ -303,7 +303,7 @@ public function providerTestGetCollectionRoute() { */ public function testGetEntityTypeIdKeyType() { $entity_type = $this->prophesize(EntityTypeInterface::class); - $entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(TRUE); + $entity_type->entityClassImplements(FieldableEntityInterface::class)->willReturn(TRUE); $entity_type->id()->willReturn('the_entity_type_id'); $entity_type->getKey('id')->willReturn('id'); @@ -320,7 +320,7 @@ public function testGetEntityTypeIdKeyType() { */ public function testGetEntityTypeIdKeyTypeNotFieldable() { $entity_type = $this->prophesize(EntityTypeInterface::class); - $entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(FALSE); + $entity_type->entityClassImplements(FieldableEntityInterface::class)->willReturn(FALSE); $this->entityFieldManager->getFieldStorageDefinitions(Argument::any())->shouldNotBeCalled(); $type = $this->routeProvider->getEntityTypeIdKeyType($entity_type->reveal());