Problem/Motivation

I would like to add remove Referenced Entities to and from appropriate entity fields which can contain more than one reference.

Steps to reproduce

Proposed resolution

Have two Reaction rules one to add and the other to remove. They both take the entity type id . field name as one parameter and the other is the entity to add or remove. The Load entity by id functionality is one way of determining the entity.

Remaining tasks

Add tests.

User interface changes

None

API changes

None

Data model changes

None

Issue fork rules-3198011

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

somersoft created an issue. See original summary.

tr’s picture

Issue tags: -entity references
tr’s picture

Status: Needs review » Needs work

Your patch had six coding standards problems - see the test output.

Why can't you use DataListItemAdd for this?

somersoft’s picture

For the two new files I have update the code to following coding styles.

I tried to use DataListItemAdd and DataListItemRemove but could not work out what to put in the list box to produce an array from a field for example a list of target_id if the field references multiple other same entities. It may be that those two functions need to change but I do not want to break rules that currently use them.

Please advise if there is away to use DataListItemAdd and DataListItemRemove.

tr’s picture

Status: Needs work » Needs review

Set to needs review to trigger testing

Tramb’s picture

The patch #3 does not work for me (a user list item field).
I propose a patch for the list item remove functionnality, that can take an array or a FieldItemList now.

But it only works on PHP 8.x due to union types.
It works on my 9.4 Drupal.

somersoft’s picture

StatusFileSize
new4.96 KB

Rerolled for PHP 8.1

somersoft’s picture

The Add functionality was not working and it has been updated in the fork.

somersoft’s picture

Removed patch as it is now out of date.