Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
group
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
group
Commits
a5bdff5c
Commit
a5bdff5c
authored
2 months ago
by
Sander Wind
Browse files
Options
Downloads
Patches
Plain Diff
Use FieldUiHooks::entityOperation() to keep it DRY
parent
dd304d08
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Plugin/Group/RelationHandlerDefault/OperationProvider.php
+27
-67
27 additions, 67 deletions
...Plugin/Group/RelationHandlerDefault/OperationProvider.php
with
27 additions
and
67 deletions
src/Plugin/Group/RelationHandlerDefault/OperationProvider.php
+
27
−
67
View file @
a5bdff5c
...
...
@@ -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}
*/
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment