You are here

protected function SearchApiBulkForm::calculateEntityBulkFormKey in Search API 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 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.

Overrides BulkForm::calculateEntityBulkFormKey

See also

self::loadEntityFromBulkFormKey()

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

File

src/Plugin/views/field/SearchApiBulkForm.php, line 237

Class

SearchApiBulkForm
Defines an actions-based bulk operation form element.

Namespace

Drupal\search_api\Plugin\views\field

Code

protected function calculateEntityBulkFormKey(EntityInterface $entity, $use_revision) {
  $parent_value = parent::calculateEntityBulkFormKey($entity, $use_revision);
  $bulk_form_key = json_decode(base64_decode($parent_value));

  // Rows of Search API views, based on entity datasources, might have
  // different entity types. We add the entity type ID to the bulk form key.
  array_unshift($bulk_form_key, $entity
    ->getEntityTypeId());
  $key = json_encode($bulk_form_key);
  return base64_encode($key);
}