You are here

public static function ViewsBulkOperationsBulkForm::calculateEntityBulkFormKey in Views Bulk Operations (VBO) 8

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 independently 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.

int $row_index: Index of the views row that contains the entity.

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 ViewsBulkOperationsBulkForm::calculateEntityBulkFormKey()
ViewsBulkOperationsBulkForm::viewsForm in src/Plugin/views/field/ViewsBulkOperationsBulkForm.php
Form constructor for the bulk form.

File

src/Plugin/views/field/ViewsBulkOperationsBulkForm.php, line 768

Class

ViewsBulkOperationsBulkForm
Defines the Views Bulk Operations field plugin.

Namespace

Drupal\views_bulk_operations\Plugin\views\field

Code

public static function calculateEntityBulkFormKey(EntityInterface $entity, $use_revision, $row_index) {
  $key_parts = [
    $row_index,
    $entity
      ->language()
      ->getId(),
    $entity
      ->getEntityTypeId(),
    $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);
}