function BulkForm::loadEntityFromBulkFormKey
Same name in other branches
- 9 core/modules/views/src/Plugin/views/field/BulkForm.php \Drupal\views\Plugin\views\field\BulkForm::loadEntityFromBulkFormKey()
- 10 core/modules/views/src/Plugin/views/field/BulkForm.php \Drupal\views\Plugin\views\field\BulkForm::loadEntityFromBulkFormKey()
- 11.x 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\fieldCode
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.