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
Commits
0dbaca91
Commit
0dbaca91
authored
3 weeks ago
by
Jürgen Haas
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3501480
by phenaproxima, jurgenhaas: Create an action that can apply a recipe
parent
ed2a889a
No related branches found
No related tags found
No related merge requests found
Pipeline
#403041
canceled
3 weeks ago
Stage: build
Stage: validate
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/miscellaneous/src/Plugin/Action/ApplyRecipe.php
+80
-0
80 additions, 0 deletions
modules/miscellaneous/src/Plugin/Action/ApplyRecipe.php
with
80 additions
and
0 deletions
modules/miscellaneous/src/Plugin/Action/ApplyRecipe.php
0 → 100644
+
80
−
0
View file @
0dbaca91
<?php
namespace
Drupal\eca_misc\Plugin\Action
;
use
Drupal\Core\Access\AccessResult
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Recipe\Recipe
;
use
Drupal\Core\Recipe\RecipeRunner
;
use
Drupal\Core\Session\AccountInterface
;
use
Drupal\eca\Plugin\Action\ConfigurableActionBase
;
/**
* Loads a query argument from the request into the token environment.
*
* @Action(
* id = "eca_apply_recipe",
* label = @Translation("Recipe: apply"),
* description = @Translation("Applies a given recipe."),
* eca_version_introduced = "2.1.2"
* )
*/
class
ApplyRecipe
extends
ConfigurableActionBase
{
/**
* {@inheritdoc}
*/
public
function
access
(
$object
,
?AccountInterface
$account
=
NULL
,
$return_as_object
=
FALSE
)
{
$result
=
AccessResult
::
allowed
();
$path
=
$this
->
tokenService
->
replace
(
$this
->
configuration
[
'recipe_path'
]);
if
(
$path
===
''
)
{
$result
=
AccessResult
::
forbidden
(
'Path is empty.'
);
}
elseif
(
!
is_dir
(
$path
))
{
$result
=
AccessResult
::
forbidden
(
'Path does not exist.'
);
}
return
$return_as_object
?
$result
:
$result
->
isAllowed
();
}
/**
* {@inheritdoc}
*/
public
function
execute
():
void
{
$path
=
trim
(
$this
->
tokenService
->
replace
(
$this
->
configuration
[
'recipe_path'
]));
$path
=
trim
(
rtrim
(
$path
,
'/'
));
$recipe
=
Recipe
::
createFromDirectory
(
$path
);
RecipeRunner
::
processRecipe
(
$recipe
);
}
/**
* {@inheritdoc}
*/
public
function
defaultConfiguration
():
array
{
return
[
'recipe_path'
=>
''
,
]
+
parent
::
defaultConfiguration
();
}
/**
* {@inheritdoc}
*/
public
function
buildConfigurationForm
(
array
$form
,
FormStateInterface
$form_state
):
array
{
$form
[
'recipe_path'
]
=
[
'#type'
=>
'textfield'
,
'#title'
=>
$this
->
t
(
'Recipe path'
),
'#default_value'
=>
$this
->
configuration
[
'recipe_path'
],
'#required'
=>
TRUE
,
'#eca_token_replacement'
=>
TRUE
,
];
return
parent
::
buildConfigurationForm
(
$form
,
$form_state
);
}
/**
* {@inheritdoc}
*/
public
function
submitConfigurationForm
(
array
&
$form
,
FormStateInterface
$form_state
):
void
{
$this
->
configuration
[
'recipe_path'
]
=
$form_state
->
getValue
(
'recipe_path'
);
parent
::
submitConfigurationForm
(
$form
,
$form_state
);
}
}
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