You are here

public function Page::buildOptionsForm in Views PDF 8

Provide a form to edit options for this plugin.

Overrides Page::buildOptionsForm

File

src/Plugin/views/display/Page.php, line 178
Contains \Drupal\views_pdf\Plugin\views\display\Page.

Class

Page
This class contains all the functionality of the PDF display.

Namespace

Drupal\views_pdf\Plugin\views\display

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  switch ($form_state
    ->get('section')) {
    case 'pdf_page':
      $form['#title'] .= t('PDF Page Options');
      $form['default_page_format'] = [
        '#type' => 'select',
        '#title' => t('Default Page Format'),
        '#required' => TRUE,
        '#options' => [
          's',
          'e',
        ],
        '#description' => t('This is the default page format. If you specifiy a different format in the template section, this settings will be override.'),
        '#default_value' => $this
          ->getOption('default_page_format'),
      ];
      $form['default_page_format_custom'] = [
        '#type' => 'textfield',
        '#title' => t('Custom Page Format'),
        '#description' => t('Here you can specifiy a custom page format. The schema is "[width]x[height]".'),
        '#default_value' => $this
          ->getOption('default_page_format_custom'),
      ];
      $form['default_page_orientation'] = [
        '#type' => 'radios',
        '#title' => t('Default Page Orientation'),
        '#required' => TRUE,
        '#options' => [
          'P' => t('Portrait'),
          'L' => t('Landscape'),
        ],
        '#description' => t('This is the default page orientation.'),
        '#default_value' => $this
          ->getOption('default_page_orientation'),
      ];
      $form['unit'] = [
        '#type' => 'select',
        '#title' => t('Unit'),
        '#required' => TRUE,
        '#options' => [
          'mm' => t('mm: Millimeter'),
          'pt' => t('pt: Point'),
          'cm' => t('cm: Centimeter'),
          'in' => t('in: Inch'),
        ],
        '#description' => t('This is the unit for the entered unit data. If you change this option all defined units were changed, but not converted.'),
        '#default_value' => $this
          ->getOption('unit'),
      ];
      $form['margin_left'] = [
        '#type' => 'textfield',
        '#title' => t('Margin: Left'),
        '#required' => TRUE,
        '#default_value' => $this
          ->getOption('margin_left'),
      ];
      $form['margin_right'] = [
        '#type' => 'textfield',
        '#title' => t('Margin: Right'),
        '#required' => TRUE,
        '#default_value' => $this
          ->getOption('margin_right'),
      ];
      $form['margin_top'] = [
        '#type' => 'textfield',
        '#title' => t('Margin: Top'),
        '#required' => TRUE,
        '#default_value' => $this
          ->getOption('margin_top'),
      ];
      $form['margin_bottom'] = [
        '#type' => 'textfield',
        '#title' => t('Margin: Bottom'),
        '#required' => TRUE,
        '#default_value' => $this
          ->getOption('margin_bottom'),
      ];
      break;
    case 'pdf_fonts':
      $fonts = ViewsPdfBase::getAvailableFontsCleanList();
      $font_styles = [
        'b' => t('Bold'),
        'i' => t('Italic'),
        'u' => t('Underline'),
        'd' => t('Line through'),
        'o' => t('Overline'),
      ];
      $align = [
        'L' => t('Left'),
        'C' => t('Center'),
        'R' => t('Right'),
        'J' => t('Justify'),
      ];
      $hyphenate = [
        'none' => t('None'),
        'auto' => t('Detect automatically'),
      ];
      $hyphenate = array_merge($hyphenate, ViewsPdfBase::getAvailableHyphenatePatterns());
      $form['#title'] .= t('PDF Default Font Options');
      $form['description'] = [
        '#prefix' => '<div class="description form-item">',
        '#suffix' => '</div>',
        '#value' => t('Here you specify a the default font settings for the document.'),
      ];
      $form['default_font_size'] = [
        '#type' => 'textfield',
        '#title' => t('Font Size'),
        '#size' => 10,
        '#default_value' => $this
          ->getOption('default_font_size'),
      ];
      $form['default_font_family'] = [
        '#type' => 'select',
        '#title' => t('Font Family'),
        '#options' => $fonts,
        '#size' => 5,
        '#default_value' => $this
          ->getOption('default_font_family'),
      ];
      $form['default_font_style'] = [
        '#type' => 'checkboxes',
        '#title' => t('Font Style'),
        '#options' => $font_styles,
        '#default_value' => $this
          ->getOption('default_font_style'),
      ];
      $form['default_text_align'] = [
        '#type' => 'radios',
        '#title' => t('Text Alignment'),
        '#options' => $align,
        '#default_value' => $this
          ->getOption('default_text_align'),
      ];
      $form['default_text_hyphenate'] = [
        '#type' => 'select',
        '#title' => t('Text Hyphenation'),
        '#options' => $hyphenate,
        '#description' => t('If you want to use hyphenation, then you need to download from <a href="@url">ctan.org</a> your needed pattern set. Then upload it to the dir "hyphenate_patterns" in the TCPDF lib directory. Perhaps you need to create the dir first. If you select the automated detection, then we try to get the language of the current node and select an appropriate hyphenation pattern.', [
          '@url' => 'http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/tex',
        ]),
        '#default_value' => $this
          ->getOption('default_text_hyphenate'),
      ];
      $form['default_font_color'] = [
        '#type' => 'textfield',
        '#title' => t('Text Color'),
        '#description' => t('If a value is entered without a comma, it will be interpreted as a hexadecimal RGB color. Normal RGB can be used by separating the components by a comma. e.g 255,255,255 for white. A CMYK color can be entered in the same way as RGB. e.g. 0,100,0,0 for magenta.'),
        '#size' => 20,
        '#default_value' => $this
          ->getOption('default_font_color'),
      ];
      break;
    case 'pdf_template':
      $form['#title'] .= t('PDF Templates');
      $templates = array_merge([
        t('-- None --'),
      ], []);
      $form['leading_template'] = [
        '#type' => 'select',
        '#options' => $templates,
        '#title' => t('Leading PDF Template'),
        '#required' => FALSE,
        '#description' => t('Here you specify a PDF file to be printed in front of every row.'),
        '#default_value' => $this
          ->getOption('leading_template'),
      ];
      $form['template'] = [
        '#type' => 'select',
        '#options' => $templates,
        '#title' => t('Template PDF'),
        '#description' => t('Here you specify a PDF file on which the content is printed. The first page of this document is used for the first page, in the target document. The second page is used for the second page in the target document and so on. If the target document has more that this template file, the last page of the template will be repeated. The leading document has no effect on the order of the pages.'),
        '#default_value' => $this
          ->getOption('template'),
      ];
      $form['succeed_template'] = [
        '#type' => 'select',
        '#options' => $templates,
        '#title' => t('Succeed PDF Template'),
        '#required' => FALSE,
        '#description' => t('Here you specify a PDF file to be printed after the main content.'),
        '#default_value' => $this
          ->getOption('succeed_template'),
      ];
      $form['template_file'] = [
        '#type' => 'file',
        '#title' => t('Upload New Template File'),
      ];
      $form['#attached']['js'][] = [
        'type' => 'setting',
        'data' => [
          'urlIsAjaxTrusted' => [
            '',
          ],
        ],
      ];
      break;
    case 'displays':
      $form['#title'] .= t('Attach to');
      $displays = [];
      foreach ($this->view
        ->getDisplay() as $display_id => $display) {
        if (!empty($display->handler) && $display->handler
          ->accept_attachments()) {
          $displays[$display_id] = $display->display_title;
        }
      }
      $form['displays'] = [
        '#type' => 'checkboxes',
        '#description' => t('The feed icon will be available only to the selected displays.'),
        '#options' => $displays,
        '#default_value' => $this
          ->getOption('displays'),
      ];
      break;
    case 'css':
      $form['#title'] .= t('CSS File');
      $form['css_file'] = [
        '#type' => 'textfield',
        '#description' => t('URL to a CSS file. This file is attached to all fields, rendered as HTML.'),
        '#default_value' => $this
          ->getOption('css_file'),
      ];
      break;
  }
}