Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
eca
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
eca
Merge requests
!490
Action to enable or disable menu links
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Action to enable or disable menu links
issue/eca-3517979:3517979-allow-eca-to
into
2.1.x
Overview
1
Commits
3
Pipelines
5
Changes
2
All threads resolved!
Hide all comments
Merged
Martin Anderson-Clutz
requested to merge
issue/eca-3517979:3517979-allow-eca-to
into
2.1.x
2 months ago
Overview
1
Commits
3
Pipelines
5
Changes
2
All threads resolved!
Hide all comments
Expand
Closes
#3517979
0
0
Merge request reports
Compare
2.1.x
version 3
f60426a5
2 months ago
version 2
5a1a9856
2 months ago
version 1
9eb65e6d
2 months ago
2.1.x (base)
and
latest version
latest version
0a11f613
3 commits,
2 months ago
version 3
f60426a5
3 commits,
2 months ago
version 2
5a1a9856
2 commits,
2 months ago
version 1
9eb65e6d
1 commit,
2 months ago
2 files
+
98
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
modules/menu/src/Plugin/Action/EnableMenuItem.php
0 → 100644
+
91
−
0
Options
<?php
namespace
Drupal\eca_menu\Plugin\Action
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Menu\MenuLinkManagerInterface
;
use
Drupal\eca\Plugin\Action\ConfigurableActionBase
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* Enables a specified menu item.
*
* @Action(
* id = "eca_menu_enable_menu_item",
* label = @Translation("Menu Item: Enable or Disable"),
* description = @Translation("Enable or disable a menu link (can be module provided)."),
* eca_version_introduced = "2.1.x",
* type = "entity"
* )
*/
class
EnableMenuItem
extends
ConfigurableActionBase
{
/**
* The MenuLinkManager.
*
* @var \Drupal\Core\Menu\MenuLinkManagerInterface
*/
protected
MenuLinkManagerInterface
$menuLinkManager
;
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
$plugin_definition
):
static
{
$instance
=
parent
::
create
(
$container
,
$configuration
,
$plugin_id
,
$plugin_definition
);
$instance
->
menuLinkManager
=
$container
->
get
(
'plugin.manager.menu.link'
);
return
$instance
;
}
/**
* {@inheritdoc}
*/
public
function
defaultConfiguration
():
array
{
return
[
'menu_item'
=>
''
,
'enabled'
=>
TRUE
,
]
+
parent
::
defaultConfiguration
();
}
/**
* {@inheritdoc}
*/
public
function
buildConfigurationForm
(
array
$form
,
FormStateInterface
$form_state
):
array
{
$form
[
'menu_item'
]
=
[
'#type'
=>
'textfield'
,
'#title'
=>
$this
->
t
(
'ID of menu item'
),
'#default_value'
=>
$this
->
configuration
[
'menu_item'
],
'#description'
=>
$this
->
t
(
'The id of a menu item provided by code (e.g. not a menu_link_content created in the menu UI).'
),
'#eca_token_replacement'
=>
TRUE
,
'#required'
=>
TRUE
,
];
$form
[
'enabled'
]
=
[
'#type'
=>
'checkbox'
,
'#title'
=>
$this
->
t
(
'Enable'
),
'#description'
=>
$this
->
t
(
'Select to have the menu item enabled, or leave unchecked to have it disabled.'
),
'#default_value'
=>
$this
->
configuration
[
'enabled'
],
];
return
parent
::
buildConfigurationForm
(
$form
,
$form_state
);
}
/**
* {@inheritdoc}
*/
public
function
submitConfigurationForm
(
array
&
$form
,
FormStateInterface
$form_state
):
void
{
$this
->
configuration
[
'menu_item'
]
=
$form_state
->
getValue
(
'menu_item'
);
$this
->
configuration
[
'enabled'
]
=
!
empty
(
$form_state
->
getValue
(
'enabled'
));
parent
::
submitConfigurationForm
(
$form
,
$form_state
);
}
/**
* {@inheritdoc}
*/
public
function
execute
(
mixed
$entity
=
NULL
):
void
{
$menuItemId
=
(
string
)
$this
->
tokenService
->
replace
(
$this
->
configuration
[
'menu_item'
]);
$definition
=
$this
->
menuLinkManager
->
getDefinition
(
$menuItemId
);
// Set the 'enabled' value based on the configuration, and save.
$definition
[
'enabled'
]
=
(
$this
->
configuration
[
'enabled'
])
?
1
:
0
;
$this
->
menuLinkManager
->
updateDefinition
(
$menuItemId
,
$definition
);
}
}
Loading