0

i am using below code to show content in admincontroller of my module but $filelink is show as text instead of html

i tried to show href link in $filelink but it renders and text content like below:

<a href='abc/pdf_2.pdf' target='_blank'>Resume</a>  

but i want it as

Resume

  function content() {
    $url = Url::fromRoute('bd_career_add');
    //$add_link = ;
    $add_link = '<p>' . \Drupal::l(t('New Submission'), $url) . '</p>';

    $text = array(
      '#type' => 'markup',
      '#markup' => $add_link,
    );

    // Table header.
    $header = array(
      'id' => t('Id'),
      'name' => t('Name'),
      'number' => t('Number'),
      'email' => t('Email'),
      'email' => t('Resume'),
      'operations' => t('Delete'),
    );
    $rows = array();
    foreach (BdCareerStorage::getAll() as $id => $content) {
      // Row with attributes on the row and some of its cells.
      $editUrl = Url::fromRoute('bd_career_edit', array('id' => $id));
      $deleteUrl = Url::fromRoute('bd_career_delete', array('id' => $id));

    $file = \Drupal\file\Entity\File::load($content->resumefid);
    $filelink ="<a href='".file_create_url($file->getFileUri())."' target='_blank'>Resume</a>";

      $rows[] = array(
        'data' => array(
          \Drupal::l($id, $editUrl),
          $content->name.' '.$content->lname,$content->number,$filelink,
          \Drupal::l('Delete', $deleteUrl)
        ),
      );
    }
    $table = array(
      '#type' => 'table',
      '#header' => $header,
      '#rows' => $rows,
      '#attributes' => array(
        'id' => 'bd-career-table',
      ),
    );
    //return $add_link . ($table);
    return array(
      $text,
      $table,
    );
  }
3
  • try this : $row[] = array( 'data' => array( '#links' => $links), ); Commented Oct 10, 2016 at 11:01
  • whats the output Commented Oct 10, 2016 at 11:26
  • i used '#links' => $filelinkin place of $filelink it show blank value
    – gaurav
    Commented Oct 10, 2016 at 11:28

1 Answer 1

0

solved it using below code:

$file = \Drupal\file\Entity\File::load($content->resumefid);
$filelink = file_create_url($file->getFileUri());

$url = Url::fromUri($filelink);
$external_link = \Drupal::l(t('Download Resume'), $url);

  $rows[] = array(
    'data' => array(
      \Drupal::l($id, $editUrl),
      $content->name.' '.$content->lname,$content->number,$external_link,
      \Drupal::l('Delete', $deleteUrl)
    ),

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.