1 locale.admin.inc locale_date_format_form($form, &$form_state, $format)

Form callback; Display fields for setting the date format for each language.

File

core/modules/locale/locale.admin.inc, line 324
Admin page callbacks for the Locale module.

Code

function locale_date_format_form($form, &$form_state, $format) {
  backdrop_set_title(t('Localize date format %format', array('%format' => $format['label'])), PASS_THROUGH);

  // We use the system_date_time_lookup() function from system.admin.inc.
  form_load_include($form_state, 'inc', 'system', 'system.admin');
  $form_state['format'] = $format;

  $form['#tree'] = TRUE;
  $form['help'] = array(
    '#type' => 'help',
    '#markup' => t('Each language may format dates and times differently. Languages without a specific format will fallback to the default. See the <a href="@url" target="_blank">PHP manual</a> for available options.', array('@url' => 'https://www.php.net/manual/datetime.format.php#refsect1-datetime.format-parameters')),
  );

  $form['locales']['default'] = array(
    '#type' => 'item',
    '#title' => t('Default'),
    '#markup' => '<strong>' . check_plain($format['pattern']) . '</strong>',
    '#field_suffix' => '<small>' . t('Displayed as %date_format', array('%date_format' => format_date(REQUEST_TIME, 'custom', $format['pattern']))) . '</small>',
  );

  // Get the enabled languages only.
  $languages = language_list(TRUE);
  foreach ($languages as $langcode => $language) {
    $pattern = isset($format['locales'][$langcode]) ? $format['locales'][$langcode] : '';
    if (!empty($form_state['values']['locales'][$langcode])) {
      $pattern = $form_state['values']['locales'][$langcode];
    }
    $placeholder_pattern = $pattern ? $pattern : $format['pattern'];
    $preview = t('Displayed as %date_format', array('%date_format' => format_date(REQUEST_TIME, 'custom', $placeholder_pattern)));

    $form['locales'][$langcode] = array(
      '#title' => check_plain($language->name),
      '#type' => 'textfield',
      '#maxlength' => 100,
      '#default_value' => $pattern,
      '#field_suffix' => '<small class="pattern-preview">' . $preview . '</small>',
      '#ajax' => array(
        'callback' => 'system_date_time_lookup',
        'event' => 'keyup',
        'progress' => array('type' => 'none', 'message' => NULL),
        'disable' => FALSE,
      ),
      '#placeholder' => $placeholder_pattern,
      '#size' => 30,
      '#wrapper_attributes' => array(
        'id' => 'locale-pattern-' . $langcode,
      ),
    );
  }

  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );

  return $form;
}