diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php index 4de891a..a518209 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->entityManager()->getDefinition($values['targetEntityType']) instanceof ContentEntityTypeInterface) { throw new \InvalidArgumentException('EntityDisplay entities can only handle fieldable entity types.'); } diff --git a/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php index a63415b..fa1c6d0 100644 --- a/core/lib/Drupal/Core/Entity/EntityType.php +++ b/core/lib/Drupal/Core/Entity/EntityType.php @@ -14,6 +14,11 @@ */ class EntityType implements EntityTypeInterface { + /* + * Defines EntityChangedInterface constant for internal usage + */ + const ENTITY_TYPE_ENTITY_CHANGED_INTERFACE = 'Drupal\Core\Entity\EntityChangedInterface'; + use StringTranslationTrait; /** @@ -301,7 +306,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(), self::ENTITY_TYPE_ENTITY_CHANGED_INTERFACE)) { $this->addConstraint('EntityChanged'); } diff --git a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php index 398347f..7011f28 100644 --- a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php @@ -359,6 +359,8 @@ public function setAccessClass($class); * * @return bool * TRUE if the entity type is a subclass of the class or interface. + * + * @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0 */ public function isSubclassOf($class); diff --git a/core/lib/Drupal/Core/Field/FieldModuleUninstallValidator.php b/core/lib/Drupal/Core/Field/FieldModuleUninstallValidator.php index d1adaa9..dc75fb0 100644 --- a/core/lib/Drupal/Core/Field/FieldModuleUninstallValidator.php +++ b/core/lib/Drupal/Core/Field/FieldModuleUninstallValidator.php @@ -2,6 +2,7 @@ namespace Drupal\Core\Field; +use Drupal\Core\Entity\ContentEntityTypeInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\FieldableEntityStorageInterface; use Drupal\Core\Extension\ModuleUninstallValidatorInterface; @@ -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 instanceof ContentEntityTypeInterface) { 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..f2a3145 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php @@ -4,6 +4,7 @@ use Drupal\Component\Utility\Html; use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Entity\ContentEntityTypeInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\TypedData\EntityDataDefinition; @@ -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 instanceof ContentEntityTypeInterface) { $id_definition = \Drupal::entityManager()->getBaseFieldDefinitions($settings['target_type'])[$target_type_info->getKey('id')]; if ($id_definition->getType() === 'integer') { $target_id_data_type = 'integer'; 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.views.inc b/core/modules/comment/comment.views.inc index 5e31876..6e68c7f 100644 --- a/core/modules/comment/comment.views.inc +++ b/core/modules/comment/comment.views.inc @@ -20,16 +20,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' || !$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..8fdeb4e 100644 --- a/core/modules/comment/src/CommentManager.php +++ b/core/modules/comment/src/CommentManager.php @@ -4,6 +4,7 @@ use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Entity\ContentEntityTypeInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\Query\QueryFactory; @@ -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 (!$entity_type instanceof ContentEntityTypeInterface) { + // Early return, only content types can carry comment fields. return array(); } diff --git a/core/modules/comment/src/CommentViewsData.php b/core/modules/comment/src/CommentViewsData.php index 2d9b021..bb92b16 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\ContentEntityTypeInterface; 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 instanceof ContentEntityTypeInterface || !$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 instanceof ContentEntityTypeInterface || !$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..1e1494c 100644 --- a/core/modules/comment/tests/src/Unit/CommentManagerTest.php +++ b/core/modules/comment/tests/src/Unit/CommentManagerTest.php @@ -22,10 +22,6 @@ public function testGetFields() { $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)); $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/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) {