class PrintableLinkBuilder in Printer and PDF versions for Drupal 8+ 8
Same name and namespace in other branches
- 2.x src/PrintableLinkBuilder.php \Drupal\printable\PrintableLinkBuilder
Helper class for the printable module.
Hierarchy
- class \Drupal\printable\PrintableLinkBuilder implements PrintableLinkBuilderInterface
Expanded class hierarchy of PrintableLinkBuilder
1 file declares its use of PrintableLinkBuilder
- PrintableLinkBuilderTest.php in tests/
src/ Unit/ PrintableLinkBuilderTest.php
1 string reference to 'PrintableLinkBuilder'
1 service uses PrintableLinkBuilder
File
- src/
PrintableLinkBuilder.php, line 12
Namespace
Drupal\printableView source
class PrintableLinkBuilder implements PrintableLinkBuilderInterface {
/**
* The config factory service.
*
* @var \Drupal\Core\Config\ConfigFactory
*/
protected $configFactory;
/**
* The URL generator service.
*
* @var \Drupal\Core\Routing\UrlGeneratorInterface
*/
protected $urlGenerator;
/**
* The printable format plugin manager.
*
* @var \Drupal\printable\PrintableFormatPluginManager
*/
protected $printableFormatManager;
/**
* Constructs a new PrintableLinkBuilder object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory service.
* @param \Drupal\printable\PrintableFormatPluginManager $printable_format_manager
* The printable format plugin manager.
*/
public function __construct(ConfigFactoryInterface $config_factory, PrintableFormatPluginManager $printable_format_manager) {
$this->configFactory = $config_factory;
$this->printableFormatManager = $printable_format_manager;
}
/**
* {@inheritdoc}
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PrintableLinkBuilder:: |
protected | property | The config factory service. | |
PrintableLinkBuilder:: |
protected | property | The printable format plugin manager. | |
PrintableLinkBuilder:: |
protected | property | The URL generator service. | |
PrintableLinkBuilder:: |
public | function |
Build a render array of the printable links for a given entity. Overrides PrintableLinkBuilderInterface:: |
|
PrintableLinkBuilder:: |
public | function | Constructs a new PrintableLinkBuilder object. |