You are here

function views_pdf_plugin_row_fields::options_submit in Views PDF 7.2

Same name and namespace in other branches
  1. 6 views_pdf_plugin_row_fields.inc \views_pdf_plugin_row_fields::options_submit()
  2. 7.3 views_pdf_plugin_row_fields.inc \views_pdf_plugin_row_fields::options_submit()
  3. 7 views_pdf_plugin_row_fields.inc \views_pdf_plugin_row_fields::options_submit()

Stores the options

Overrides views_plugin_row::options_submit

File

plugins/views_pdf_plugin_row_fields.inc, line 334
PDF row fields plugin provides the the fields plugin for unformatted style.

Class

views_pdf_plugin_row_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'] = '';
  }
}