diff --git a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php index 5963b37..87268f4 100644 --- a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php @@ -380,6 +380,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 8.0.0 */ public function isSubclassOf($class); diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index f06d608..eb041f5 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -14,7 +14,6 @@ use Drupal\comment\Entity\Comment; use Drupal\comment\CommentManagerInterface; use Drupal\comment\Entity\CommentType; -use Drupal\Core\Entity\ContentEntityTypeInterface; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\Component\Utility\SafeMarkup; @@ -311,10 +310,6 @@ function comment_form_field_storage_config_edit_form_alter(&$form, FormStateInte * @see \Drupal\comment\Plugin\Field\FieldType\CommentItem::propertyDefinitions() */ 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) instanceof ContentEntityTypeInterface) { - return; - } if (!\Drupal::service('comment.manager')->getFields($entity_type)) { // Do not query database when entity has no comment fields. return; diff --git a/core/modules/comment/comment.views.inc b/core/modules/comment/comment.views.inc index 69a1cec..6e68c7f 100644 --- a/core/modules/comment/comment.views.inc +++ b/core/modules/comment/comment.views.inc @@ -4,7 +4,6 @@ * @file * Provide views data for comment.module. */ -use Drupal\Core\Entity\ContentEntityTypeInterface; /** * Implements hook_views_data_alter(). @@ -21,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 instanceof ContentEntityTypeInterface || !$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 46d2572..f1be1a8 100644 --- a/core/modules/comment/src/CommentManager.php +++ b/core/modules/comment/src/CommentManager.php @@ -107,6 +107,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 instanceof ContentEntityTypeInterface) { + // Early return, only content types can carry comment fields. return array(); } diff --git a/core/modules/comment/tests/src/Unit/CommentManagerTest.php b/core/modules/comment/tests/src/Unit/CommentManagerTest.php index acdd57a..6cc8393 100644 --- a/core/modules/comment/tests/src/Unit/CommentManagerTest.php +++ b/core/modules/comment/tests/src/Unit/CommentManagerTest.php @@ -27,10 +27,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/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php index 5762e9e..c9e5fec 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php @@ -875,7 +875,7 @@ public function testGetFieldDefinitionsProvider() { * A field definition object. */ protected function setUpEntityWithFieldDefinition($custom_invoke_all = FALSE, $field_definition_id = 'id', $entity_keys = array()) { - $this->entityType = $this->getMock('Drupal\Core\Entity\EntityTypeInterface'); + $this->entityType = $this->getMock('Drupal\Core\Entity\ContentEntityTypeInterface'); $this->entity = $this->getMockBuilder('Drupal\Tests\Core\Entity\EntityManagerTestEntity') ->disableOriginalConstructor() @@ -888,10 +888,6 @@ protected function setUpEntityWithFieldDefinition($custom_invoke_all = FALSE, $f $this->entityType->expects($this->any()) ->method('getKeys') ->will($this->returnValue($entity_keys + array('default_langcode' => 'default_langcode'))); - $this->entityType->expects($this->any()) - ->method('isSubclassOf') - ->with($this->equalTo('\Drupal\Core\Entity\FieldableEntityInterface')) - ->will($this->returnValue(TRUE)); $field_definition = $this->getMockBuilder('Drupal\Core\Field\BaseFieldDefinition') ->disableOriginalConstructor() ->getMock();