You are here

function calendar_systems_calendars_form in Calendar Systems 6.2

Form callback to list all available calendars and their config links.

Return value

An array of form elements to be themed later on.

1 string reference to 'calendar_systems_calendars_form'
calendar_systems_menu in ./calendar_systems.module
Implements hook_menu().

File

./calendar_systems.admin.inc, line 16
Implements necessary callbacks for Calendar Systems administration forms.

Code

function calendar_systems_calendars_form() {
  $form = array();

  // Include patch helpers.
  module_load_include('patch.inc', 'calendar_systems');

  // Do not show the calendars form in case that
  // the required core patches is not yet applied.
  if (!_calendar_systems_patches_applied()) {
    $form['calendar_systems_error'] = array(
      '#type' => 'item',
      '#value' => t('Calendar Systems is not correctly installed. Please checkout the <a href="!link">status reports</a>.', array(
        '!link' => url('admin/reports/status'),
      )),
    );

    // Let it be rendered.
    return $form;
  }
  $options = array();

  // Get a list of available calendars.
  $calendars = calendar_systems_calendars();

  // Generate site-wide options.
  $form['sitewide'] = array();
  foreach ($calendars as $identifier => $calendar) {
    $options[$identifier] = '';

    // Add fake elements to be themed later on.
    $form['sitewide'][$calendar['name']]['_id'] = array(
      '#value' => $identifier,
    );

    // Also add calendar configuration link.
    $form['sitewide'][$calendar['name']]['_config'] = array(
      '#value' => function_exists($calendar['config callback']) ? l(t('Configuration'), 'admin/settings/date-time/calendars/' . $identifier) : t('No configuration'),
    );
  }

  // Append the default calendar radio group.
  $form['default_calendar'] = array(
    '#type' => 'radios',
    '#options' => $options,
    '#default_value' => variable_get('calendar_systems_default_calendar', 'gregorian'),
  );
  global $user;

  // Note for locale and user specific calendar configs.
  $form['calendar_systems_notice'] = array(
    '#type' => 'item',
  );

  // If the locale module is available:
  if (function_exists('locale')) {
    $form['calendar_systems_notice']['#value'] = t('Calendars are also configurable per <a href="!locale-link">locale</a> and <a href="!user-link">user</a> basis.', array(
      '!user-link' => url("user/{$user->uid}/edit"),
      '!locale-link' => url('admin/settings/language'),
    ));
  }
  else {
    $form['calendar_systems_notice']['#value'] = t('Calendars are also configurable per <a href="!user-link">user</a> basis. If you had the locale module enabled, you could also configure them per locale basis.', array(
      '!user-link' => url("user/{$user->uid}/edit"),
    ));
  }

  // Append the submit button.
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Set as default calendar'),
  );
  return $form;
}