public function CslStyleForm::validateForm in Bibliography & Citation 8
Same name and namespace in other branches
- 2.0.x src/Form/CslStyleForm.php \Drupal\bibcite\Form\CslStyleForm::validateForm()
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
1 call to CslStyleForm::validateForm()
- CslStyleFileForm::validateForm in src/
Form/ CslStyleFileForm.php - Form validation handler.
1 method overrides CslStyleForm::validateForm()
- CslStyleFileForm::validateForm in src/
Form/ CslStyleFileForm.php - Form validation handler.
File
- src/
Form/ CslStyleForm.php, line 78
Class
- CslStyleForm
- Add/edit form for bibcite_csl_style entity.
Namespace
Drupal\bibcite\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\bibcite\Entity\CslStyleInterface $csl_style */
$csl_style = $this
->getEntity();
$csl = new Csl($form_state
->getValue('csl'));
if ($csl_style
->isNew()) {
$this
->validateUnique($form, $form_state, $csl
->getId());
if ($parent_url = $csl
->getParent()) {
$this
->validateParent($form, $form_state, $parent_url);
}
}
if (!$csl_style
->isNew()) {
/** @var \Drupal\bibcite\Entity\CslStyleInterface $original_csl_style */
$original_csl_style = $this->entityTypeManager
->getStorage($csl_style
->getEntityTypeId())
->load($csl_style
->id());
if ($csl_style
->calculateHash() != $original_csl_style
->calculateHash()) {
if ($original_csl_style
->getUrlId() != $csl
->getId()) {
$this
->validateUnique($form, $form_state, $csl
->getId());
}
if ($parent_url = $csl
->getParent()) {
$this
->validateParent($form, $form_state, $parent_url);
}
}
$default_style = $this
->config('bibcite.settings')
->get('default_style');
if (!$csl_style
->status() && $default_style == $csl_style
->id()) {
$form_state
->setErrorByName('status', $this
->t('You can not disable default style.'));
}
}
}