You are here

protected function DataListItemAdd::doExecute in Rules 8.3

Add an item to a list.

Parameters

array $list: A list to which an item is added.

mixed $item: An item being added to the list.

bool $unique: (optional) Whether or not we can add duplicate items.

string $position: (optional) Determines if item will be added at beginning or end. Allowed values:

  • "start": Add to beginning of the list.
  • "end": Add to end of the list.

File

src/Plugin/RulesAction/DataListItemAdd.php, line 58

Class

DataListItemAdd
Provides an 'Add list item' action.

Namespace

Drupal\rules\Plugin\RulesAction

Code

protected function doExecute(array $list, $item, $unique = FALSE, $position = 'end') {

  // Optionally, only add the list item if it is not yet contained.
  if (!((bool) $unique && in_array($item, $list))) {
    if ($position === 'start') {
      array_unshift($list, $item);
    }
    else {
      $list[] = $item;
    }
  }
  $this
    ->setContextValue('list', $list);
}