public function CclActionsForm::validateForm in Custom Contextual Links 8
Form validation handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormBase::validateForm
File
- ccl_actions/
src/ Form/ CclActionsForm.php, line 135 - Contains \Drupal\ccl_actions\Form\CclActionsForm.
Class
Namespace
Drupal\ccl_actions\FormCode
public function validateForm(array &$form, \Drupal\Core\Form\FormStateInterface $form_state) {
$values = $form_state
->getValues();
// Check that that we can get the node id and transform it for saving.
if ($values['node_options'] == 'node') {
if (is_numeric($values['node_id'])) {
$form_state
->setValueForElement($form['options_group']['node_id'], $values['node_id']);
}
elseif (preg_match('/\\[nid:[0-9]*\\]/', $values['node_id'], $match)) {
$form_state
->setValueForElement($form['options_group']['node_id'], substr(rtrim($match[0], ']'), 5));
}
else {
$form_state
->setErrorByName('nid', t('Enter a node id or use the autocomplete widget to select an existing node.'));
}
}
}