public function TermsOfUseForm::validateForm in Terms of Use 8
First check if a nid was set. Then check if the nid exists
Overrides FormBase::validateForm
File
- src/
Form/ TermsOfUseForm.php, line 96 - Contains \Drupal\terms_of_use\Form\TermsOfUseForm.
Class
Namespace
Drupal\terms_of_use\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
if (NULL !== $form_state
->getValue('terms_of_use_node_id')) {
$nid = $form_state
->getValue('terms_of_use_node_id');
if (empty($nid)) {
$form_state
->setErrorByName('terms_of_use_node_id', $this
->t('You must specify a node <em>nid</em>.'));
}
else {
$node = Node::load($nid);
if ($node == NULL) {
$form_state
->setErrorByName('terms_of_use_node_id', $this
->t('No post was published with <em>nid</em> !nid.', array(
'!nid' => $nid,
)));
}
else {
$this->node_title = $node
->label();
}
}
}
/*
elseif (!empty($form_state['values']['terms_of_use_node_title'])) {
$nid = db_select('node', 'n')
->fields('n', array('nid'))
->condition('n.title', db_like($form_state['values']['terms_of_use_node_title']), 'LIKE')
->condition('n.status', 1)
->range(0, 1)
->addTag('node_access')
->execute()
->fetchField();
if (!$nid) {
$form_state->setErrorByName('terms_of_use_node_title', $this->t('No post was published with this title.'));
}
else {
$config->set('node_id', $nid);
}
}
else {
$form_state->setErrorByName('terms_of_use_node_title', $this->t('You must specify a node title.'));
}*/
}