You are here

public function PrintableLinkBuilder::buildLinks in Printer and PDF versions for Drupal 8+ 8

Same name and namespace in other branches
  1. 2.x src/PrintableLinkBuilder.php \Drupal\printable\PrintableLinkBuilder::buildLinks()

Build a render array of the printable links for a given entity.

Parameters

Drupal\Core\Entity\EntityInterface $entity: The entity to build the printable links for.

Return value

array The render array of printable links for the passed in entity.

Overrides PrintableLinkBuilderInterface::buildLinks

File

src/PrintableLinkBuilder.php, line 51

Class

PrintableLinkBuilder
Helper class for the printable module.

Namespace

Drupal\printable

Code

public function buildLinks(EntityInterface $entity = NULL) {
  $links = [];
  $printable_settings = $this->configFactory
    ->get('printable.settings');

  // Build the array of links to be added to the entity.
  foreach ($this->printableFormatManager
    ->getDefinitions() as $key => $definition) {
    $links[$key] = [
      'title' => $definition['title'],
      'url' => Url::fromRoute('printable.show_format.' . $entity
        ->getEntityTypeId(), [
        'printable_format' => $key,
        'entity' => $entity
          ->id(),
      ]),
    ];

    // Add target "blank" if the configuration option is set.
    if ($printable_settings
      ->get('open_target_blank') && ($key == 'print' or !$printable_settings
      ->get('save_pdf'))) {
      $links[$key]['attributes']['target'] = '_blank';
    }
  }
  return $links;
}