QRController.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace Drupal\materio_expo\Controller;
  3. use Drupal\Core\Controller\ControllerBase;
  4. use Symfony\Component\HttpFoundation\RedirectResponse;
  5. use Drupal\Core\Url;
  6. /**
  7. * Class QRController.
  8. */
  9. class QRController extends ControllerBase {
  10. /**
  11. * Hello.
  12. *
  13. * @return string
  14. * Return Hello string.
  15. */
  16. public function getfile($ref) {
  17. //? https://drupal.stackexchange.com/questions/255216/how-to-do-a-redirectresponse-with-a-destination-query-parameter
  18. //* get node from ref
  19. $entity_storage = \Drupal::entityTypeManager()->getStorage('node');
  20. $query = $entity_storage->getQuery()
  21. ->condition('type', 'materiau')
  22. ->condition('status', '1')
  23. ->condition('field_reference', $ref);
  24. $results = $query->execute();
  25. $nid = array_pop($results);
  26. $node = $entity_storage->load($nid);
  27. //* get file from node
  28. $file = $node->get('field_fiche_expo')->referencedEntities()[0];
  29. //* redirect to file
  30. return new RedirectResponse($file->createFileUrl());
  31. // return [
  32. // '#type' => 'markup',
  33. // '#markup' => $this->t("Implement method: getfile with parameter(s): $ref"),
  34. // ];
  35. }
  36. }