You are here

function _webform_chart_form_configure in Webform Chart 7

Same name and namespace in other branches
  1. 7.2 webform_chart.admin.inc \_webform_chart_form_configure()

Provides an administration form for the webform_chart module.

Enabling administrator roles to specify a back end to use for rendering charts and configure those back ends. This invokes all #module_name#_webform_chart_backends functions so other modules may provide additional back ends and configuration data.

1 call to _webform_chart_form_configure()
webform_chart_form_webform_configure_form_alter in ./webform_chart.module
Implements hook_form_FORM_ID_alter().

File

./webform_chart.admin.inc, line 17
Provides administration functions for the webform_chart module.

Code

function _webform_chart_form_configure(&$form, &$form_state) {

  // Retrieve existing configuration (if existing).
  $config = unserialize($form['#node']->webform['charting']);

  // Get all possible rendering back-ends.
  $backends = array_merge(array(
    'none' => t('None'),
  ), module_invoke_all('wfc_backend'));
  $form['charting'] = array(
    '#type' => 'fieldset',
    '#title' => t('Webform Chart Back-end'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );

  // Choose the rendering backend.
  $form['charting']['backend'] = array(
    '#type' => 'select',
    '#title' => t('Select Back-end'),
    '#options' => $backends,
    '#default_value' => isset($config['backend']) ? $config['backend'] : 'none',
    '#description' => t('Select a back-end to use for rendering webform charts'),
  );

  // Display the help section: the available backends.
  $form['charting']['help'] = array(
    '#markup' => theme('webform_chart_form_help'),
  );

  // Choose the setting mode: either global or per component.
  $methods = array(
    0 => t('Global settings'),
    1 => t('Per component settings'),
  );
  $form['charting']['config_method'] = array(
    '#type' => 'radios',
    '#title' => t('Configuration method'),
    '#default_value' => isset($config['config_method']) ? $config['config_method'] : 1,
    '#options' => $methods,
    '#description' => t('Choose either to activate a per component setting for the charts or global settings for this form to be replicated on all components.'),
    '#states' => array(
      'invisible' => array(
        'select[id="edit-backend"]' => array(
          'value' => 'none',
        ),
      ),
    ),
  );

  // Display backend configuration (only if global settings mode).
  foreach ($backends as $backend => $display) {
    if ($backend && $backend != 'none') {
      $fn = $backend . '_wfc_backend_configure';
      $form['charting']['backend_config_' . $backend] = array(
        '#type' => 'fieldset',
        '#title' => t('@display Configuration', array(
          '@display' => $display,
        )),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#states' => array(
          'expanded' => array(
            ':input[name="config_method"]' => array(
              'value' => '0',
            ),
            'select[id="edit-backend"]' => array(
              'value' => $backend,
            ),
          ),
          'visible' => array(
            ':input[name="config_method"]' => array(
              'value' => '0',
            ),
            'select[id="edit-backend"]' => array(
              'value' => $backend,
            ),
          ),
        ),
      );
      if (function_exists($fn)) {

        // If the form was previously saved as a
        // "per component" setting mode, index config does not exist.
        if (!isset($config['config'])) {
          $config['config'] = array();
        }
        $backend_config = $fn($config['config']);
        $form['charting']['backend_config_' . $backend] = array_merge($form['charting']['backend_config_' . $backend], $backend_config);
      }
    }
  }
}