protected function DiffPluginBase::loadEntityFromDiffFormKey in Diff 8
Loads an entity based on a diff form key.
Parameters
string $diff_form_key: The diff 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 diff form key.
Throws
\UnexpectedValueException If no entity can be found for the given diff form key.
1 call to DiffPluginBase::loadEntityFromDiffFormKey()
- DiffFrom::viewsFormSubmit in src/
Plugin/ views/ field/ DiffFrom.php - Submit handler for the bulk form.
File
- src/
Plugin/ views/ field/ DiffPluginBase.php, line 137
Class
- DiffPluginBase
- Base class for diff view field plugins.
Namespace
Drupal\diff\Plugin\views\fieldCode
protected function loadEntityFromDiffFormKey($diff_form_key) {
$key = base64_decode($diff_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 (empty($entity)) {
throw new \UnexpectedValueException('Entity not found: ' . $diff_form_key);
}
if ($entity instanceof TranslatableInterface) {
$entity = $entity
->getTranslation($langcode);
}
return $entity;
}