You are here

function views_pdf_plugin_row_fields::options_submit in Views PDF 6

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

Stores the options

File

./views_pdf_plugin_row_fields.inc, line 327
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 file upload via Ajax.
  $files_path = file_directory_path();
  $template_dir = variable_get('views_pdf_template_path', 'views_pdf_templates');
  $dir = $files_path . '/' . $template_dir;
  if (!is_dir($dir)) {
    @mkdir($dir);
    @chmod($dir, 0775);
  }
  if (is_writable($dir)) {
    $template_path = file_create_path($dir);

    // 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(), $template_path);
    if ($file) {
      $form_state['values']['row_options']['template'] = $file->destination;
    }
  }
  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'] = '';
  }
}