Skip to content
Snippets Groups Projects

Rename EntityReferenceIntegrityDependencyManagerInterface to...

8 files
+ 65
111
Compare changes
  • Side-by-side
  • Inline
Files
8
@@ -4,7 +4,7 @@ namespace Drupal\entity_reference_integrity_enforce;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\entity_reference_integrity\EntityReferenceDependencyManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\entity_reference_integrity_enforce\Exception\ProtectedEntityException;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -14,11 +14,11 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class EntityPredelete implements ContainerInjectionInterface {
/**
* The dependency manager.
* The entity type manager.
*
* @var \Drupal\entity_reference_integrity\EntityReferenceDependencyManagerInterface
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $dependencyManager;
protected $entityTypeManager;
/**
* The entity type IDs protection is enabled for.
@@ -28,10 +28,15 @@ class EntityPredelete implements ContainerInjectionInterface {
protected $enabledEntityTypeIds;
/**
* Create a DeleteFormAlter object.
* Create a EntityPredelete object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param array $enabled_entity_type_ids
* The entity type IDs protection is enabled for.
*/
public function __construct(EntityReferenceDependencyManagerInterface $calculator, array $enabled_entity_type_ids) {
$this->dependencyManager = $calculator;
public function __construct(EntityTypeManagerInterface $entity_type_manager, array $enabled_entity_type_ids) {
$this->entityTypeManager = $entity_type_manager;
$this->enabledEntityTypeIds = $enabled_entity_type_ids;
}
@@ -40,7 +45,7 @@ class EntityPredelete implements ContainerInjectionInterface {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity_reference_integrity.dependency_manager'),
$container->get('entity_type.manager'),
$container->get('config.factory')->get('entity_reference_integrity_enforce.settings')->get('enabled_entity_type_ids')
);
}
@@ -49,7 +54,11 @@ class EntityPredelete implements ContainerInjectionInterface {
* Implements hook_entity_delete().
*/
public function entityDelete(EntityInterface $entity) {
if (in_array($entity->getEntityTypeId(), $this->enabledEntityTypeIds, TRUE) && $this->dependencyManager->hasDependents($entity)) {
if (!in_array($entity->getEntityTypeId(), $this->enabledEntityTypeIds, TRUE)) {
return;
}
$handler = $this->entityTypeManager->getHandler($entity->getEntityTypeId(), 'entity_reference_integrity');
if ($handler->hasDependents($entity)) {
throw new ProtectedEntityException(sprintf('Cannot delete "%s" of type "%s" with label "%s" and ID "%s" because other content is referencing it and the integrity of this entity type is enforced.', $entity->getEntityTypeId(), $entity->bundle(), $entity->label(), $entity->id()));
}
}
Loading