You are here

function scald_admin_context_form in Scald: Media Management made easy 7

Form constructor for the context editing form.

Parameters

string $context_name: (optional) Context name, when editing an existing Scald context.

1 string reference to 'scald_admin_context_form'
scald_menu in ./scald.module
Implements hook_menu().

File

includes/scald.admin.inc, line 252

Code

function scald_admin_context_form($form, &$form_state, $context_name = NULL) {
  if ($context_name) {

    // Edit an existing Scald context.
    $custom_contexts = variable_get('scald_custom_contexts', array());
    if (!array_key_exists($context_name, $custom_contexts)) {
      drupal_set_message(t('Custom context not found: %context', array(
        '%context' => $context_name,
      )), 'error');
      drupal_goto('admin/structure/scald');
    }
    else {
      $context = $custom_contexts[$context_name];
    }
  }
  else {

    // Default setting for the new context.
    $context = array(
      'name' => '',
      'title' => '',
      'description' => '',
      'render_language' => 'XHTML',
      'parseable' => TRUE,
      'formats' => array(),
    );
  }

  // Make the context array available to implementations of hook_form_alter.
  $form['#context'] = $context;
  $form['title'] = array(
    '#title' => t('Title'),
    '#type' => 'textfield',
    '#default_value' => $context['title'],
    '#description' => t('The title of this context. This text will be displayed as part of the list on the <em>Scald Dashboard</em> and on the <em>Atom type Contexts</em> pages. It is recommended that this name begin with a capital letter and contain only letters, numbers, and spaces..'),
    '#required' => TRUE,
    '#size' => 30,
  );
  $form['name'] = array(
    '#type' => 'machine_name',
    '#default_value' => $context['name'],
    '#maxlength' => 32,
    '#machine_name' => array(
      'source' => array(
        'title',
      ),
      'exists' => 'scald_context_load',
    ),
    '#disabled' => $context['name'] ? TRUE : FALSE,
    '#description' => t('A unique machine-readable name for this context. It must only contain lowercase letters, numbers, and underscores.'),
  );
  $form['description'] = array(
    '#title' => t('Description'),
    '#type' => 'textarea',
    '#default_value' => $context['description'],
    '#description' => t('Describe this context. The text will be displayed on the <em>Scald Dashboard</em> page.'),
  );
  $form['additional_settings'] = array(
    '#type' => 'vertical_tabs',
    // @todo provide a JavaScript to do Vertical Tabs summary stuffs.
    '#attached' => array(),
  );
  $form['system'] = array(
    '#type' => 'fieldset',
    '#title' => t('System settings'),
    '#collapsible' => TRUE,
    '#group' => 'additional_settings',
  );
  $form['system']['parseable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Make parseable'),
    '#default_value' => (bool) $context['parseable'],
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => $context['name'] ? t('Save context') : t('Add context'),
    '#weight' => 40,
  );
  if ($context['name']) {
    $form['actions']['delete'] = array(
      '#markup' => l(t('Delete context'), 'admin/structure/scald/context/delete/' . $context['name']),
      '#weight' => 45,
    );
  }
  return $form;
}