You are here

protected function BulkForm::calculateEntityBulkFormKey in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/src/Plugin/views/field/BulkForm.php \Drupal\views\Plugin\views\field\BulkForm::calculateEntityBulkFormKey()
  2. 9 core/modules/views/src/Plugin/views/field/BulkForm.php \Drupal\views\Plugin\views\field\BulkForm::calculateEntityBulkFormKey()

Calculates a bulk form key.

This generates a key that is used as the checkbox return value when submitting a bulk form. This key allows the entity for the row to be loaded totally independent of the executed view row.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to calculate a bulk form key for.

bool $use_revision: Whether the revision id should be added to the bulk form key. This should be set to TRUE only if the view is listing entity revisions.

Return value

string The bulk form key representing the entity's id, language and revision (if applicable) as one string.

See also

self::loadEntityFromBulkFormKey()

1 call to BulkForm::calculateEntityBulkFormKey()
BulkForm::viewsForm in core/modules/views/src/Plugin/views/field/BulkForm.php
Form constructor for the bulk form.

File

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

Class

BulkForm
Defines an actions-based bulk operation form element.

Namespace

Drupal\views\Plugin\views\field

Code

protected function calculateEntityBulkFormKey(EntityInterface $entity, $use_revision) {
  $key_parts = [
    $entity
      ->language()
      ->getId(),
    $entity
      ->id(),
  ];
  if ($entity instanceof RevisionableInterface && $use_revision) {
    $key_parts[] = $entity
      ->getRevisionId();
  }

  // An entity ID could be an arbitrary string (although they are typically
  // numeric). JSON then Base64 encoding ensures the bulk_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);
}