You are here

function _node_expire_node_validate in Node expire 8

Same name and namespace in other branches
  1. 7 node_expire.nodeapi.inc \_node_expire_node_validate()

Implements hook_node_validate().

1 call to _node_expire_node_validate()
node_expire_node_validate in ./node_expire.module
Implements hook_node_validate().

File

./node_expire.nodeapi.inc, line 72
Node API integration.

Code

function _node_expire_node_validate(&$ntype, \Drupal\node\NodeInterface $node) {
  $handle_content_expiry = \Drupal::config('node_expire.settings')
    ->get('node_expire_handle_content_expiry');
  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 (\Drupal::config('node_expire.settings')
    ->get('node_expire_past_date_allowed') == 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'], $node
    ->getCreatedTime())) {
    form_set_error('expire_date', t('It must expire before %date.', array(
      '%date' => format_date(strtotime($ntype['max'], $node
        ->getCreatedTime()), 'custom', NODE_EXPIRE_FORMAT),
    )));
  }
}