You are here

function config_pages_edit_form in Config Pages 7

Form callback: create or edit a config_pages.

Parameters

$config_pages: The config_pages object to edit or for a create form an empty config_pages object with only a config_pages type defined.

1 string reference to 'config_pages_edit_form'
config_pages_form_wrapper in ./config_pages.admin.inc
Form callback wrapper: create or edit a config_pages.

File

./config_pages.admin.inc, line 288
ConfigPages editing UI.

Code

function config_pages_edit_form($form, &$form_state, $config_pages) {

  // Context field.
  $form['context'] = array(
    '#type' => 'value',
    '#value' => $config_pages->context,
  );
  $form['#config_pages'] = $config_pages;

  // Process confirmation form.
  if (!empty($form_state['storage']['delete_confirmation'])) {
    $question = 'Are you sure you want to clear this configuration page?';
    $path = $_GET['q'];
    $form = confirm_form($form, $question, $path, NULL, t('Yes'));
    $form['actions']['submit']['#submit'] = array(
      'config_pages_form_submit_delete',
    );
    return $form;
  }
  $groups = config_pages_context_groups($config_pages->type);
  $context_links = array();
  foreach ($groups as $group => $title) {
    list($module, $key) = explode(':', $group);
    $context_links = module_invoke($module, 'config_pages_context_list', $key, TRUE);
    if (!empty($context_links)) {

      // Get current value of this context.
      $value = module_invoke($module, 'config_pages_context_value', $key);

      // Create form elements to select another context.
      $form['context_selection_' . $key] = array(
        '#type' => 'fieldset',
        '#title' => t('Choose @name context', array(
          '@name' => $title,
        )),
        '#weight' => -100,
      );
      foreach ($context_links as $pos => $link) {
        if ($link['value'] == $value) {
          $link['title'] = '<strong>' . $link['title'] . '</strong>';
        }
        $form['context_selection_' . $key][$link['value']] = array(
          '#type' => 'link',
          '#href' => $link['href'],
          '#title' => $link['title'],
          '#prefix' => $pos > 0 ? ' | ' : '',
          '#options' => array(
            'html' => TRUE,
          ),
        );
      }
    }
  }

  // Add the field related form elements.
  $form_state['config_pages'] = $config_pages;
  field_attach_form('config_pages', $config_pages, $form, $form_state);
  $form['actions'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'form-actions',
      ),
    ),
    '#weight' => 400,
  );

  // We add the form's #submit array to this button along with the actual submit
  // handler to preserve any submit handlers added by a form callback_wrapper.
  $submit = array();
  if (!empty($form['#submit'])) {
    $submit += $form['#submit'];
  }
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#submit' => $submit + array(
      'config_pages_edit_form_submit',
    ),
  );
  if (!empty($config_pages->config_pages_id)) {
    $form['actions']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Clear'),
      '#submit' => array(
        'config_pages_form_submit_delete',
      ),
      '#weight' => 45,
    );

    // Add panelize button.
    if (module_exists('panels_ipe') && function_exists('panelizer_entity_plugin_get_handler')) {
      $handler = panelizer_entity_plugin_get_handler('config_pages');
      if ($handler && $handler
        ->is_panelized($config_pages->type . '.default')) {
        if (empty($config_pages->panelizer['default'])) {
          $form['actions']['panelize'] = array(
            '#type' => 'submit',
            '#value' => t('Panelize Default View Mode with IPE'),
            '#submit' => array(
              'config_pages_form_submit_panelize',
            ),
            '#weight' => 46,
          );
        }
        else {
          $form['actions']['panelize'] = array(
            '#type' => 'markup',
            '#markup' => t('[ Default View Mode Already panelized with IPE ]'),
            '#weight' => 46,
          );
        }
      }
    }
  }

  // We append the validate handler to #validate in case a form callback_wrapper
  // is used to add validate handlers earlier.
  $form['#validate'][] = 'config_pages_edit_form_validate';
  return $form;
}