You are here

private static function FormHookHandler::doFormAlter in Node expire 7.2

Implements hook_form_alter().

Adds expiration options to the node entry forms.

1 call to FormHookHandler::doFormAlter()
FormHookHandler::hookFormAlter in src/Module/Hook/FormHookHandler.php
Implements hook_form_alter().

File

src/Module/Hook/FormHookHandler.php, line 154
FormHookHandler class.

Class

FormHookHandler
FormHookHandler class.

Namespace

Drupal\node_expire\Module\Hook

Code

private static function doFormAlter(&$ntype, &$form, &$form_state, $form_id) {

  // Check if the Node expire feature is enabled for the node type.
  $node = isset($form['#node']) ? $form['#node'] : NULL;
  $handle_content_expiry = ConfigHandler::getHandleContentExpiry();
  if ($handle_content_expiry != 0) {
    if (empty($ntype['enabled'])) {
      return;
    }

    // Replace not set to default string.
    if (!isset($node->expire)) {

      // $ntype = isset($ntypes[$node->type]) ? $ntypes[$node->type] : NULL;
      $node->expire = TimestampUtils::dateDbToStr('', $ntype);
    }
  }
  else {

    // Replace not set to empty string.
    if (!isset($node->expire)) {
      $node->expire = '';
    }

    // Convert the timestamp into a human readable date - legacy branch.
    if (is_numeric($node->expire)) {
      $node->expire = format_date($node->expire, 'custom', ConfigHandler::getDateFormat());
    }
  }

  // This supports node to never expire.
  if (empty($ntype['default']) && empty($node->expire)) {
    $ntype['required'] = FALSE;
  }
  if (user_access('edit node expire')) {
    if (ConfigHandler::getDateEntryElements()) {

      // Date popups.
      // TODO: Edit format description sting.
      $expire_field = array(
        '#title' => t('Expiration date'),
        '#description' => t('Time date to consider the node expired. Format: %time (%format).', array(
          '%time' => format_date(REQUEST_TIME, 'custom', ConfigHandler::getDateFormat()),
          '%format' => ConfigHandler::getDateFormat(),
        )),
        '#type' => 'date_popup',
        '#date_format' => ConfigHandler::getDateFormat(),
        '#required' => $ntype['required'],
        '#default_value' => $node->expire,
      );
    }
    else {

      // Text fields.
      // TODO: Edit format description sting.
      $expire_field = array(
        '#title' => t('Expiration date'),
        '#description' => t('Time date to consider the node expired. Format: %time (%format).', array(
          '%time' => format_date(REQUEST_TIME, 'custom', ConfigHandler::getDateFormat()),
          '%format' => ConfigHandler::getDateFormat(),
        )),
        '#type' => 'textfield',
        '#maxlength' => 25,
        '#required' => $ntype['required'],
        '#default_value' => $node->expire,
      );
    }
  }
  else {
    $expire_field = array(
      '#type' => 'value',
      '#value' => $node->expire,
    );
  }

  // If we use hidden value, do not create fieldset.
  if ($expire_field['#type'] == 'value') {
    $form['options1'] = array();
    $form['options1']['expire'] =& $expire_field;
  }
  elseif (!$form['options']['#access']) {
    $form['options1'] = array(
      '#type' => 'fieldset',
      '#title' => t('Publishing options'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      '#weight' => 95,
    );
    $form['options1']['expire'] =& $expire_field;
  }
  else {
    $form['options']['expire'] =& $expire_field;
  }
  if (isset($node->expired)) {
    $form['node_expire'] = array(
      '#type' => 'value',
      '#value' => TRUE,
    );
  }
}