getSession(); $alreadysetemail = $session->get('materio_expo_email'); if($alreadysetemail){ //* get node from ref $entity_storage = \Drupal::entityTypeManager()->getStorage('node'); $query = $entity_storage->getQuery() ->condition('type', 'materiau') ->condition('status', '1') ->condition('field_reference', $ref); $results = $query->execute(); $nid = array_pop($results); $node = $entity_storage->load($nid); //* get file from node $file = $node->get('field_fiche_expo')->referencedEntities()[0]; //* redirect to file return new RedirectResponse($file->createFileUrl()); // return [ // '#type' => 'markup', // '#markup' => $this->t("Error, email not provided"), // ]; } else { // return [ // '#type' => 'markup', // '#markup' => $this->t("Error, email not provided"), // ]; $url = Url::fromRoute('materio_expo.get_email', ['ref'=>$ref]); return new RedirectResponse($url->toString()); } } }