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
!469
Issue
#3500732
by mysdiir: Action that combines two lists.
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Issue
#3500732
by mysdiir: Action that combines two lists.
issue/eca-3500732:3500732-combine-list
into
3.0.x
Overview
35
Commits
20
Pipelines
20
Changes
1
All threads resolved!
Hide all comments
Open
mysdiir
requested to merge
issue/eca-3500732:3500732-combine-list
into
3.0.x
4 months ago
Overview
35
Commits
20
Pipelines
20
Changes
1
All threads resolved!
Hide all comments
Expand
Closes
#3500732
0
0
Merge request reports
Compare
3.0.x
version 19
dfadce0e
1 month ago
version 18
d66933f7
2 months ago
version 17
72c1f84b
3 months ago
version 16
c3231fa9
3 months ago
version 15
e95e47fa
3 months ago
version 14
185c78ab
3 months ago
version 13
7c04171b
3 months ago
version 12
a1a66b29
3 months ago
version 11
7fe10678
3 months ago
version 10
4c5cc718
3 months ago
version 9
0285e9fb
4 months ago
version 8
b78b6840
4 months ago
version 7
f99e5240
4 months ago
version 6
0645c89e
4 months ago
version 5
22b8581f
4 months ago
version 4
651a70e7
4 months ago
version 3
ed8ff1c1
4 months ago
version 2
fe3355d3
4 months ago
version 1
c40d948d
4 months ago
3.0.x (HEAD)
and
latest version
latest version
dfadce0e
20 commits,
1 month ago
version 19
dfadce0e
41 commits,
1 month ago
version 18
d66933f7
19 commits,
2 months ago
version 17
72c1f84b
18 commits,
3 months ago
version 16
c3231fa9
17 commits,
3 months ago
version 15
e95e47fa
16 commits,
3 months ago
version 14
185c78ab
15 commits,
3 months ago
version 13
7c04171b
14 commits,
3 months ago
version 12
a1a66b29
13 commits,
3 months ago
version 11
7fe10678
12 commits,
3 months ago
version 10
4c5cc718
11 commits,
3 months ago
version 9
0285e9fb
10 commits,
4 months ago
version 8
b78b6840
9 commits,
4 months ago
version 7
f99e5240
8 commits,
4 months ago
version 6
0645c89e
6 commits,
4 months ago
version 5
22b8581f
5 commits,
4 months ago
version 4
651a70e7
4 commits,
4 months ago
version 3
ed8ff1c1
3 commits,
4 months ago
version 2
fe3355d3
2 commits,
4 months ago
version 1
c40d948d
1 commit,
4 months ago
1 file
+
137
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
modules/base/src/Plugin/Action/ListMerge.php
0 → 100644
+
137
−
0
Options
<?php
declare
(
strict_types
=
1
);
namespace
Drupal\eca_base\Plugin\Action
;
use
Drupal\Core\Access\AccessResult
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Session\AccountInterface
;
use
Drupal\eca\Plugin\Action\ListDataOperationBase
;
use
Drupal\eca\Plugin\DataType\DataTransferObject
;
/**
* Action to count items in a list and store resulting number as token.
*
* @Action(
* id = "eca_list_combine",
* label = @Translation("List: merge"),
* description = @Translation("Merges two lists into a new one."),
* eca_version_introduced = "2.1.6",
* )
*/
class
ListMerge
extends
ListDataOperationBase
{
/**
* {@inheritdoc}
*/
public
function
defaultConfiguration
():
array
{
return
[
'merged_list'
=>
''
,
'list_token_left'
=>
''
,
'list_token_right'
=>
''
,
]
+
parent
::
defaultConfiguration
();
}
/**
* {@inheritdoc}
*/
public
function
buildConfigurationForm
(
array
$form
,
FormStateInterface
$form_state
):
array
{
$form
[
'merged_list'
]
=
[
'#type'
=>
'textfield'
,
'#title'
=>
$this
->
t
(
'Token name'
),
'#description'
=>
$this
->
t
(
'The name of the new token, containing the combined list.'
),
'#default_value'
=>
$this
->
configuration
[
'merged_list'
],
'#weight'
=>
-
20
,
'#required'
=>
TRUE
,
'#eca_token_reference'
=>
TRUE
,
];
$form
[
'list_token_left'
]
=
[
'#type'
=>
'textfield'
,
'#title'
=>
$this
->
t
(
'Token name of first list'
),
'#description'
=>
$this
->
t
(
'Token name of the first list that should be combined into a new one.'
),
'#default_value'
=>
$this
->
configuration
[
'list_token_left'
],
'#weight'
=>
-
15
,
'#required'
=>
TRUE
,
'#eca_token_reference'
=>
TRUE
,
];
$form
[
'list_token_right'
]
=
[
'#type'
=>
'textfield'
,
'#title'
=>
$this
->
t
(
'Token name of second list'
),
'#description'
=>
$this
->
t
(
'Token name of the second list that should be combined into a new one.'
),
'#default_value'
=>
$this
->
configuration
[
'list_token_right'
],
'#weight'
=>
-
10
,
'#required'
=>
TRUE
,
'#eca_token_reference'
=>
TRUE
,
];
return
$form
;
}
/**
* {@inheritdoc}
*/
public
function
submitConfigurationForm
(
array
&
$form
,
FormStateInterface
$form_state
):
void
{
$this
->
configuration
[
'merged_list'
]
=
$form_state
->
getValue
(
'merged_list'
);
$this
->
configuration
[
'list_token_left'
]
=
$form_state
->
getValue
(
'list_token_left'
);
$this
->
configuration
[
'list_token_right'
]
=
$form_state
->
getValue
(
'list_token_right'
);
}
/**
* {@inheritdoc}
*/
public
function
access
(
$object
,
?AccountInterface
$account
=
NULL
,
$return_as_object
=
FALSE
)
{
if
(
$account
===
NULL
)
{
$account
=
$this
->
currentUser
;
}
$list_left_token_raw
=
$this
->
tokenService
->
getTokenData
(
$this
->
configuration
[
'list_token_left'
]);
$list_right_token_raw
=
$this
->
tokenService
->
getTokenData
(
$this
->
configuration
[
'list_token_right'
]);
if
(
!
is_array
(
$list_left_token_raw
)
&&
!
(
$list_left_token_raw
instanceof
\Traversable
))
{
$access_result
=
AccessResult
::
forbidden
(
'The left token does not provide an iterable list.'
);
}
elseif
(
!
is_array
(
$list_right_token_raw
)
&&
!
(
$list_right_token_raw
instanceof
\Traversable
))
{
$access_result
=
AccessResult
::
forbidden
(
'The right token does not provide an iterable list.'
);
}
else
{
$access_result
=
AccessResult
::
allowed
();
}
return
$return_as_object
?
$access_result
:
$access_result
->
isAllowed
();
}
/**
* Converts the given value into an array if necessary.
*
* @param mixed $value
* The value to be converted.
*
* @return array
* The converted array.
*/
private
function
normalizeToArray
(
mixed
$value
):
array
{
if
(
$value
instanceof
DataTransferObject
)
{
return
$value
->
toArray
();
}
if
(
$value
instanceof
\Traversable
)
{
return
iterator_to_array
(
$value
);
}
return
(
array
)
$value
;
}
/**
* {@inheritdoc}
*/
public
function
execute
():
void
{
$list_left_token_raw
=
$this
->
tokenService
->
getTokenData
(
$this
->
configuration
[
'list_token_left'
]);
$list_right_token_raw
=
$this
->
tokenService
->
getTokenData
(
$this
->
configuration
[
'list_token_right'
]);
$list_left_token
=
$this
->
normalizeToArray
(
$list_left_token_raw
);
$list_right_token
=
$this
->
normalizeToArray
(
$list_right_token_raw
);
$combined_list
=
array_merge
(
$list_left_token
,
$list_right_token
);
$this
->
tokenService
->
addTokenData
(
$this
->
configuration
[
'merged_list'
],
$combined_list
);
}
}
Loading