protected function DiffPluginBase::calculateEntityDiffFormKey in Diff 8
Calculates a diff form key.
This generates a key that is used as the checkbox return value when submitting a diff form. This key allows the entity for the row to be loaded totally independently of the executed view row.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity to calculate a diff form key for.
Return value
string The diff form key representing the entity's id, language and revision (if applicable) as one string.
See also
self::loadEntityFromDiffFormKey()
1 call to DiffPluginBase::calculateEntityDiffFormKey()
- DiffPluginBase::viewsForm in src/
Plugin/ views/ field/ DiffPluginBase.php
File
- src/
Plugin/ views/ field/ DiffPluginBase.php, line 109
Class
- DiffPluginBase
- Base class for diff view field plugins.
Namespace
Drupal\diff\Plugin\views\fieldCode
protected function calculateEntityDiffFormKey(EntityInterface $entity) {
$key_parts = [
$entity
->language()
->getId(),
$entity
->id(),
];
if ($entity instanceof RevisionableInterface) {
$key_parts[] = $entity
->getRevisionId();
}
// An entity ID could be an arbitrary string (although they are typically
// numeric). JSON then Base64 encoding ensures the diff_form_key is
// safe to use in HTML, and that the key parts can be retrieved.
$key = Json::encode($key_parts);
return base64_encode($key);
}