- Issue created by @danielspeicher
- @jurgenhaas opened merge request.
- π©πͺGermany jurgenhaas Gottmadingen
Started a first draft for this new condition. It most likely requires more cases to be checked when iterating through the list.
- First commit to issue fork.
- last update
over 1 year ago 284 pass - @mxh opened merge request.
- π©πͺGermany mxh Offenburg
We're using such a condition since a couple of weeks. I've created MR349 which contains the implementation of that plugin. It's funny that the plugin ID matches with your suggestion. Feel free to use / reuse / not use anything from it.
- Status changed to Needs work
over 1 year ago 1:05pm 26 April 2023 - π©πͺGermany jurgenhaas Gottmadingen
@mxh thanks for MR!349, I've looked into it, and it covers all that's in MR!339, plus more. I'm happy to use yours instead of the original one and left a couple of comments in the MR. I'm happy to "fix" them myself, but wanted to get your feedback on them first.
- Assigned to mxh
- last update
over 1 year ago 284 pass - Issue was unassigned.
- Status changed to Needs review
over 1 year ago 6:54pm 26 April 2023 - last update
over 1 year ago 284 pass - π©πͺGermany jurgenhaas Gottmadingen
Got it, thanks for the clarification. I've now committed a couple of code clean-ups and PHP 8.1 adjustments.
- π©πͺGermany mxh Offenburg
Thanks. Would it be possible to stick with "list_token" instead of "list_token_name"? As we are already using the plugin, otherwise I'd need to take care of it with update hooks and proper config synchronization on quite a few installations. However I also understand that "list_token_name" is better regards consistency with other plugin configurations, so I'm also fine by using that.
- π©πͺGermany jurgenhaas Gottmadingen
TBH we do have the same situation the other way round, and I thought the consistency argument would weigh more here.
- π©πͺGermany mxh Offenburg
Just took another look. Actually the current name is "list_token" in the other plugins. For example in
Drupal\eca_base\Plugin\Action\ListCount
andDrupal\eca\Plugin\Action\ListOperationBase
. "list_token_name" is currently not used. - last update
over 1 year ago 284 pass - π©πͺGermany jurgenhaas Gottmadingen
That's really unfortunate. We're using
token_name
(almost) everywhere, but for the list related plugins, there islist_token
. My problem is that this is not a token, it's a token name. And we know from support that this is a huge source of confusion to when the token syntax needs to be used vs. just the token name.Now, the variable name is not so crucial for end users, that's more for the developers.
But the field label should NOT call this a token, it's a token name. So, we stick with the variable name
list_token
, but I've updated the label to make clear, it's the name of a token. - π©πͺGermany mxh Offenburg
Yes, definitely the label needs that explicit description as you now applied. I agree that "list_token" is not a good choice, "list_token_name" would be more consistent regards existing "token_name" keys.
- π©πͺGermany jurgenhaas Gottmadingen
As we are not in a good position to change that config key now, it looks like this is RTBC for MR!349?
- Status changed to Needs work
over 1 year ago 11:44am 30 April 2023 - π©πͺGermany mxh Offenburg
I'd say as always for new features, it needs test coverage.
- Assigned to danielspeicher
- last update
over 1 year ago 287 pass - π©πͺGermany danielspeicher Steisslingen
@mxh Hello Max, perhaps you can help me here.
I have written some tests for the standard lists containing by index and value.
Now I want to test the part where the value to check is an entity and the list is an instance of
EntityReferenceFieldItemListInterface
.How do I create such a constellation programmatically? For example, a node with a field containing an unlimited amount of
EntityReferences
. - π©πͺGermany mxh Offenburg
You can test this using nodes.
Sample code creating a multi-value entity reference field:
// Create the multi-value reference, using inlimited cardinality. $field_definition = FieldStorageConfig::create([ 'field_name' => 'field_node_multi', 'type' => 'entity_reference', 'entity_type' => 'node', 'settings' => [ 'target_type' => 'node', ], 'cardinality' => FieldStorageConfig::CARDINALITY_UNLIMITED, ]); $field_definition->save(); $field = FieldConfig::create([ 'field_storage' => $field_definition, 'label' => 'A multi-valued entity reference.', 'entity_type' => 'node', 'bundle' => 'article', ]); $field->save();
Then you can just create let's say three nodes, add the other two to the first one, and then add the nodes to the token service:
<?php $node1 = Node::create([...]); $node2 = Node::create([...]); $node3 = Node::create([...]); $node2->save(); $node3->save(); $node1->get('field_node_multi')->setValue([$node2, $node3]); $node1->save(); $this->token_services->addTokenData('node1', $node1); $this->token_services->addTokenData('node2', $node1); $this->token_services->addTokenData('node3', $node1); ?>
And then finally check with the condition plugin whether for example "node2" is contained in "[node:field_node_multi]". For that to make it work, it might be that you need to add the token module to the list of modules to install. But it could also be that it works already without it, not sure.
- πΊπΈUnited States mortona2k Seattle
I'm trying to use this to check if a media item is in an entity reference list. The list values is an array of media objects, and the value I want to match is the mid. Is it possible to specify that with tokens?
- π©πͺGermany jurgenhaas Gottmadingen
@mortona2k the list comes from an entity field, right? Then you can refer to that with
[node:field_NAME]
in the "Name of token containing the list" field.As for the value you want to lookup, you can use the Entity: load action to load the entity into a token of your own and then use that token in the value field.
- πΊπΈUnited States mortona2k Seattle
Thank you very much, I got it working as you described, using the field name token. I was trying to load the entity reference field values to use as a list before using this.
I actually had it working without this plugin, but it took a lot of extra logic loops. Basically I popped each item off the list and did a value comparison. This workflow is much simpler and easy to read now.
- Open on Drupal.org βCore: 10.0.7 + Environment: PHP 8.1 & MySQL 8last update
over 1 year ago Not currently mergeable. - last update
over 1 year ago 272 pass, 4 fail - last update
over 1 year ago 287 pass - last update
over 1 year ago 287 pass - last update
over 1 year ago 287 pass - last update
over 1 year ago 287 pass - last update
over 1 year ago 287 pass - last update
over 1 year ago 287 pass - last update
over 1 year ago 287 pass - last update
over 1 year ago 287 pass - last update
over 1 year ago 287 pass - last update
over 1 year ago 287 pass - Status changed to Needs review
over 1 year ago 3:04pm 5 June 2023 - π©πͺGermany danielspeicher Steisslingen
I have added another test for entity references.
@mxh Thanks for the input. It works great.
- Issue was unassigned.
- Status changed to RTBC
over 1 year ago 3:24pm 5 June 2023 - last update
over 1 year ago 287 pass - last update
over 1 year ago 287 pass -
jurgenhaas β
committed c74413d0 on 1.2.x authored by
mxh β
Issue #3352393 by danielspeicher, jurgenhaas, mxh: New condition:...
-
jurgenhaas β
committed c74413d0 on 1.2.x authored by
mxh β
- Status changed to Fixed
over 1 year ago 4:16pm 5 June 2023 Automatically closed - issue fixed for 2 weeks with no activity.
- Status changed to Fixed
over 1 year ago 11:22am 30 August 2023 - πΊπΈUnited States sascher
Hi thanks so much for this module.
I am confused by something though, I canβt find this condition when using the UI and I donβt see the code for list contains in the 1.14 version of the module
I see that docs were started here https://ecaguide.org/plugins/eca/base/conditions/eca_list_contains/
Am I missing something simple?
Thanks
- π©πͺGermany jurgenhaas Gottmadingen
Hi @sascher, new features are always going into the latest branch, which is 2.0.x - so, that's where that new plugin exists. The ECA Guide currently doesn't yet expose, in which version plugins got introduced, but we may change that hopefully soon, see π Annotate ECA plugins with version when they got introduced Active .
If you want to use that in your ECA 1.1 version, then you can apply the diff from the MR as a patch.
- πΊπΈUnited States sascher
Thanks @Jurgenhass. I tried applying the patch with composer to 1.1.4 version and got some errors. I will report back if I figure this out .
"drupal/eca": { "https://www.drupal.org/project/eca/issues/3352393": "https://git.drupalcode.org/project/eca/-/merge_requests/349.patch" }
some of the errors I got upon running cache clear were
In YamlSymfony.php line 40:
Duplicate key "eca.execution.render_subscriber" detected at line 107 (nea
r " - { name: event_subscriber }").
In Parser.php line 347:
Duplicate key "eca.execution.render_subscriber" detected at line 107 (nea
r " - { name: event_subscriber }").
- π©πͺGermany jurgenhaas Gottmadingen
Please use
https://git.drupalcode.org/project/eca/-/merge_requests/349.diff
instead ofhttps://git.drupalcode.org/project/eca/-/merge_requests/349.patch
as it only contains the effective changes, not the long history of commits. - πΊπΈUnited States sascher
Thanks @Jurgenhass I see the condition in there now!