You are here

function _ajax_loader_settings_form in Ajax loader 7

Renders ajax loader settings form.

_state

Parameters

$form:

Return value

mixed

1 string reference to '_ajax_loader_settings_form'
ajax_loader_menu in ./ajax_loader.module
Implements hook_menu().

File

includes/settings.ajax_loader.inc, line 14
Contains ajax loader settings form.

Code

function _ajax_loader_settings_form($form, &$form_state) {
  $settings = variable_get('ajax_loader_settings', array());
  $form['wrapper'] = array(
    '#prefix' => '<div id="throbber-wrapper">',
    '#suffix' => '</div>',
  );
  $form['wrapper']['throbber'] = array(
    '#type' => 'select',
    '#title' => t('Throbber'),
    '#description' => t('Choose your throbber'),
    '#required' => TRUE,
    '#options' => _ajax_loader_get_options(),
    '#default_value' => isset($settings['throbber']) ? $settings['throbber'] : NULL,
    '#ajax' => array(
      'wrapper' => 'throbber-wrapper',
      'callback' => 'ajax_loader_change',
    ),
  );
  if (!empty($form_state['values']['throbber']) || isset($settings['throbber'])) {

    // Show preview of throbber.
    if (!empty($form_state['values']['throbber'])) {
      $class = $form_state['values']['throbber'];
    }
    else {
      $class = $settings['throbber'];
    }

    /** @var ThrobberInterface $throbber */
    $throbber = new $class();
    $form['wrapper']['throbber']['#attached']['css'] = array(
      array(
        'data' => drupal_get_path('module', 'ajax_loader') . '/css/throbber-general.css',
        'type' => 'file',
      ),
      array(
        'data' => $throbber
          ->getCssFile(),
        'type' => 'file',
      ),
      array(
        'data' => drupal_get_path('module', 'ajax_loader') . '/css/throbber-admin.css',
        'type' => 'file',
      ),
    );
    $form['wrapper']['throbber']['#suffix'] = '<span class="throbber-example">' . $throbber
      ->getMarkup() . '</span>';
  }
  $form['hide_ajax_message'] = array(
    '#type' => 'checkbox',
    '#title' => t('Never show ajax loading message'),
    '#description' => t('Choose whether you want to hide the loading ajax message even when it is set.'),
    '#default_value' => isset($settings['hide_ajax_message']) ? $settings['hide_ajax_message'] : 0,
  );
  $form['show_admin_paths'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use ajax loader on admin pages'),
    '#description' => t('Choose whether you also want to show the loader on admin pages or still like to use the default core loader.'),
    '#default_value' => isset($settings['show_admin_paths']) ? $settings['show_admin_paths'] : 0,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}