class PrintDownload in Entity Print 8.2
Downloads the Printed entity.
@Action( id = "entity_print_download_action", label = @Translation("Print"), type = "node" )
@TODO, support multiple entity types once core is fixed.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\Core\Action\ActionBase implements ActionInterface
- class \Drupal\Core\Action\ConfigurableActionBase implements ConfigurableInterface, ConfigurablePluginInterface, DependentPluginInterface, PluginFormInterface
- class \Drupal\entity_print\Plugin\Action\PrintDownload implements ContainerFactoryPluginInterface
- class \Drupal\Core\Action\ConfigurableActionBase implements ConfigurableInterface, ConfigurablePluginInterface, DependentPluginInterface, PluginFormInterface
- class \Drupal\Core\Action\ActionBase implements ActionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of PrintDownload
See also
https://www.drupal.org/node/2011038
File
- src/
Plugin/ Action/ PrintDownload.php, line 31
Namespace
Drupal\entity_print\Plugin\ActionView source
class PrintDownload extends ConfigurableActionBase implements ContainerFactoryPluginInterface {
/**
* Access manager.
*
* @var \Drupal\Core\Access\AccessManagerInterface
*/
protected $accessManager;
/**
* The Print builder service.
*
* @var \Drupal\entity_print\PrintBuilderInterface
*/
protected $printBuilder;
/**
* The Entity Print plugin manager.
*
* @var \Drupal\entity_print\Plugin\EntityPrintPluginManagerInterface
*/
protected $entityPrintPluginManager;
/**
* The export type manager.
*
* @var \Drupal\entity_print\Plugin\ExportTypeManagerInterface
*/
protected $exportTypeManager;
/**
* The Print engine implementation.
*
* @var \Drupal\entity_print\Plugin\PrintEngineInterface
*/
protected $printEngine;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, AccessManagerInterface $access_manager, PrintBuilderInterface $print_builder, PluginManagerInterface $entity_print_plugin_manager, ExportTypeManagerInterface $export_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->accessManager = $access_manager;
$this->printBuilder = $print_builder;
$this->entityPrintPluginManager = $entity_print_plugin_manager;
$this->exportTypeManager = $export_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('access_manager'), $container
->get('entity_print.print_builder'), $container
->get('plugin.manager.entity_print.print_engine'), $container
->get('plugin.manager.entity_print.export_type'));
}
/**
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
/** @var \Drupal\node\NodeInterface $object */
$route_params = [
'export_type' => $this->configuration['export_type'],
'entity_id' => $object
->id(),
'entity_type' => $object
->getEntityTypeId(),
];
return $this->accessManager
->checkNamedRoute('entity_print.view', $route_params, $account, $return_as_object);
}
/**
* {@inheritdoc}
*/
public function execute($entity = NULL) {
$this
->executeMultiple([
$entity,
]);
}
/**
* {@inheritdoc}
*/
public function executeMultiple(array $entities) {
try {
(new StreamedResponse(function () use ($entities) {
$this->printBuilder
->deliverPrintable($entities, $this->entityPrintPluginManager
->createSelectedInstance($this->configuration['export_type']), TRUE);
}))
->send();
} catch (PrintEngineException $e) {
$this
->messenger()
->addError(new FormattableMarkup(Xss::filter($e
->getMessage()), []));
}
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['export_type'] = [
'#type' => 'select',
'#title' => $this
->t('Export type'),
'#options' => $this->exportTypeManager
->getFormOptions(),
'#required' => TRUE,
'#default_value' => !empty($this->configuration['export_type']) ? $this->configuration['export_type'] : NULL,
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['export_type'] = $form_state
->getValue('export_type');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigurableActionBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
1 |
ConfigurableActionBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
8 |
ConfigurableActionBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
ConfigurableActionBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
ConfigurableActionBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
2 |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PrintDownload:: |
protected | property | Access manager. | |
PrintDownload:: |
protected | property | The Entity Print plugin manager. | |
PrintDownload:: |
protected | property | The export type manager. | |
PrintDownload:: |
protected | property | The Print builder service. | |
PrintDownload:: |
protected | property | The Print engine implementation. | |
PrintDownload:: |
public | function |
Checks object access. Overrides ActionInterface:: |
|
PrintDownload:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
|
PrintDownload:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
PrintDownload:: |
public | function |
Executes the plugin. Overrides ExecutableInterface:: |
|
PrintDownload:: |
public | function |
Executes the plugin for an array of objects. Overrides ActionBase:: |
|
PrintDownload:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
PrintDownload:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides ConfigurableActionBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |