You are here

function ds_ctools_content in Display Suite 7

Same name and namespace in other branches
  1. 7.2 includes/ds.field_ui.inc \ds_ctools_content()

Return the configuration settings for the CTools field.

1 string reference to 'ds_ctools_content'
ds_menu in ./ds.module
Implements hook_menu().

File

./ds.field_ui.inc, line 954
Field UI functions for Display Suite.

Code

function ds_ctools_content($action = 'add', $entity_type = '', $field_name = '', $type_name = '', $subtype_name = '', $step = NULL) {
  ctools_include('modal');
  ctools_include('ajax');
  ctools_include('content');
  ctools_include('object-cache');
  $commands = array();
  $content_type = ctools_get_content_type($type_name);
  $subtype = ctools_content_get_subtype($content_type, $subtype_name);
  if ($data = ctools_object_cache_get($field_name, $field_name)) {
    $conf = $data;
  }
  else {
    $conf = ctools_content_get_defaults($content_type, $subtype);
  }
  $url = 'admin/structure/ds/fields/manage_ctools/content/' . $action . '/' . $entity_type . '/' . $field_name;
  $base_url = $url;
  if (!empty($type_name) && !empty($subtype_name)) {
    $url .= '/' . $type_name . '/' . $subtype_name . '/%step';
  }
  $form_info = array(
    'path' => $url,
    'show cancel' => TRUE,
    'next callback' => 'ds_ctools_content_next',
  );

  // Get entity context.
  $contexts = ds_get_entity_context($entity_type);
  $form_state = array(
    'contexts' => $contexts,
    'ajax' => TRUE,
    'modal' => TRUE,
    'modal return' => TRUE,
    'field_name' => $field_name,
  );

  // Call the content form.
  $output = ctools_content_form($action, $form_info, $form_state, $content_type, $subtype_name, $subtype, $conf, $step);
  if (!empty($form_state['complete']) || isset($_GET['dismiss'])) {
    $configuration = array(
      'conf' => $form_state['conf'],
      'type' => $type_name,
      'subtype' => $subtype_name,
    );
    $commands[] = ctools_modal_command_dismiss();
    $commands[] = ajax_command_invoke('input[name="fields[' . $field_name . '][settings_edit_form][settings][ctools]"]', 'dsCtoolsContentConfiguration', array(
      serialize($configuration),
    ));
    $commands[] = ajax_command_invoke('.select-content-link', 'dsCtoolsContentUpdate', array(
      serialize($configuration),
    ));
    ctools_object_cache_clear($field_name, $field_name);
  }
  else {
    if (!empty($form_state['cancel']) || isset($_GET['selection'])) {
      ctools_object_cache_clear($field_name, $field_name);
      $commands[] = ds_ctools_content_select($contexts, $field_name, $action, $entity_type);
    }
    elseif ($output === FALSE && !isset($_GET['dismiss'])) {
      $output = t('No further configuration exists for this content type.<br/><br/><a href="!close_modal" class="use-ajax">Click here to close the modal and save the settings.</a><br/><br/><a href="!new_content" class="use-ajax">Click here to select new content</a>.', array(
        '!new_content' => url($base_url, array(
          'query' => array(
            'selection' => TRUE,
          ),
        )),
        '!close_modal' => url($url, array(
          'query' => array(
            'dismiss' => 1,
          ),
        )),
      ));
      $commands[] = ctools_modal_command_display(t('Edit content'), $output);
    }
    else {
      $commands = ctools_modal_form_render($form_state, $output);
    }
  }
  print ajax_render($commands);
  ajax_footer();
  exit;
}