You are here

private static function NodeHookHandler::doNodeValidate in Node expire 7.2

Implements hook_node_validate().

1 call to NodeHookHandler::doNodeValidate()
NodeHookHandler::hookNodeValidate in src/Module/Hook/NodeHookHandler.php
Implements hook_node_validate().

File

src/Module/Hook/NodeHookHandler.php, line 161
NodeHookHandler class.

Class

NodeHookHandler
NodeHookHandler class.

Namespace

Drupal\node_expire\Module\Hook

Code

private static function doNodeValidate(&$ntype, $node) {
  $handle_content_expiry = ConfigHandler::getHandleContentExpiry();
  if ($handle_content_expiry != 0) {
    if (!isset($ntype['enabled']) || !$ntype['enabled']) {
      return;
    }
  }

  // The only restriction we have is that the node can't expire in the past.
  if ($node->expire == '') {
    if (!empty($ntype['required']) && $ntype['default']) {
      form_set_error('expire_date', t('You must choose an expiration date.'));
    }
  }
  elseif (!($expire = strtotime($node->expire)) or $expire <= 0) {
    form_set_error('expire_date', t('You have to specify a valid expiration date.'));
  }
  elseif (variable_get('node_expire_past_date_allowed', 0) == 0 && $expire <= REQUEST_TIME) {
    form_set_error('expire_date', t("You can't expire a node in the past!"));
  }
  elseif (!empty($ntype['max']) and $expire > strtotime($ntype['max'])) {
    form_set_error('expire_date', t('It must expire before %date.', array(
      '%date' => format_date(strtotime($ntype['max']), 'custom', ConfigHandler::getDateFormat()),
    )));
  }
}