You are here

function ctools_context_add_item_table_buttons in Chaos Tool Suite (ctools) 7

Same name and namespace in other branches
  1. 6 includes/context-admin.inc \ctools_context_add_item_table_buttons()
2 calls to ctools_context_add_item_table_buttons()
ctools_context_add_item_table in includes/context-admin.inc
Add the context table to the page.
ctools_context_ajax_item_add in includes/context-admin.inc
Ajax entry point to add an context

File

includes/context-admin.inc, line 248
includes/common-context.inc Provide API for adding contexts for modules that embed displays.

Code

function ctools_context_add_item_table_buttons($type, $module, &$form, $available_contexts) {
  drupal_add_library('system', 'drupal.ajax');
  $form['buttons'] = array(
    '#tree' => TRUE,
  );
  if (!empty($available_contexts)) {
    $type_info = ctools_context_info($type);
    $module = $form['#ctools_context_module'];
    $cache_key = $form['#cache_key'];

    // The URL for this ajax button
    $form['buttons'][$type]['add-url'] = array(
      '#attributes' => array(
        'class' => array(
          "ctools-{$type}-add-url",
        ),
      ),
      '#type' => 'hidden',
      '#value' => url("ctools/context/ajax/add/{$module}/{$type}/{$cache_key}", array(
        'absolute' => TRUE,
      )),
    );
    asort($available_contexts);

    // This also will be in the URL.
    $form['buttons'][$type]['item'] = array(
      '#attributes' => array(
        'class' => array(
          "ctools-{$type}-add-url",
        ),
      ),
      '#type' => 'select',
      '#options' => $available_contexts,
      '#required' => FALSE,
    );
    $form['buttons'][$type]['add'] = array(
      '#type' => 'submit',
      '#attributes' => array(
        'class' => array(
          'ctools-use-modal',
        ),
      ),
      '#id' => "ctools-{$type}-add",
      '#value' => $type_info['add button'],
    );
  }
}