You are here

function ctools_custom_content_type_edit_form in Chaos Tool Suite (ctools) 7

Same name and namespace in other branches
  1. 6 plugins/content_types/custom/custom.inc \ctools_custom_content_type_edit_form()

Returns an edit form for the custom type.

1 string reference to 'ctools_custom_content_type_edit_form'
_ctools_default_content_type_content_type in plugins/content_types/custom/custom.inc
Settings for the default custom content type.

File

plugins/content_types/custom/custom.inc, line 267
Custom content type.

Code

function ctools_custom_content_type_edit_form($form, &$form_state) {
  $settings = ctools_custom_content_type_get_conf($form_state['subtype'], $form_state['conf']);
  $form_state['settings'] = $settings;
  if ($settings['custom_type'] == 'fixed') {

    // No form for this case.
    return $form;
  }
  $form['admin_title'] = array(
    '#type' => 'textfield',
    '#default_value' => isset($settings['admin_title']) ? $settings['admin_title'] : '',
    '#title' => t('Administrative title'),
    '#description' => t('This title will be used administratively to identify this pane. If blank, the regular title will be used.'),
  );

  // Copy over the title override settings for a title heading.
  $form['aligner_start'] = array(
    '#markup' => '<div class="option-text-aligner clearfix">',
  );
  $form['title'] = array(
    '#type' => 'textfield',
    '#default_value' => $settings['title'],
    '#title' => t('Title'),
    '#id' => 'override-title-textfield',
  );
  $form['title_heading'] = array(
    '#type' => 'select',
    '#default_value' => isset($settings['title_heading']) ? $settings['title_heading'] : 'h2',
    '#options' => array(
      'h1' => t('h1'),
      'h2' => t('h2'),
      'h3' => t('h3'),
      'h4' => t('h4'),
      'h5' => t('h5'),
      'h6' => t('h6'),
      'div' => t('div'),
      'span' => t('span'),
    ),
    '#id' => 'override-title-heading',
  );
  $form['aligner_stop'] = array(
    '#markup' => '</div>',
  );
  $form['body'] = array(
    '#type' => 'text_format',
    '#title' => t('Body'),
    '#default_value' => $settings['body'],
    '#format' => $settings['format'],
  );
  if (!empty($form_state['contexts'])) {

    // Set extended description if both CCK and Token modules are enabled, notifying of unlisted keywords.
    if (module_exists('content') && module_exists('token')) {
      $description = t('If checked, context keywords will be substituted in this content. Note that CCK fields may be used as keywords using patterns like <em>%node:field_name-formatted</em>.');
    }
    elseif (!module_exists('token')) {
      $description = t('If checked, context keywords will be substituted in this content. More keywords will be available if you install the Token module, see http://drupal.org/project/token.');
    }
    else {
      $description = t('If checked, context keywords will be substituted in this content.');
    }
    $form['substitute'] = array(
      '#type' => 'checkbox',
      '#title' => t('Use context keywords'),
      '#description' => $description,
      '#default_value' => !empty($settings['substitute']),
    );
    $form['contexts'] = array(
      '#title' => t('Substitutions'),
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $rows = array();
    foreach ($form_state['contexts'] as $context) {
      foreach (ctools_context_get_converters('%' . check_plain($context->keyword) . ':', $context) as $keyword => $title) {
        $rows[] = array(
          check_plain($keyword),
          t('@identifier: @title', array(
            '@title' => $title,
            '@identifier' => $context->identifier,
          )),
        );
      }
    }
    $header = array(
      t('Keyword'),
      t('Value'),
    );
    $form['contexts']['context'] = array(
      '#markup' => theme('table', array(
        'header' => $header,
        'rows' => $rows,
      )),
    );
  }
  if (!user_access('administer custom content') || !module_exists('ctools_custom_content')) {
    return $form;
  }

  // Make the other form items dependent upon it.
  ctools_include('dependent');
  ctools_add_js('dependent');
  $form['reusable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Make this content reusable'),
    '#default_value' => FALSE,
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Machine name'),
    '#description' => t('The machine readable name of this content. It must be unique, and it must contain only alphanumeric characters and underscores. Once created, you will not be able to change this value!'),
    '#dependency' => array(
      'edit-reusable' => array(
        1,
      ),
    ),
  );
  $form['category'] = array(
    '#type' => 'textfield',
    '#title' => t('Category'),
    '#description' => t('What category this content should appear in. If left blank the category will be "Miscellaneous".'),
    '#dependency' => array(
      'edit-reusable' => array(
        1,
      ),
    ),
  );
  $form['admin_description'] = array(
    '#type' => 'textarea',
    '#title' => t('Administrative description'),
    '#description' => t('A description of what this content is, does or is for, for administrative use.'),
    '#dependency' => array(
      'edit-reusable' => array(
        1,
      ),
    ),
  );
  return $form;
}