You are here

public static function FillPdfLinkManipulator::prepareEntityIds in FillPDF 5.0.x

Same name and namespace in other branches
  1. 8.4 src/Service/FillPdfLinkManipulator.php \Drupal\fillpdf\Service\FillPdfLinkManipulator::prepareEntityIds()

Helper method preparing entity IDs for link generation.

@internal

Parameters

array $parameters: Array of parameters.

Return value

array An associative array of entity IDs.

2 calls to FillPdfLinkManipulator::prepareEntityIds()
FillPdfLinkManipulator::generateLink in src/Service/FillPdfLinkManipulator.php
Generates a FillPdf Url from the given parameters.
ParseEntityIdsTest::testEntityIds in tests/src/Unit/LinkManipulator/ParseEntityIdsTest.php
Tests parsing entity IDs from query parameters and back.

File

src/Service/FillPdfLinkManipulator.php, line 234

Class

FillPdfLinkManipulator

Namespace

Drupal\fillpdf\Service

Code

public static function prepareEntityIds(array $parameters) {
  $query = [];
  if (empty($parameters['entity_ids'])) {
    return $query;
  }

  // $parameters['entity_ids'] contains entity IDs indexed by entity type.
  // Collapse these into the entity_type:entity_id format.
  $entity_ids = [];
  foreach ($parameters['entity_ids'] as $entity_type => $type_ids) {
    foreach ($type_ids as $entity_id) {
      $entity_ids[] = "{$entity_type}:{$entity_id}";
    }
  }
  switch (count($entity_ids)) {
    case 0:
      break;
    case 1:
      $query['entity_id'] = reset($entity_ids);
      break;
    default:
      $query['entity_ids'] = $entity_ids;
  }
  return $query;
}