diff --git a/src/Plugin/Group/RelationHandlerDefault/OperationProvider.php b/src/Plugin/Group/RelationHandlerDefault/OperationProvider.php index 76d8431ff0c45710970f7e6446c53601d3a7301a..d1a254cf5608d109ef90cae859cd60ec2368c2db 100644 --- a/src/Plugin/Group/RelationHandlerDefault/OperationProvider.php +++ b/src/Plugin/Group/RelationHandlerDefault/OperationProvider.php @@ -7,6 +7,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Session\AccountProxyInterface; use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\Url; +use Drupal\field_ui\Hook\FieldUiHooks; use Drupal\group\Entity\GroupInterface; use Drupal\group\Entity\GroupTypeInterface; use Drupal\group\Plugin\Group\Relation\GroupRelationTypeManagerInterface; @@ -58,82 +59,41 @@ class OperationProvider implements OperationProviderInterface { $ui_allowed = !$this->groupRelationType->isEnforced() && !$this->groupRelationType->isCodeOnly(); if ($relationship_type_id = $this->getRelationshipTypeId($group_type)) { - $route_params = ['group_relationship_type' => $relationship_type_id]; - $operations['configure'] = [ - 'title' => $this->t('Configure'), - 'url' => new Url('entity.group_relationship_type.edit_form', $route_params), - ]; + $route_params = ['group_relationship_type' => $relationship_type_id]; + $operations['configure'] = [ + 'title' => $this->t('Configure'), + 'url' => new Url('entity.group_relationship_type.edit_form', $route_params), + ]; - if ($ui_allowed) { - $operations['uninstall'] = [ - 'title' => $this->t('Uninstall'), - 'weight' => 99, - 'url' => new Url('entity.group_relationship_type.delete_form', $route_params), - ]; - } + if ($ui_allowed) { + $operations['uninstall'] = [ + 'title' => $this->t('Uninstall'), + 'weight' => 99, + 'url' => new Url('entity.group_relationship_type.delete_form', $route_params), + ]; + } - // Use a safer alternative to field_ui_entity_operation() - if ($this->moduleHandler->moduleExists('field_ui')) { - $relationship_type = $this->entityTypeManager()->getStorage('group_relationship_type')->load($relationship_type_id); - if ($relationship_type) { - $operations += $this->getFieldUiOperations($relationship_type); - } + // Use a safer alternative to field_ui_entity_operation() + if ($this->moduleHandler->moduleExists('field_ui')) { + $relationship_type = $this->entityTypeManager()->getStorage('group_relationship_type')->load($relationship_type_id); + if ($relationship_type) { + $operations += new FieldUiHooks()->entityOperation($relationship_type); } - } + } + } elseif ($ui_allowed) { - $operations['install'] = [ - 'title' => $this->t('Install'), - 'url' => new Url('entity.group_relationship_type.add_form', [ - 'group_type' => $group_type->id(), - 'plugin_id' => $this->pluginId, - ]), - ]; + $operations['install'] = [ + 'title' => $this->t('Install'), + 'url' => new Url('entity.group_relationship_type.add_form', [ + 'group_type' => $group_type->id(), + 'plugin_id' => $this->pluginId, + ]), + ]; } return $operations; -} - -/** - * Generates Field UI operations. - */ -protected function getFieldUiOperations(EntityInterface $entity): array { - $operations = []; - $entity_type_id = $entity->getEntityTypeId(); - - // Ensure we only add Field UI operations for entities that support it. - if (in_array($entity_type_id, ['node', 'taxonomy_term', 'user', 'group'])) { - $route_name = "entity.{$entity_type_id}.field_ui_fields"; - - if ($this->currentUser->hasPermission('administer ' . $entity_type_id . ' fields')) { - $operations['manage_fields'] = [ - 'title' => $this->t('Manage fields'), - 'url' => Url::fromRoute($route_name, [$entity_type_id => $entity->id()]), - ]; - } } - return $operations; -} - -/** - * Provides entity operation links, replacing field_ui_entity_operation(). - */ -protected function getEntityOperations($entity) { - $operations = []; - if ($entity->hasLinkTemplate('edit-form')) { - $operations['edit'] = [ - 'title' => $this->t('Edit'), - 'url' => $entity->toUrl('edit-form'), - ]; - } - if ($entity->hasLinkTemplate('delete-form')) { - $operations['delete'] = [ - 'title' => $this->t('Delete'), - 'url' => $entity->toUrl('delete-form'), - ]; - } - return $operations; -} /** * {@inheritdoc} */