You are here

function Fields::options_submit in Views PDF 8

Stores the options.

File

src/Plugin/views/row/Fields.php, line 352
Contains \Drupal\views_pdf\Plugin\views\row\Fields.

Class

Fields
This class contains all the functionality of the field PDF style.

Code

function options_submit(&$form, &$form_state) {
  $default = $this->display->handler
    ->get_option('default_font_style');
  foreach ($form_state['values']['row_options']['formats'] as $id => $field) {

    // Reset to default, if the elements are equal to the default settings.
    if (count(array_diff($default, $field['text']['font_style'])) == 0 && count(array_diff($field['text']['font_style'], $default)) == 0) {
      $form_state['values']['row_options']['formats'][$id]['text']['font_style'] = NULL;
    }
    if ($field['text']['align'] == $this->display->handler
      ->get_option('default_text_align')) {
      $form_state['values']['row_options']['formats'][$id]['text']['align'] = NULL;
    }
    if ($field['text']['hyphenate'] == $this->display->handler
      ->get_option('default_text_hyphenate')) {
      $form_state['values']['row_options']['formats'][$id]['text']['hyphenate'] = NULL;
    }
  }

  // Save new file:
  // Note: The jQuery update is required to use Ajax for file upload. With
  // default Drupal jQuery it will not work.
  // For upload with Ajax a iFrame is open and upload in it, because
  // normal forms are not allowed to handle directly.
  $destination = variable_get('views_pdf_template_stream', 'public://views_pdf_templates');
  if (file_prepare_directory($destination, FILE_CREATE_DIRECTORY)) {

    // The file field is not called "template_file" as expected, it calls
    // "row_options". The reason for that is not clear.
    $file = file_save_upload('row_options', array(), $destination);
    if (is_object($file)) {
      $file_name = basename($file->destination, '.pdf');
      $form_state['values']['row_options']['template'] = $file_name;
      $file->status |= FILE_STATUS_PERMANENT;
      $file = file_save($file);
    }
  }
  if ($form_state['values']['row_options']['leading_template'] == t('-- None --')) {
    $form_state['values']['row_options']['leading_template'] = '';
  }
  if ($form_state['values']['row_options']['template'] == t('-- None --')) {
    $form_state['values']['row_options']['template'] = '';
  }
  if ($form_state['values']['row_options']['succeed_template'] == t('-- None --')) {
    $form_state['values']['row_options']['succeed_template'] = '';
  }
}