function views_export_export_form_submit

File

views_export/views_export.module, line 174

Code

function views_export_export_form_submit(&$form, &$form_state) {
    $code = "<?php \n";
    if (empty($form_state['values']['name'])) {
        $form_state['values']['name'] = 'foo';
    }
    foreach ($form_state['values']['modules'] as $module => $views) {
        $views = array_filter($views);
        asort($views);
        if ($views) {
            $code .= module_invoke($module, 'views_exportables', 'export', $views, $form_state['values']['name']) . "\n\n";
        }
    }
    $lines = substr_count($code, "\n");
    $types = system_elements();
    $info = '; $Id$' . "\n";
    $info .= "\n";
    $info .= strtr("name = @module Export Module\n", array(
        '@module' => $form_state['values']['name'],
    ));
    $info .= strtr("description = Exports some views of @module\n", array(
        '@module' => $form_state['values']['name'],
    ));
    $info .= "dependencies[] = views\n";
    $info .= "core = 6.x\n";
    $element_info = array(
        '#title' => t('Put this in @module.info in your modules/@module directory', array(
            '@module' => $form_state['values']['name'],
        )),
        '#type' => 'textarea',
        '#id' => 'export-info-textarea',
        '#name' => 'export-info-textarea',
        '#attributes' => array(),
        '#rows' => 9,
        '#cols' => 60,
        '#value' => $info,
        '#parents' => array(
            'dummy',
        ),
        '#required' => FALSE,
    ) + $types['textarea'];
    $api = "<?php\n";
    $api .= "/**\n";
    $api .= " * Implementation of hook_views_api().\n";
    $api .= " */\n";
    $api .= "function @module_views_api() {\n";
    $api .= "  return array(\n";
    $api .= "    'api' => '" . views_api_version() . "',\n";
    $api .= "    'path' => drupal_get_path('module', '@module'),\n";
    $api .= "    //'path' => drupal_get_path('module', '@module') . '/includes',\n";
    $api .= "  );\n";
    $api .= "}";
    $api = strtr($api, array(
        '@module' => check_plain($form_state['values']['name']),
    ));
    $element_api = array(
        '#title' => t('Put this in @module.module in your modules/@module directory (place a &lt;?php at the top of the file so the webserver knows that it is PHP code)', array(
            '@module' => $form_state['values']['name'],
        )),
        '#type' => 'textarea',
        '#id' => 'export-api-textarea',
        '#name' => 'export-api-textarea',
        '#attributes' => array(
            'dir' => 'ltr',
        ),
        '#rows' => 9,
        '#cols' => 60,
        '#value' => $api,
        '#parents' => array(
            'dummy',
        ),
        '#required' => FALSE,
    ) + $types['textarea'];
    $element_hook = array(
        '#title' => t('Put this in @module.views_default.inc in your modules/@module directory or modules/@module/includes directory (place a &lt;?php at the top of the file so the webserver knows that it is PHP code)', array(
            '@module' => $form_state['values']['name'],
        )),
        '#type' => 'textarea',
        '#id' => 'export-textarea',
        '#name' => 'export-textarea',
        '#attributes' => array(
            'dir' => 'ltr',
        ),
        '#rows' => min($lines, 150),
        '#value' => $code,
        '#parents' => array(
            'dummy',
        ),
        '#required' => FALSE,
    ) + $types['textarea'];
    $form_state['output'] = theme('textarea', $element_info);
    $form_state['output'] .= theme('textarea', $element_api);
    $form_state['output'] .= theme('textarea', $element_hook);
}