You are here

protected function MinisiteItemList::delegateMethodForItemList in Mini site 8

Delegate method for an items list.

Works in the same way as \Drupal\Core\Field\EntityReferenceFieldItemList::delegateMethod(), but with supplied items list object.

Any argument passed will be forwarded to the invoked method.

Parameters

string $method: The method name to call for each item in the list.

\Drupal\Core\Field\FieldItemList $item_list: The items list to traverse.

Return value

array An array of results keyed by delta.

See also

\Drupal\Core\Field\FieldItemList::delegateMethod()

1 call to MinisiteItemList::delegateMethodForItemList()
MinisiteItemList::postSave in src/Plugin/Field/FieldType/MinisiteItemList.php
Defines custom post-save behavior for field values.

File

src/Plugin/Field/FieldType/MinisiteItemList.php, line 89

Class

MinisiteItemList
Class MinisiteItemList.

Namespace

Drupal\minisite\Plugin\Field\FieldType

Code

protected function delegateMethodForItemList($method, FieldItemList $item_list) {
  $result = [];
  $args = array_slice(func_get_args(), 2);
  foreach ($item_list->list as $delta => $item) {

    // call_user_func_array() is way slower than a direct call so we avoid
    // using it if have no parameters.
    $result[$delta] = $args ? call_user_func_array([
      $item,
      $method,
    ], $args) : $item
      ->{$method}();
  }
  return $result;
}