class PrintableConfigurationForm in Printer and PDF versions for Drupal 8+ 8
Same name and namespace in other branches
- 2.x src/Form/PrintableConfigurationForm.php \Drupal\printable\Form\PrintableConfigurationForm
Provides shared configuration form for all printable formats.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\printable\Form\PrintableConfigurationForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of PrintableConfigurationForm
1 string reference to 'PrintableConfigurationForm'
File
- src/
Form/ PrintableConfigurationForm.php, line 15
Namespace
Drupal\printable\FormView source
class PrintableConfigurationForm extends ConfigFormBase {
/**
* The printable entity manager.
*
* @var \Drupal\printable\PrintableEntityManagerInterface
*/
protected $printableEntityManager;
/**
* The config factory service.
*
* @var \Drupal\Core\Config\ConfigFactory
*/
protected $configFactory;
/**
* The block manager service.
*
* @var \Drupal\Core\Block\BlockManager
*/
protected $blockManager;
/**
* Constructs a new form object.
*
* @param \Drupal\printable\PrintableEntityManagerInterface $printable_entity_manager
* The printable entity manager.
* @param \Drupal\Core\Config\ConfigFactory $configFactory
* Defines the configuration object factory.
* @param \Drupal\Core\Block\BlockManager $blockManager
* Manages discovery and instantiation of block plugins.
*/
public function __construct(PrintableEntityManagerInterface $printable_entity_manager, ConfigFactory $configFactory, BlockManager $blockManager) {
$this->printableEntityManager = $printable_entity_manager;
$this->configFactory = $configFactory;
$this->blockManager = $blockManager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('printable.entity_manager'), $container
->get('config.factory'), $container
->get('plugin.manager.block'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'printable_configuration';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'printable.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $printable_format = NULL) {
// Allow users to choose what entities printable is enabled for.
$form['settings']['printable_entities'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Printable Enabled Entities'),
'#description' => $this
->t('Select the entities that printable support should be enabled for.'),
'#options' => [],
'#default_value' => [],
];
// Build the options array.
foreach ($this->printableEntityManager
->getCompatibleEntities() as $entity_type => $entity_definition) {
$form['settings']['printable_entities']['#options'][$entity_type] = $entity_definition
->getLabel();
}
// Build the default values array.
foreach ($this->printableEntityManager
->getPrintableEntities() as $entity_type => $entity_definition) {
$form['settings']['printable_entities']['#default_value'][] = $entity_type;
}
// Provide option to open printable page in a new tab/window.
$form['settings']['open_target_blank'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Open in New Tab'),
'#description' => $this
->t('Open the printable version in a new tab/window.'),
'#default_value' => $this
->config('printable.settings')
->get('open_target_blank'),
];
// Allow users to include CSS from the current theme.
$form['settings']['css_include'] = [
'#type' => 'textfield',
'#title' => $this
->t('CSS Include'),
'#description' => $this
->t('Specify an additional CSS file to include. Relative to the root of the Drupal install. The token <em>[theme:theme_machine_name]</em> is available.'),
'#default_value' => $this
->config('printable.settings')
->get('css_include'),
];
// Provide option to turn off link extraction.
$form['settings']['extract_links'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Extract Links'),
'#description' => $this
->t('Extract any links in the content, e.g. "Some Link (http://drupal.org)'),
'#default_value' => $this
->config('printable.settings')
->get('extract_links'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->configFactory
->getEditable('printable.settings')
->set('printable_entities', $form_state
->getValue('printable_entities'))
->set('open_target_blank', $form_state
->getValue('open_target_blank'))
->set('css_include', $form_state
->getValue('css_include'))
->set('extract_links', $form_state
->getValue('extract_links'))
->save();
// Invalidate the block cache to update custom block-based derivatives.
// @todo try to make configsaveevent later.
$this->blockManager
->clearCachedDefinitions();
parent::submitForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
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 | |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PrintableConfigurationForm:: |
protected | property | The block manager service. | |
PrintableConfigurationForm:: |
protected | property |
The config factory service. Overrides FormBase:: |
|
PrintableConfigurationForm:: |
protected | property | The printable entity manager. | |
PrintableConfigurationForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
PrintableConfigurationForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
PrintableConfigurationForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
PrintableConfigurationForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
PrintableConfigurationForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
PrintableConfigurationForm:: |
public | function |
Constructs a new form object. Overrides ConfigFormBase:: |
|
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
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. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |