Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
eck
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
eck
Merge requests
!30
Issue
#3360396
: Add more menu links
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#3360396
: Add more menu links
issue/eck-3360396:3360396-add-more-menu
into
2.x
Overview
0
Commits
2
Pipelines
0
Changes
2
Merged
Dieter Holvoet
requested to merge
issue/eck-3360396:3360396-add-more-menu
into
2.x
2 years ago
Overview
0
Commits
2
Pipelines
0
Changes
2
Expand
1
0
Merge request reports
Compare
2.x
version 4
21af79e2
1 year ago
version 3
2ed8bf17
1 year ago
version 2
f78d774b
1 year ago
version 1
f78d774b
2 years ago
2.x (base)
and
latest version
latest version
c84f5a03
2 commits,
1 year ago
version 4
21af79e2
2 commits,
1 year ago
version 3
2ed8bf17
1 commit,
1 year ago
version 2
f78d774b
1 commit,
1 year ago
version 1
f78d774b
1 commit,
2 years ago
2 files
+
157
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
src/Plugin/Derivative/EckTypesMenuItemsDeriver.php
0 → 100644
+
153
−
0
Options
<?php
namespace
Drupal\eck\Plugin\Derivative
;
use
Drupal\Component\Plugin\Derivative\DeriverBase
;
use
Drupal\Core\Plugin\Discovery\ContainerDeriverInterface
;
use
Drupal\Core\StringTranslation\StringTranslationTrait
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* Provides menu links for the different settings entity types & bundles.
*/
class
EckTypesMenuItemsDeriver
extends
DeriverBase
implements
ContainerDeriverInterface
{
use
StringTranslationTrait
;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected
$entityTypeManager
;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected
$moduleHandler
;
/**
* The route provider.
*
* @var \Drupal\Core\Routing\RouteProviderInterface
*/
protected
$routeProvider
;
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
,
$basePluginId
)
{
$instance
=
new
static
();
$instance
->
entityTypeManager
=
$container
->
get
(
'entity_type.manager'
);
$instance
->
moduleHandler
=
$container
->
get
(
'module_handler'
);
$instance
->
routeProvider
=
$container
->
get
(
'router.route_provider'
);
return
$instance
;
}
/**
* {@inheritdoc}
*/
public
function
getDerivativeDefinitions
(
$base_plugin_definition
)
{
$entityTypes
=
$this
->
entityTypeManager
->
getStorage
(
'eck_entity_type'
)
->
loadMultiple
();
foreach
(
$entityTypes
as
$entityType
)
{
$id
=
sprintf
(
'eck.entity_type.%s'
,
$entityType
->
id
());
$this
->
derivatives
[
$id
]
=
[
'title'
=>
$entityType
->
label
(),
'route_name'
=>
'entity.eck_entity_type.edit_form'
,
'route_parameters'
=>
[
'eck_entity_type'
=>
$entityType
->
id
(),
],
'parent'
=>
'eck.entity_type.admin.structure.settings'
,
'id'
=>
$id
,
]
+
$base_plugin_definition
;
$parentId
=
implode
(
':'
,
[
$base_plugin_definition
[
'id'
],
$id
]);
$bundleType
=
sprintf
(
'%s_type'
,
$entityType
->
id
());
if
(
!
$this
->
entityTypeManager
->
hasDefinition
(
$bundleType
))
{
continue
;
}
$bundles
=
$this
->
entityTypeManager
->
getStorage
(
$bundleType
)
->
loadMultiple
();
foreach
(
$bundles
as
$bundle
)
{
$id
=
sprintf
(
'eck.entity_type.%s.%s'
,
$entityType
->
id
(),
$bundle
->
id
());
$this
->
derivatives
[
$id
]
=
[
'title'
=>
$bundle
->
label
(),
'route_name'
=>
sprintf
(
'entity.%s.edit_form'
,
$bundleType
),
'route_parameters'
=>
[
$bundleType
=>
$bundle
->
id
(),
],
'parent'
=>
$parentId
,
'id'
=>
$id
,
]
+
$base_plugin_definition
;
$bundleParentId
=
implode
(
':'
,
[
$base_plugin_definition
[
'id'
],
$id
]);
if
(
$this
->
moduleHandler
->
moduleExists
(
'field_ui'
))
{
$this
->
derivatives
[
'entity.'
.
$entityType
->
id
()
.
'.field_ui_fields.'
.
$bundle
->
id
()]
=
[
'title'
=>
$this
->
t
(
'Manage fields'
),
'route_name'
=>
'entity.'
.
$entityType
->
id
()
.
'.field_ui_fields'
,
'parent'
=>
$bundleParentId
,
'route_parameters'
=>
[
$bundleType
=>
$bundle
->
id
(),
],
'weight'
=>
1
,
]
+
$base_plugin_definition
;
$this
->
derivatives
[
'entity.entity_form_display.'
.
$entityType
->
id
()
.
'.default.'
.
$bundle
->
id
()]
=
[
'title'
=>
$this
->
t
(
'Manage form display'
),
'route_name'
=>
'entity.entity_form_display.'
.
$entityType
->
id
()
.
'.default'
,
'parent'
=>
$bundleParentId
,
'route_parameters'
=>
[
$bundleType
=>
$bundle
->
id
(),
],
'weight'
=>
2
,
]
+
$base_plugin_definition
;
$this
->
derivatives
[
'entity.entity_view_display.'
.
$entityType
->
id
()
.
'.default.'
.
$bundle
->
id
()]
=
[
'title'
=>
$this
->
t
(
'Manage display'
),
'route_name'
=>
'entity.entity_view_display.'
.
$entityType
->
id
()
.
'.default'
,
'parent'
=>
$bundleParentId
,
'route_parameters'
=>
[
$bundleType
=>
$bundle
->
id
(),
],
'weight'
=>
3
,
]
+
$base_plugin_definition
;
if
(
$this
->
routeExists
(
'entity.'
.
$entityType
->
id
()
.
'.entity_permissions_form'
))
{
$this
->
derivatives
[
'entity.entity_permissions_form.'
.
$entityType
->
id
()
.
'.default.'
.
$bundle
->
id
()]
=
[
'title'
=>
$this
->
t
(
'Manage permissions'
),
'route_name'
=>
'entity.'
.
$entityType
->
id
()
.
'.entity_permissions_form'
,
'parent'
=>
$bundleParentId
,
'route_parameters'
=>
[
$bundleType
=>
$bundle
->
id
(),
],
'weight'
=>
3
,
]
+
$base_plugin_definition
;
}
}
}
}
return
parent
::
getDerivativeDefinitions
(
$base_plugin_definition
);
}
/**
* Determine if a route exists by name.
*
* @param string $routeName
* The name of the route to check.
*
* @return bool
* Whether a route with that route name exists.
*/
public
function
routeExists
(
string
$routeName
)
{
return
(
count
(
$this
->
routeProvider
->
getRoutesByNames
([
$routeName
]))
===
1
);
}
}
Loading