You are here

function ds_panels_field_ui in Display Suite 7

Manage display screen with panels editor.

Parameters

$entity_type: The name of the entity type.

$bundle_arg: The name of the bundle.

$view_mode: The name of the view mode.

1 call to ds_panels_field_ui()
ds_extras_select_layout_editor in modules/ds_extras/ds_extras.admin.inc
Select the editor depending on layout.

File

modules/ds_extras/ds_extras.panels.inc, line 26
Administrative functions for DS panels.

Code

function ds_panels_field_ui($entity_type, $bundle, $view_mode) {
  $build = array();
  $panel_layout = '';

  // Load ds field ui.
  module_load_include('inc', 'ds', 'ds.field_ui');
  module_load_include('inc', 'ds_extras', 'ds.admin');

  // Get the ds layout. Make sure this does not break in case
  // there was a layout created with Field UI.
  $ds_layout = ds_get_layout($entity_type, $bundle, $view_mode);
  if (!empty($ds_layout) && !isset($ds_layout['settings']['ds_panels'])) {
    $ds_layout = NULL;
  }

  // Check if the layout is added as an extra argument in the URI.
  // Depending on the outcome, the selection tab will display
  // links, a form or the layout edit form.
  $layout_tab_first = FALSE;
  $menu = menu_get_item();
  if (!empty($menu['theme_arguments'])) {
    $layout_tab_first = TRUE;
    $panel_layout = array_shift($menu['theme_arguments']);
  }

  // Check the $panel_layout variable.
  if (!empty($ds_layout)) {
    $panel_layout = $ds_layout['settings']['layout'];
  }

  // If there's a ds layout and panel layout and the layout key is in the URI
  // show the layout change form of panels, else return the form
  // to select the form or update its settings.
  if (!empty($ds_layout) && !empty($panel_layout) && $layout_tab_first) {
    $display = panels_load_display($ds_layout['settings']['did']);
    $display->context = ds_get_entity_context($entity_type);
    $destination = str_replace('/' . $panel_layout, '', $_GET['q']);
    $layout = panels_edit_layout($display, t('Save'), $destination, 'ds_panels');
  }
  else {
    $layout = drupal_get_form('ds_panels_layout', $entity_type, $bundle, $view_mode, $ds_layout, $panel_layout, $layout_tab_first);
  }

  // Content tab.
  $content = ds_panels_content($entity_type, $bundle, $view_mode, $ds_layout, $panel_layout);

  // Move all this stuff into nice vertical tabs.
  $build['tabs'] = array(
    '#type' => 'vertical_tabs',
    '#theme_wrappers' => array(
      'vertical_tabs',
    ),
  );
  $build['tabs']['ds_panels_content'] = array(
    '#type' => 'fieldset',
    '#group' => 'tabs',
    '#title' => t('Content'),
    '#weight' => 0,
  );
  $build['tabs']['ds_panels_content']['content'] = array(
    '#markup' => drupal_render($content),
  );
  $build['tabs']['ds_panels_layout'] = array(
    '#type' => 'fieldset',
    '#group' => 'tabs',
    '#title' => t('Layout'),
    '#weight' => $layout_tab_first || empty($ds_layout) ? -1 : 1,
  );
  $build['tabs']['ds_panels_layout']['content'] = array(
    '#markup' => drupal_render($layout),
  );

  // Add the Custom display settings form. We're just going to copy
  // the code from Field UI, because otherwhise we need override to much.
  if ($view_mode == 'default') {
    $view_modes = drupal_get_form('ds_panels_display_settings', $entity_type, $bundle);
    if (!empty($view_modes['view_modes_custom'])) {
      $build['tabs']['view_modes'] = array(
        '#type' => 'fieldset',
        '#group' => 'tabs',
        '#title' => t('Custom display settings'),
        '#weight' => 10,
      );
      $build['tabs']['view_modes']['content'] = array(
        '#markup' => drupal_render($view_modes),
      );
    }
  }

  // Switch to Field UI.
  if (variable_get('ds_extras_editor_switch') && variable_get('ds_extras_panel_view_modes')) {
    $build['tabs']['editor_switch'] = array(
      '#type' => 'fieldset',
      '#group' => 'tabs',
      '#title' => t('Switch editor'),
      '#weight' => 10,
    );
    $query = array(
      'switch' => 'field_ui',
    );
    $switch_link = l(t('Switch to Field UI'), $_GET['q'], array(
      'query' => $query,
    ));
    $content = array(
      '#markup' => '<p>' . t('Click on the link underneath to switch to Field UI') . '</p><p>' . $switch_link . '</p>',
    );
    $build['tabs']['editor_switch']['content'] = array(
      '#markup' => drupal_render($content),
    );
  }
  return $build;
}