You are here

protected function BulkForm::loadEntityFromBulkFormKey in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/views/field/BulkForm.php \Drupal\views\Plugin\views\field\BulkForm::loadEntityFromBulkFormKey()
  2. 10 core/modules/views/src/Plugin/views/field/BulkForm.php \Drupal\views\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/views/src/Plugin/views/field/BulkForm.php
Submit handler for the bulk form.

File

core/modules/views/src/Plugin/views/field/BulkForm.php, line 534

Class

BulkForm
Defines a actions-based bulk operation form element.

Namespace

Drupal\views\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->entityTypeManager
    ->getStorage($this
    ->getEntityType());
  $entity = $revision_id ? $storage
    ->loadRevision($revision_id) : $storage
    ->load($id);
  if ($entity instanceof TranslatableInterface) {
    $entity = $entity
      ->getTranslation($langcode);
  }
  return $entity;
}