You are here

protected function BulkForm::loadEntityFromBulkFormKey in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Plugin/views/field/BulkForm.php \Drupal\system\Plugin\views\field\BulkForm::loadEntityFromBulkFormKey()

Loads an entity based on a bulk form key.

Parameters

string $bulk_form_key: The bulk form key representing the entity's id, language and revision (if applicable) as one string.

Return value

\Drupal\Core\Entity\EntityInterface The entity loaded in the state (language, optionally revision) specified as part of the bulk form key.

1 call to BulkForm::loadEntityFromBulkFormKey()
BulkForm::viewsFormSubmit in core/modules/system/src/Plugin/views/field/BulkForm.php
Submit handler for the bulk form.

File

core/modules/system/src/Plugin/views/field/BulkForm.php, line 485
Contains \Drupal\system\Plugin\views\field\BulkForm.

Class

BulkForm
Defines a actions-based bulk operation form element.

Namespace

Drupal\system\Plugin\views\field

Code

protected function loadEntityFromBulkFormKey($bulk_form_key) {
  $key = base64_decode($bulk_form_key);
  $key_parts = json_decode($key);
  $revision_id = NULL;

  // If there are 3 items, vid will be last.
  if (count($key_parts) === 3) {
    $revision_id = array_pop($key_parts);
  }

  // The first two items will always be langcode and ID.
  $id = array_pop($key_parts);
  $langcode = array_pop($key_parts);

  // Load the entity or a specific revision depending on the given key.
  $storage = $this->entityManager
    ->getStorage($this
    ->getEntityType());
  $entity = $revision_id ? $storage
    ->loadRevision($revision_id) : $storage
    ->load($id);
  if ($entity instanceof TranslatableInterface) {
    $entity = $entity
      ->getTranslation($langcode);
  }
  return $entity;
}