You are here

function content_menu_add_exiting_view in Content Menu 8

Same name and namespace in other branches
  1. 7 content_menu.menu_admin.inc \content_menu_add_exiting_view()

List all views with a page display.

1 string reference to 'content_menu_add_exiting_view'
content_menu_menu in ./content_menu.module
Implements hook_menu().

File

./content_menu.menu_admin.inc, line 610

Code

function content_menu_add_exiting_view($form, $form_state) {
  if (!module_exists('views')) {
    return;
  }
  $form = array();
  $item = content_menu_get_menu_item_from_querystring();
  $form['#menu_item'] = $item;
  $all_views = views_get_all_views();
  foreach ($all_views as $view) {
    foreach ($view->display as $display) {
      if ($display->display_plugin == 'page') {
        if (!property_exists($view, 'disabled') || property_exists($view, 'disabled') && !$view->disabled) {
          $view_path = $display->display_options['path'];
          $view_title = check_plain($view->name . ' - ' . $display->display_title . ' (' . $display->display_options['path'] . ')');
          if (drupal_valid_path($view_path)) {
            $options[$view_path] = $view_title;
          }
        }
      }
    }
  }
  if (!empty($options)) {
    asort($options);
    $form['existing_view'] = array(
      '#type' => 'radios',
      '#title' => t('Link to this view'),
      '#default_value' => isset($item['link_path']) ? $item['link_path'] : NULL,
      '#required' => TRUE,
      '#options' => $options,
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save'),
      '#submit' => array(
        'content_menu_add_exiting_view_submit',
      ),
    );
  }
  else {
    $no_views_notice = t('There are no available views.');
    if (module_exists('views_ui') && user_access('administer views')) {
      $no_views_notice .= ' ' . t('You can create views in the <a href="@url">Views UI</a>', array(
        '@url' => url('admin/structure/views'),
      ));
    }
    $form['view_info'] = array(
      '#title' => t('Use these views'),
      '#type' => 'item',
      '#markup' => $no_views_notice,
    );
  }
  return $form;
}