FlipbookListBuilder.php in 3D Flipbook 8
File
src/Entity/Controller/FlipbookListBuilder.php
View source
<?php
namespace Drupal\flipbook\Entity\Controller;
use Drupal\image\Entity\ImageStyle;
use Drupal\file\Entity\File;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Render\Markup;
class FlipbookListBuilder extends EntityListBuilder {
public function render() {
$build['description'] = [
'#markup' => $this
->t('Flipbook Entity Example implements a Flipbooks model. These flipbooks are fieldable entities. You can manage the fields on the <a href="@adminlink">Flipbook admin page</a>.', [
'@adminlink' => \Drupal::urlGenerator()
->generateFromRoute('flipbook.settings'),
]),
];
$build += parent::render();
return $build;
}
public function buildHeader() {
$header['id'] = $this
->t('FlipbookID');
$header['name'] = $this
->t('Name');
$header['flipbook_cover'] = $this
->t('FlipBook Cover');
$header['flipbook'] = $this
->t('Flipbook Pdf');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row['id'] = $entity
->id();
$row['name'] = $entity
->link();
$fid = $entity->flipbook_cover->target_id;
$pid = $entity->flipbook->target_id;
$file = File::load($fid);
$pfile = File::load($pid);
$path = $file
->getFileUri();
$pdfpath = file_create_url($pfile
->getFileUri());
$fname = $file
->getFilename();
$pname = $pfile
->getFilename();
$url = ImageStyle::load('large')
->buildUrl($path);
$row['flipbook_cover'] = Markup::create('<a href=' . $url . ' target="_blank">' . $fname . '</a>');
$row['flipbook'] = Markup::create('<a href=' . $pdfpath . ' target="_blank">' . $pname . '</a>');
return $row + parent::buildRow($entity);
}
}