You are here

protected function ContentEntityStorageBase::invokeFieldMethod in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::invokeFieldMethod()

Invokes a method on the Field objects within an entity.

Any argument passed will be forwarded to the invoked method.

Parameters

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

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity object.

Return value

array A multidimensional associative array of results, keyed by entity translation language code and field name.

4 calls to ContentEntityStorageBase::invokeFieldMethod()
ContentEntityStorageBase::deleteRevision in core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php
Delete a specific entity revision.
ContentEntityStorageBase::doDelete in core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php
Performs storage-specific entity deletion.
ContentEntityStorageBase::invokeFieldPostSave in core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php
Invokes the post save method on the Field objects within an entity.
ContentEntityStorageBase::invokeHook in core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php
Invokes a hook on behalf of the entity.

File

core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php, line 440
Contains \Drupal\Core\Entity\ContentEntityStorageBase.

Class

ContentEntityStorageBase
Base class for content entity storage handlers.

Namespace

Drupal\Core\Entity

Code

protected function invokeFieldMethod($method, ContentEntityInterface $entity) {
  $result = [];
  $args = array_slice(func_get_args(), 2);
  foreach (array_keys($entity
    ->getTranslationLanguages()) as $langcode) {
    $translation = $entity
      ->getTranslation($langcode);

    // For non translatable fields, there is only one field object instance
    // across all translations and it has as parent entity the entity in the
    // default entity translation. Therefore field methods on non translatable
    // fields should be invoked only on the default entity translation.
    $fields = $translation
      ->isDefaultTranslation() ? $translation
      ->getFields() : $translation
      ->getTranslatableFields();
    foreach ($fields as $name => $items) {

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