You are here

function patterns_export_submit in Patterns 7

Same name and namespace in other branches
  1. 7.2 patterns_export/patterns_export.module \patterns_export_submit()

Submit hook of the export form

File

patterns_export/patterns_export.module, line 182

Code

function patterns_export_submit($form, &$form_state) {
  $tm_index = patterns_moduletags_get_index();
  $format = $form_state['values']['format'];
  $filename = $form_state['values']['pattern_name'];

  // TODO: Loop here and create a modules section
  // Create the array of exports functions.
  // Can either be the full module_tags index,
  // or we must go through all the checkbox and build the array from scratch
  if (!isset($form_state['values']['all']) || $form_state['values']['all'] == 0) {
    $exports = $tm_index;
  }
  else {

    // Individual modules have selected and the tagmodules index needs to be
    // refactored.
    $exports = array();
    foreach ($form_state['values']['ext'] as $module => $data) {
      foreach ($data['options'] as $tag => $enabled) {
        if (empty($enabled)) {
          continue;
        }
        $exports[$module][$tag][PATTERNS_EXPORT] = array();

        // Loop along all enabled export functions
        foreach ($data[$tag]['options'] as $export_key => $func) {
          if (!empty($func)) {
            $exports[$module][$tag][PATTERNS_EXPORT][] = $tm_index[$module][$tag][PATTERNS_EXPORT][$func];
          }
        }

        // If no sub-tag was selected (should not be the case)
        // then we execute EXPORT_ALL (if available)
        if (empty($exports[$module][$tag][PATTERNS_EXPORT])) {
          if (isset($tm_index[$module][$tag][PATTERNS_EXPORT][PATTERNS_EXPORT_ALL])) {
            $exports[$module][$tag][PATTERNS_EXPORT][] = $tm_index[$module][$tag][PATTERNS_EXPORT][PATTERNS_EXPORT_ALL];
          }
        }

        // Add necessary information
        if (isset($tm_index[$module][$tag][PATTERNS_FILES])) {
          $exports[$module][$tag][PATTERNS_FILES] = $tm_index[$module][$tag][PATTERNS_FILES];
        }
      }
    }
  }
  if (empty($exports)) {
    form_set_error('ext', t('No valid component selected.'));
    return FALSE;
  }
  $form_state['redirect'] = 'admin/patterns/export';
  patterns_export_start_engine($filename, $exports, $form_state['values']['info'], $form_state['values']['export']['to'], $format, $form_state['values']['export']['mode']);
}