protected function SearchApiBulkForm::loadEntityFromBulkFormKey in Search API 8
Loads an entity based on a bulk form key.
This is a slightly changed copy of the parent's method, except that the entity type ID is not view based but is extracted from the 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.
Throws
\Drupal\Component\Plugin\Exception\PluginNotFoundException Thrown if the entity type doesn't exist.
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException Thrown if the storage handler couldn't be loaded.
Overrides BulkForm::loadEntityFromBulkFormKey
1 call to SearchApiBulkForm::loadEntityFromBulkFormKey()
- SearchApiBulkForm::viewsFormValidate in src/
Plugin/ views/ field/ SearchApiBulkForm.php
File
- src/
Plugin/ views/ field/ SearchApiBulkForm.php, line 266
Class
- SearchApiBulkForm
- Defines an actions-based bulk operation form element.
Namespace
Drupal\search_api\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 4 items, the revision ID will be last.
if (count($key_parts) === 4) {
$revision_id = array_pop($key_parts);
}
// The first three items will always be the entity type, langcode and ID.
list($entity_type_id, $langcode, $id) = $key_parts;
// Load the entity or a specific revision depending on the given key.
$storage = $this->entityTypeManager
->getStorage($entity_type_id);
$entity = $revision_id ? $storage
->loadRevision($revision_id) : $storage
->load($id);
if ($entity instanceof TranslatableInterface) {
$entity = $entity
->getTranslation($langcode);
}
return $entity;
}