diff --git a/src/Plugin/EntityLimit/RoleLimit.php b/src/Plugin/EntityLimit/RoleLimit.php index 24debe9..359ac8f 100644 --- a/src/Plugin/EntityLimit/RoleLimit.php +++ b/src/Plugin/EntityLimit/RoleLimit.php @@ -253,14 +253,14 @@ class RoleLimit extends EntityLimitPluginBase implements ContainerFactoryPluginI $uid = $this->account->id(); } - $fields = \Drupal::service('entity_field.manager') - ->getFieldStorageDefinitions($entityLimit->getEntityLimitType()); - $uid_field = !empty($fields['user_id']) ? 'user_id' : 'uid'; + $entityType = \Drupal::entityTypeManager()->getDefinition($entityLimit->getEntityLimitType()); + $bundleKey = $entityType->getKey('bundle'); + $ownerKey = $entityType->getKey('owner'); $access = TRUE; $query = \Drupal::entityQuery($entityLimit->getEntityLimitType()); - $query->condition('type', $entityLimit->getEntityLimitBundles(), 'IN'); - $query->condition($uid_field, $uid); + $query->condition($bundleKey, $entityLimit->getEntityLimitBundles(), 'IN'); + $query->condition($ownerKey, $uid); $query->accessCheck(FALSE); $count = count($query->execute()); if ($count >= (int) $limit) { diff --git a/src/Plugin/EntityLimit/UserLimit.php b/src/Plugin/EntityLimit/UserLimit.php index 130a1c0..361fae3 100644 --- a/src/Plugin/EntityLimit/UserLimit.php +++ b/src/Plugin/EntityLimit/UserLimit.php @@ -244,14 +244,15 @@ class UserLimit extends EntityLimitPluginBase implements ContainerFactoryPluginI $uid = $this->account->id(); } - $fields = \Drupal::service('entity_field.manager') - ->getFieldStorageDefinitions($entityLimit->getEntityLimitType()); - $uid_field = !empty($fields['user_id']) ? 'user_id' : 'uid'; + $entityType = \Drupal::entityTypeManager()->getDefinition($entityLimit->getEntityLimitType()); + $bundleKey = $entityType->getKey('bundle'); + $ownerKey = $entityType->getKey('owner'); + $access = TRUE; $query = \Drupal::entityQuery($entityLimit->getEntityLimitType()); $query->accessCheck(FALSE); - $query->condition('type', $entityLimit->getEntityLimitBundles(), 'IN'); - $query->condition($uid_field, $uid); + $query->condition($bundleKey, $entityLimit->getEntityLimitBundles(), 'IN'); + $query->condition($ownerKey, $uid); $count = count($query->execute()); if ($count >= (int) $limit) { $access = FALSE;