Commit 3d72d4be authored by catch's avatar catch
Browse files

Issue #2194783 by Berdir, vprocessor, andypost, Antonnavi, tim.plunkett,...

Issue #2194783 by Berdir, vprocessor, andypost, Antonnavi, tim.plunkett, Crell, Mile23, catch: Rename EntityTypeInterface::isSubclassOf() to ::entityClassImplements()
parent ab8284be
......@@ -366,7 +366,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($this->time->getRequestTime());
}
}
......
......@@ -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);
......
......@@ -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.');
}
......
......@@ -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] = [
......
......@@ -308,7 +308,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');
}
......@@ -429,11 +429,18 @@ public function setClass($class) {
return $this;
}
/**
* {@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);
}
/**
......
......@@ -351,6 +351,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.
*
......@@ -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);
......
......@@ -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));
}
}
......
......@@ -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) {
......
......@@ -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;
}
......
......@@ -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.
......
......@@ -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);
......
......@@ -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.',
......
......@@ -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);
}
}
......
......@@ -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.
......
......@@ -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;
}
......
......@@ -5,6 +5,8 @@
* Provide views data for comment.module.
*/
use Drupal\Core\Entity\ContentEntityInterface;
/**
* Implements hook_views_data_alter().
*/
......@@ -22,7 +24,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);
......
......@@ -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();
}
......
......@@ -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
......
......@@ -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');
......
......@@ -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;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment