You are here

function views_create_view_code in Views (for Drupal 7) 5

1 call to views_create_view_code()
views_ui_admin_export_page in ./views_ui.module

File

./views_ui.module, line 1918

Code

function views_create_view_code($vid) {
  $view = views_get_view($vid);
  if (!$view) {
    return t("View '%vid' not found.", array(
      '%vid' => $vid,
    ));
  }
  $requires = array();
  $output = "  \$view = new stdClass();\n";
  $output .= "  \$view->name = " . var_export($view->name, true) . ";\n";
  $output .= "  \$view->description = " . var_export($view->description, true) . ";\n";
  $output .= "  \$view->access = " . var_export($view->access, true) . ";\n";
  if (user_access('use PHP for block visibility')) {
    $output .= "  \$view->view_args_php = " . var_export($view->view_args_php, true) . ";\n";
  }

  // page items
  // Always emit these - needed for rendering embedded views, even if page is disabled.
  $output .= "  \$view->page = " . views_tf($view->page) . ";\n";
  $output .= "  \$view->page_title = " . var_export($view->page_title, true) . ";\n";
  $output .= "  \$view->page_header = " . var_export($view->page_header, true) . ";\n";
  $output .= "  \$view->page_header_format = " . var_export($view->page_header_format, true) . ";\n";
  $output .= "  \$view->page_footer = " . var_export($view->page_footer, true) . ";\n";
  $output .= "  \$view->page_footer_format = " . var_export($view->page_footer_format, true) . ";\n";
  $output .= "  \$view->page_empty = " . var_export($view->page_empty, true) . ";\n";
  $output .= "  \$view->page_empty_format = " . var_export($view->page_empty_format, true) . ";\n";
  $output .= "  \$view->page_type = " . var_export($view->page_type, true) . ";\n";
  $output .= "  \$view->url = " . var_export($view->url, true) . ";\n";
  $output .= "  \$view->use_pager = " . views_tf($view->use_pager) . ";\n";
  $output .= "  \$view->nodes_per_page = " . var_export($view->nodes_per_page, true) . ";\n";
  if ($view->menu) {
    $output .= "  \$view->menu = " . views_tf($view->menu) . ";\n";
    $output .= "  \$view->menu_title = " . var_export($view->menu_title, true) . ";\n";
    $output .= "  \$view->menu_tab = " . views_tf($view->menu_tab) . ";\n";
    $output .= "  \$view->menu_tab_weight = " . var_export($view->menu_tab_weight, true) . ";\n";
    $output .= "  \$view->menu_tab_default = " . views_tf($view->menu_tab_default) . ";\n";
    $output .= "  \$view->menu_tab_default_parent = " . var_export($view->menu_tab_default_parent, true) . ";\n";
    $output .= "  \$view->menu_tab_default_parent_type = " . var_export($view->menu_tab_default_parent_type, true) . ";\n";
    $output .= "  \$view->menu_parent_tab_weight = " . var_export($view->menu_parent_tab_weight, true) . ";\n";
    $output .= "  \$view->menu_parent_title = " . var_export($view->menu_parent_title, true) . ";\n";
  }
  if ($view->block) {
    $output .= "  \$view->block = " . views_tf($view->block) . ";\n";
    $output .= "  \$view->block_title = " . var_export($view->block_title, true) . ";\n";
    $output .= "  \$view->block_header = " . var_export($view->block_header, true) . ";\n";
    $output .= "  \$view->block_header_format = " . var_export($view->block_header_format, true) . ";\n";
    $output .= "  \$view->block_footer = " . var_export($view->block_footer, true) . ";\n";
    $output .= "  \$view->block_footer_format = " . var_export($view->block_footer_format, true) . ";\n";
    $output .= "  \$view->block_empty = " . var_export($view->block_empty, true) . ";\n";
    $output .= "  \$view->block_empty_format = " . var_export($view->block_empty_format, true) . ";\n";
    $output .= "  \$view->block_type = " . var_export($view->block_type, true) . ";\n";
    $output .= "  \$view->nodes_per_block = " . var_export($view->nodes_per_block, true) . ";\n";
    $output .= "  \$view->block_more = " . views_tf($view->block_more) . ";\n";
    $output .= "  \$view->block_use_page_header = " . views_tf($view->block_use_page_header) . ";\n";
    $output .= "  \$view->block_use_page_footer = " . views_tf($view->block_use_page_footer) . ";\n";
    $output .= "  \$view->block_use_page_empty = " . views_tf($view->block_use_page_empty) . ";\n";
  }
  $output .= "  \$view->sort = array(\n";
  foreach ($view->sort as $sort) {
    $output .= "    array(\n";
    $fieldbits = explode('.', $sort['field']);
    $output .= "      'tablename' => " . var_export($fieldbits[0], true) . ",\n";
    $output .= "      'field' => " . var_export($fieldbits[1], true) . ",\n";
    $output .= "      'sortorder' => " . var_export($sort['sortorder'], true) . ",\n";
    $output .= "      'options' => " . var_export($sort['options'], true) . ",\n";
    $output .= "    ),\n";
    $requires[$fieldbits[0]] = 1;
  }
  $output .= "  );\n";
  $output .= "  \$view->argument = array(\n";
  foreach ($view->argument as $argument) {
    $output .= "    array(\n";
    $output .= "      'type' => " . var_export($argument['type'], true) . ",\n";
    $output .= "      'argdefault' => " . var_export($argument['argdefault'], true) . ",\n";
    $output .= "      'title' => " . var_export($argument['title'], true) . ",\n";
    $output .= "      'options' => " . var_export($argument['options'], true) . ",\n";
    $output .= "      'wildcard' => " . var_export($argument['wildcard'], true) . ",\n";
    $output .= "      'wildcard_substitution' => " . var_export($argument['wildcard_substitution'], true) . ",\n";
    $output .= "    ),\n";
  }
  $output .= "  );\n";
  $output .= "  \$view->field = array(\n";
  foreach ($view->field as $field) {
    $output .= "    array(\n";
    $output .= "      'tablename' => " . var_export($field['tablename'], true) . ",\n";
    $output .= "      'field' => " . var_export($field['field'], true) . ",\n";
    $output .= "      'label' => " . var_export($field['label'], true) . ",\n";
    if ($field['handler']) {
      $output .= "      'handler' => " . var_export($field['handler'], true) . ",\n";
    }
    if ($field['sortable']) {
      $output .= "      'sortable' => " . var_export($field['sortable'], true) . ",\n";
    }
    if ($field['defaultsort']) {
      $output .= "      'defaultsort' => " . var_export($field['defaultsort'], true) . ",\n";
    }
    if ($field['options']) {
      $output .= "      'options' => " . var_export($field['options'], true) . ",\n";
    }
    $output .= "    ),\n";
    $requires[$field['tablename']] = 1;
  }
  $output .= "  );\n";
  $output .= "  \$view->filter = array(\n";
  foreach ($view->filter as $filter) {
    $output .= "    array(\n";
    $fieldbits = explode('.', $filter['field']);
    $output .= "      'tablename' => " . var_export($fieldbits[0], true) . ",\n";
    $output .= "      'field' => " . var_export($fieldbits[1], true) . ",\n";
    $output .= "      'operator' => " . var_export($filter['operator'], true) . ",\n";
    $output .= "      'options' => " . var_export($filter['options'], true) . ",\n";
    $output .= "      'value' => " . var_export($filter['value'], true) . ",\n";
    $output .= "    ),\n";
    $requires[$fieldbits[0]] = 1;
  }
  $output .= "  );\n";
  $output .= "  \$view->exposed_filter = array(\n";
  foreach ($view->exposed_filter as $filter) {
    $output .= "    array(\n";
    $fieldbits = explode('.', $filter['field']);
    $output .= "      'tablename' => " . var_export($fieldbits[0], true) . ",\n";
    $output .= "      'field' => " . var_export($fieldbits[1], true) . ",\n";
    $output .= "      'label' => " . var_export($filter['label'], true) . ",\n";
    $output .= "      'optional' => " . var_export($filter['optional'], true) . ",\n";
    $output .= "      'is_default' => " . var_export($filter['is_default'], true) . ",\n";
    $output .= "      'operator' => " . var_export($filter['operator'], true) . ",\n";
    $output .= "      'single' => " . var_export($filter['single'], true) . ",\n";
    $output .= "    ),\n";
    $requires[$fieldbits[0]] = 1;
  }
  $output .= "  );\n";
  $output .= "  \$view->requires = array(" . implode(', ', array_keys($requires)) . ");\n";
  $output .= "  \$views[\$view->name] = \$view;\n";
  return $output;
}