You are here

function ds_build_modes_page in Display Suite 6.3

Same name and namespace in other branches
  1. 6.2 includes/ds.buildmodes.inc \ds_build_modes_page()

Build modes overview.

1 string reference to 'ds_build_modes_page'
_ds_ui_menu in includes/ds.registry.inc
Return menu items and import default settings.

File

includes/ds.buildmodes.inc, line 11
Manage build modes.

Code

function ds_build_modes_page($module) {
  $output = '';
  $action = check_plain(arg(6));
  $build_mode = check_plain(arg(7));
  $build_modes = ds_get_build_modes($module, TRUE);
  $api_info = ds_api_info($module);
  $hide = FALSE;

  // Only show edit forms if allowed by api
  if (!isset($api_info['no_new_build_modes'])) {

    // Delete form.
    if (in_array($build_mode, array_keys($build_modes)) && $action == 'delete') {
      $output .= drupal_get_form('ds_build_mode_delete_form', $module, $build_mode);
      $hide = TRUE;
    }
    elseif (in_array($build_mode, array_keys($build_modes)) && $action == 'edit') {
      $output .= drupal_get_form('ds_build_mode_form', $module, $build_mode);
      $hide = TRUE;
    }
    if (empty($build_modes)) {
      $output .= '<p>' . t('You have not defined any custom build modes.') . '</p>';
    }
  }
  if ($hide == FALSE) {

    // Custom build modes overview form.
    if (!empty($build_modes)) {
      $groups = array();
      foreach ($build_modes as $key => $build_mode) {
        $groups[$build_mode['group']][$key] = $build_mode;
      }
      $header = array(
        t('Group'),
        t('Name'),
        t('Machine name'),
        t('Module'),
        t('State'),
        t('Operations'),
      );
      $rows = array();
      foreach ($groups as $group_key => $group) {

        // Add a header row for this group
        $rows[] = array(
          'data' => array(
            array(
              'data' => '<em>' . $group_key . '</em>',
              'colspan' => 6,
            ),
          ),
        );
        foreach ($group as $key => $mode) {

          // Check state of build mode
          $in_code = TRUE;
          $overridden = FALSE;
          $state = 'default';
          $state_message = t('In code');
          if (!isset($mode['module']) || empty($mode['module'])) {
            $in_code = FALSE;
            $state_message = t('Database');
            $state = 'custom';
          }
          elseif (isset($mode['overridden']) && !empty($mode['overridden'])) {
            $overridden = TRUE;
            $state_message = t('Overridden');
            $state = 'overridden';
          }

          // Build the row
          $row = array();
          $row[] = '';
          $row[] = '<strong>' . check_plain($mode['title']) . '</strong>';
          $row[] = $key;
          $row[] = isset($mode['module']) ? $mode['module'] : 'unknown';
          $row[] = $state_message;
          if ($state != 'default') {
            $row[] = l(t('Edit'), DS_PATH_MODULES . '/' . $module . '/buildmodes/edit/' . $key) . ' - ' . l(t('Delete'), DS_PATH_MODULES . '/' . $module . '/buildmodes/delete/' . $key);
          }
          else {
            $row[] = '';
          }
          $rows[] = array(
            'data' => $row,
          );
        }
      }
      $output .= theme('table', $header, $rows);
    }

    // New build mode form.
    if (!isset($api_info['no_new_build_modes'])) {
      $output .= drupal_get_form('ds_build_mode_form', $module);
    }
    else {
      $output .= theme('fieldset', array(
        '#title' => t('Add new build mode'),
        '#value' => '<p>This type does not support custom build modes.</p>',
      ));
    }

    // Matrix form.
    if (isset($api_info['types'])) {
      $types = $api_info['types']();
      $output .= drupal_get_form('ds_buildmodes_matrix_form', $module, $types);
    }
  }
  return $output;
}