You are here

function datex_form_alter in Datex 7

Same name and namespace in other branches
  1. 7.3 datex.module \datex_form_alter()
  2. 7.2 datex.module \datex_form_alter()

Implements hook_form_alter().

Looks for node editing forms and adds a Jalali calendar to author information editing field in vertical tabs.

File

./datex.module, line 163
Convert output of date_format() to Jalali in a patched drupal installation.

Code

function datex_form_alter(&$form, &$form_state, $form_id) {

  // Make sure this is a node edit form and date element is present.
  if (_datex_skip_language() || !isset($form['#node_edit_form'])) {
    return;
  }

  // Add a nice datepicker and an small jQuery file which attaches that
  // datepicker to node_edit_form form element.
  if (variable_get('datex_jquery', FALSE)) {
    _datex_jquery_add_libraries('jquery.datetimeentry', 'fa');
    drupal_add_js(drupal_get_path('module', 'datex') . '/datex_jquery.js');
  }
  $now = datex_format(time(), 'o-m-d H:i:s O');
  $validator = array(
    '_datex_node_edit_form_author_date_validate',
  );
  if (isset($form['author']['date'])) {
    $t_args = array(
      '%date' => $now,
    );
    $form['author']['date']['#description'] = t('Format: %date The date format is YYYY-MM-DD and time is H:i:s. Leave blank to use the time of form submission.', $t_args);
    $form['author']['date']['#element_validate'] = $validator;
  }
  $mode = _datex_integration_mode(DATEX_THEMING_METHOD);
  if (isset($form['scheduler_settings'])) {
    foreach (array(
      'publish_on',
      'unpublish_on',
    ) as $name) {
      if (isset($form['scheduler_settings'][$name])) {
        $form['scheduler_settings'][$name]['#element_validate'] = $validator;
      }
      if ($mode) {
        if (isset($form['#node']->scheduler[$name]) && !empty($form['scheduler_settings'][$name]['#default_value'])) {
          $form['scheduler_settings'][$name]['#default_value'] = datex_format($form['#node']->scheduler[$name], 'Y-m-d H:i:s O');
        }
        $form['scheduler_settings'][$name]['#description'] = t('Format: %date The date format is YYYY-MM-DD and time is H:i:s. Leave blank to disable scheduled.', array(
          '%date' => $now,
        ));
      }
    }
  }
  if ($mode && !empty($form['author']['date']['#default_value'])) {
    $form['author']['date']['#default_value'] = datex_format($form['created']['#value'], 'Y-m-d H:i:s O');
  }
}