You are here

public function PrintableConfigurationForm::buildForm in Printer and PDF versions for Drupal 8+ 2.x

Same name and namespace in other branches
  1. 8 src/Form/PrintableConfigurationForm.php \Drupal\printable\Form\PrintableConfigurationForm::buildForm()

Form constructor.

Parameters

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

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/PrintableConfigurationForm.php, line 82

Class

PrintableConfigurationForm
Provides shared configuration form for all printable formats.

Namespace

Drupal\printable\Form

Code

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);
}