You are here

public function PhpWkhtmlToPdf::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 PdfEngineBase::buildConfigurationForm

File

src/Plugin/EntityPrint/PrintEngine/PhpWkhtmlToPdf.php, line 137

Class

PhpWkhtmlToPdf
PHP wkhtmltopdf plugin.

Namespace

Drupal\entity_print\Plugin\EntityPrint\PrintEngine

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildConfigurationForm($form, $form_state);
  $form['zoom'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Zoom'),
    '#description' => $this
      ->t('Set this to zoom the pages - needed to produce hairlines.'),
    '#default_value' => $this->configuration['zoom'],
    '#weight' => -8,
    '#step' => 0.01,
  ];
  $form['binary_location'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Binary Location'),
    '#description' => $this
      ->t('Set this to the system path where the PDF engine binary is located.'),
    '#default_value' => $this->configuration['binary_location'],
    '#weight' => -7,
  ];
  $form['toc'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Table of contents'),
    '#tree' => TRUE,
    '#open' => $this->configuration['toc_generate'],
  ];
  $form['toc']['toc_generate'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Generate table of contents?'),
    '#default_value' => $this->configuration['toc_generate'],
  ];
  $form['toc']['toc_enable_back_links'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Link from section header to table of contents?'),
    '#default_value' => $this->configuration['toc_enable_back_links'],
  ];
  $form['toc']['toc_disable_dotted_lines'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Do not use dotted lines in the table of contents?'),
    '#default_value' => $this->configuration['toc_disable_dotted_lines'],
  ];
  $form['toc']['toc_disable_links'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Do not link from table of contents to sections'),
    '#default_value' => $this->configuration['toc_disable_links'],
  ];
  $form['viewport_size'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Viewport Size'),
    '#options' => self::$viewportSizeOptions,
    '#description' => $this
      ->t('Set viewport size if you have custom scrollbars or css attribute overflow to emulate window size.'),
    '#default_value' => $this->configuration['viewport_size'],
    '#weight' => -6,
  ];
  $form['remove_pdf_margins'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Remove PDF margins'),
    '#description' => $this
      ->t('Remove the page margins on the PDF'),
    '#default_value' => $this->configuration['remove_pdf_margins'],
    '#weight' => -5,
  ];
  return $form;
}