function FieldItemList::delegateMethod

Same name in other branches
  1. 9 core/lib/Drupal/Core/Field/FieldItemList.php \Drupal\Core\Field\FieldItemList::delegateMethod()
  2. 8.9.x core/lib/Drupal/Core/Field/FieldItemList.php \Drupal\Core\Field\FieldItemList::delegateMethod()
  3. 11.x core/lib/Drupal/Core/Field/FieldItemList.php \Drupal\Core\Field\FieldItemList::delegateMethod()

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.

4 calls to FieldItemList::delegateMethod()
FieldItemList::delete in core/lib/Drupal/Core/Field/FieldItemList.php
Defines custom delete behavior for field values.
FieldItemList::deleteRevision in core/lib/Drupal/Core/Field/FieldItemList.php
Defines custom revision delete behavior for field values.
FieldItemList::postSave in core/lib/Drupal/Core/Field/FieldItemList.php
Defines custom post-save behavior for field values.
FieldItemList::preSave in core/lib/Drupal/Core/Field/FieldItemList.php
Defines custom presave behavior for field values.

File

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

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.