diff --git a/dgi_fixity.module b/dgi_fixity.module index 07461e4..85b49a3 100644 --- a/dgi_fixity.module +++ b/dgi_fixity.module @@ -139,18 +139,38 @@ function dgi_fixity_cron() { * Implements hook_entity_type_alter(). */ function dgi_fixity_entity_type_alter(array &$entity_types) { - return \Drupal::service('class_resolver') - ->getInstanceFromDefinition(EntityTypeInfo::class) - ->entityTypeAlter($entity_types); + /** @var \Drupal\dgi_fixity\FixityCheckServiceInterface $fixity */ + $fixity = \Drupal::service('dgi_fixity.fixity_check'); + $supported_entity_types = $fixity->fromEntityTypes(); + foreach ($supported_entity_types as $entity_type_id) { + $entity_type = &$entity_types[$entity_type_id]; + $entity_type->setLinkTemplate('fixity-audit', "/fixity/$entity_type_id/{{$entity_type_id}}"); + $entity_type->setLinkTemplate('fixity-check', "/fixity/$entity_type_id/{{$entity_type_id}}/check"); + $entity_type->setFormClass('fixity-check', 'Drupal\dgi_fixity\Form\CheckForm'); + } } /** * Implements hook_entity_operation(). */ function dgi_fixity_entity_operation(EntityInterface $entity) { - return \Drupal::service('class_resolver') - ->getInstanceFromDefinition(EntityTypeInfo::class) - ->entityOperation($entity); + $current_user = \Drupal::service('current_user'); + $operations = []; + if ($entity->hasLinkTemplate('fixity-audit') && $current_user->hasPermission('view fixity checks')) { + $operations['fixity-audit'] = [ + 'title' => \t('Audit'), + 'weight' => 10, + 'url' => $entity->toUrl('fixity-audit'), + ]; + if ($entity->hasLinkTemplate('fixity-check') && $current_user->hasPermission('administer fixity checks')) { + $operations['fixity-check'] = [ + 'title' => \t('Check'), + 'weight' => 13, + 'url' => $entity->toUrl('fixity-check', ['query' => \Drupal::service('redirect.destination')->getAsArray()]), + ]; + } + } + return $operations; } /** diff --git a/src/EntityTypeInfo.php b/src/EntityTypeInfo.php deleted file mode 100644 index 85e5d72..0000000 --- a/src/EntityTypeInfo.php +++ /dev/null @@ -1,125 +0,0 @@ -stringTranslation = $string_translation; - $this->currentUser = $current_user; - $this->redirect = $redirect; - $this->fixity = $fixity; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('string_translation'), - $container->get('current_user'), - $container->get('redirect.destination'), - $container->get('dgi_fixity.fixity_check'), - ); - } - - /** - * Gets fixity check links to appropriate entity types. - * - * This is an alter hook bridge. - * - * @param \Drupal\Core\Entity\EntityTypeInterface[] $entity_types - * The master entity type list to alter. - * - * @see hook_entity_type_alter() - */ - public function entityTypeAlter(array &$entity_types) { - $supported_entity_types = $this->fixity->fromEntityTypes(); - foreach ($supported_entity_types as $entity_type_id) { - $entity_type = &$entity_types[$entity_type_id]; - $entity_type->setLinkTemplate('fixity-audit', "/fixity/$entity_type_id/{{$entity_type_id}}"); - $entity_type->setLinkTemplate('fixity-check', "/fixity/$entity_type_id/{{$entity_type_id}}/check"); - $entity_type->setFormClass('fixity-check', 'Drupal\dgi_fixity\Form\CheckForm'); - } - } - - /** - * Gets fixity operations on entities that support it. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity on which to define an operation. - * - * @return array - * An array of operation definitions. - * - * @see hook_entity_operation() - */ - public function entityOperation(EntityInterface $entity) { - $operations = []; - if ($entity->hasLinkTemplate('fixity-audit') && $this->currentUser->hasPermission('view fixity checks')) { - $operations['fixity-audit'] = [ - 'title' => $this->t('Audit'), - 'weight' => 10, - 'url' => $entity->toUrl('fixity-audit'), - ]; - if ($entity->hasLinkTemplate('fixity-check') && $this->currentUser->hasPermission('administer fixity checks')) { - $operations['fixity-check'] = [ - 'title' => $this->t('Check'), - 'weight' => 13, - 'url' => $entity->toUrl('fixity-check', ['query' => $this->redirect->getAsArray()]), - ]; - } - } - return $operations; - } - -}