abstract class PrintableFormatBase in Printer and PDF versions for Drupal 8+ 8
Same name and namespace in other branches
- 2.x src/Plugin/PrintableFormatBase.php \Drupal\printable\Plugin\PrintableFormatBase
Provides a base class for Filter plugins.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\printable\Plugin\PrintableFormatBase implements ContainerFactoryPluginInterface, PrintableFormatInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of PrintableFormatBase
2 files declare their use of PrintableFormatBase
- PdfFormat.php in modules/
printable_pdf/ src/ Plugin/ PrintableFormat/ PdfFormat.php - PrintFormat.php in src/
Plugin/ PrintableFormat/ PrintFormat.php
File
- src/
Plugin/ PrintableFormatBase.php, line 17
Namespace
Drupal\printable\PluginView source
abstract class PrintableFormatBase extends PluginBase implements PrintableFormatInterface, ContainerFactoryPluginInterface {
/**
* The config factory service.
*
* @var \Drupal\Core\Config\ConfigFactory
*/
protected $configFactory;
/**
* A render array of the content to be output by the printable format.
*
* @var array
*/
protected $content;
/**
* A string containing the list of links present in the page.
*
* @var string
*/
protected $footerContent;
/**
* Printable CSS include manager.
*
* @var \Drupal\printable\PrintableCssIncludeInterface
*/
protected $printableCssInclude;
/**
* Printable link extractor.
*
* @var \Drupal\printable\LinkExtractor\LinkExtractorInterface
*/
protected $linkExtractor;
/**
* {@inheritdoc}
*
* @param array $configuration
* The configuration array.
* @param string $plugin_id
* The plugin ID.
* @param array $plugin_definition
* The plugin definition.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory service.
* @param \Drupal\printable\PrintableCssIncludeInterface $printable_css_include
* The printable CSS include manager.
* @param \Drupal\printable\LinkExtractor\LinkExtractorInterface $link_extractor
* The link extractor.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, ConfigFactoryInterface $config_factory, PrintableCssIncludeInterface $printable_css_include, LinkExtractorInterface $link_extractor) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->configFactory = $config_factory;
$this->printableCssInclude = $printable_css_include;
$this->linkExtractor = $link_extractor;
$this->configuration += $this
->defaultConfiguration();
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('config.factory'), $container
->get('printable.css_include'), $container
->get('printable.link_extractor'));
}
/**
* {@inheritdoc}
*/
public function getLabel() {
return $this->pluginDefinition['title'];
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this->pluginDefinition['description'];
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [];
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return $this->configuration;
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$this->configuration = $configuration;
$this->configFactory
->getEditable('printable.format')
->set($this
->getPluginId(), $this->configuration)
->save();
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function setContent(array $content) {
$this->content = $content;
$this->footerContent = NULL;
if ($this->configFactory
->get('printable.settings')
->get('list_attribute')) {
$this->footerContent = $this->linkExtractor
->listAttribute((string) render($this->content));
}
}
/**
* {@inheritdoc}
*/
public function getResponse() {
return new Response($this
->getOutput());
}
/**
* Build a render array of the content, wrapped in the printable theme.
*
* @return array
* A render array representing the themed output of the content.
*/
protected function buildContent() {
$build = [
'#theme' => [
'printable__' . $this
->getPluginId(),
'printable',
],
'#header' => [
'#theme' => [
'printable_header__' . $this
->getPluginId(),
'printable_header',
],
'#logo_url' => theme_get_setting('logo.url'),
],
'#content' => $this->content,
'#footer' => [
'#theme' => [
'printable_footer__' . $this
->getPluginId(),
'printable_footer',
],
'#footer_content' => $this->footerContent,
],
];
if ($include_path = $this->printableCssInclude
->getCssIncludePath()) {
$build['#attached']['css'][] = $include_path;
}
return $build;
}
/**
* Extracts the links present in HTML string.
*
* @param string $content
* The HTML of the page to be added.
*
* @return string
* The HTML string with presence of links dependending on configuration.
*/
protected function extractLinks($content) {
if ($this->configFactory
->get('printable.settings')
->get('extract_links')) {
$rendered_page = $this->linkExtractor
->extract($content);
}
else {
$rendered_page = $this->linkExtractor
->removeAttribute($content, 'href');
}
return $rendered_page;
}
/**
* Get the HTML output of the whole page and pass to the response object.
*
* @return string
* The HTML string representing the output of this printable format.
*/
protected function getOutput() {
$content = $this
->buildContent();
// @todo add a renderer service over here.
return $this
->extractLinks(render($content));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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 | |
DependentPluginInterface:: |
public | function | Calculates dependencies for the configured plugin. | 19 |
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. | |
PluginFormInterface:: |
public | function | Form constructor. | 36 |
PluginFormInterface:: |
public | function | Form submission handler. | 32 |
PrintableFormatBase:: |
protected | property | The config factory service. | |
PrintableFormatBase:: |
protected | property | A render array of the content to be output by the printable format. | |
PrintableFormatBase:: |
protected | property | A string containing the list of links present in the page. | |
PrintableFormatBase:: |
protected | property | Printable link extractor. | |
PrintableFormatBase:: |
protected | property | Printable CSS include manager. | |
PrintableFormatBase:: |
protected | function | Build a render array of the content, wrapped in the printable theme. | |
PrintableFormatBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
1 |
PrintableFormatBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurablePluginInterface:: |
2 |
PrintableFormatBase:: |
protected | function | Extracts the links present in HTML string. | |
PrintableFormatBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurablePluginInterface:: |
|
PrintableFormatBase:: |
public | function |
Returns the administrative description for this format plugin. Overrides PrintableFormatInterface:: |
|
PrintableFormatBase:: |
public | function |
Returns the administrative label for this format plugin. Overrides PrintableFormatInterface:: |
|
PrintableFormatBase:: |
protected | function | Get the HTML output of the whole page and pass to the response object. | |
PrintableFormatBase:: |
public | function |
Returns the response object for this format plugin. Overrides PrintableFormatInterface:: |
1 |
PrintableFormatBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurablePluginInterface:: |
|
PrintableFormatBase:: |
public | function |
Set the content for the printable response. Overrides PrintableFormatInterface:: |
|
PrintableFormatBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
1 |
PrintableFormatBase:: |
public | function |
Overrides PluginBase:: |
1 |
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. |