You are here

public function PdfEngineBase::buildConfigurationForm in Entity Print 8.2

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

array $form: An associative array containing the initial structure of the plugin form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Return value

array The form structure.

Overrides PrintEngineBase::buildConfigurationForm

2 calls to PdfEngineBase::buildConfigurationForm()
DomPdf::buildConfigurationForm in src/Plugin/EntityPrint/PrintEngine/DomPdf.php
Form constructor.
PhpWkhtmlToPdf::buildConfigurationForm in src/Plugin/EntityPrint/PrintEngine/PhpWkhtmlToPdf.php
Form constructor.
2 methods override PdfEngineBase::buildConfigurationForm()
DomPdf::buildConfigurationForm in src/Plugin/EntityPrint/PrintEngine/DomPdf.php
Form constructor.
PhpWkhtmlToPdf::buildConfigurationForm in src/Plugin/EntityPrint/PrintEngine/PhpWkhtmlToPdf.php
Form constructor.

File

src/Plugin/EntityPrint/PrintEngine/PdfEngineBase.php, line 16

Class

PdfEngineBase
Base class for all PDF print engines.

Namespace

Drupal\entity_print\Plugin\EntityPrint\PrintEngine

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildConfigurationForm($form, $form_state);
  $form['default_paper_size'] = [
    '#title' => $this
      ->t('Paper Size'),
    '#type' => 'select',
    '#options' => $this
      ->getPaperSizes(),
    '#default_value' => $this->configuration['default_paper_size'],
    '#description' => $this
      ->t('The page size to print the PDF to.'),
    '#weight' => -10,
  ];
  $form['orientation'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Paper Orientation'),
    '#options' => [
      static::PORTRAIT => $this
        ->t('Portrait'),
      static::LANDSCAPE => $this
        ->t('Landscape'),
    ],
    '#description' => $this
      ->t('The paper orientation one of Landscape or Portrait'),
    '#default_value' => $this->configuration['orientation'],
    '#weight' => -9,
  ];
  $form['credentials'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('HTTP Authentication'),
    '#open' => !empty($this->configuration['username']) || !empty($this->configuration['password']),
    '#weight' => 10,
  ];
  $form['credentials']['username'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Username'),
    '#description' => $this
      ->t('If your website is behind HTTP Authentication you can set the username'),
    '#default_value' => $this->configuration['username'],
  ];
  $form['credentials']['password'] = [
    '#type' => 'password',
    '#title' => $this
      ->t('Password'),
    '#description' => $this
      ->t('If your website is behind HTTP Authentication you can set the password. Note this data is not encrypted and will be exported to config.'),
    '#default_value' => $this->configuration['password'],
  ];
  return $form;
}