protected function FieldItemList::delegateMethod

protected FieldItemList::delegateMethod($method)

Calls a method on each FieldItem.

Any argument passed will be forwarded to the invoked method.

Parameters

string $method: The name of the method to be invoked.

Return value

array An array of results keyed by delta.

File

core/lib/Drupal/Core/Field/FieldItemList.php, line 238

Class

FieldItemList
Represents an entity field; that is, a list of field item objects.

Namespace

Drupal\Core\Field

Code

protected function delegateMethod($method) {
  $result = [];
  $args = array_slice(func_get_args(), 1);
  foreach ($this->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;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Field!FieldItemList.php/function/FieldItemList::delegateMethod/8.1.x