Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

D9 compat. #17

Merged
merged 3 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion embargoes.info.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Embargoes
description: 'A module for managing embargo policies with access restrictions on content.'
type: module
core: 8.x
core_version_requirement: ^8 || ^9
dependencies:
- menu_ui
2 changes: 1 addition & 1 deletion modules/embargoes_log_views/embargoes_log_views.info.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Embargoes Log Views
description: 'Provides views for embargo logs.'
type: module
core: 8.x
core_version_requirement: ^8 || ^9
dependencies:
- embargoes
- views
44 changes: 28 additions & 16 deletions src/Form/EmbargoesIpRangeEntityForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public function form(array $form, FormStateInterface $form_state) {
'#default_value' => implode('|', $range->getRanges()),
'#description' => $this->t("IP range to be used. Please list in CIDR format, and separate multiple ranges with a '|'."),
'#required' => TRUE,
'#element_validate' => [
'::validateIpRanges',
],
];

$form['proxy_url'] = [
Expand All @@ -82,6 +85,24 @@ public function form(array $form, FormStateInterface $form_state) {
return $form;
}

/**
* Validates the IP range entered.
*
* @param array $element
* An array representing the element.
* @param Drupal\Core\Form\FormStateInterface $form_state
* The Drupal form state.
*/
public function validateIpRanges(array $element, FormStateInterface $form_state) {
$errors = $this->ipRanges->detectIpRangeStringErrors(array_map('trim', explode('|', trim($form_state->getValue('range')))));
if (!empty($errors)) {
$form_state->setError($element, $this->t('Problems detected with the %label IP Range.', ['%label' => $this->entity->label()]));
foreach ($errors as $error) {
$this->messenger()->addError($this->t('Error: %error.', ['%error' => $error]));
jordandukart marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

/**
* {@inheritdoc}
*/
Expand All @@ -91,22 +112,13 @@ public function save(array $form, FormStateInterface $form_state) {
$range->setProxyUrl($form_state->getValue('proxy_url'));
$status = $range->save();

$errors = $this->ipRanges->detectIpRangeStringErrors(array_map('trim', explode('|', trim($form_state->getValue('range')))));
if (!$errors) {
switch ($status) {
case SAVED_NEW:
$this->messenger()->addMessage($this->t('Created the %label IP Range.', ['%label' => $range->label()]));
break;

default:
$this->messenger()->addMessage($this->t('Saved the %label IP Range.', ['%label' => $range->label()]));
}
}
else {
drupal_set_message("Problems detected with the {$range->label()} IP Range.", 'error');
foreach ($errors as $error) {
drupal_set_message("Error: {$error}.", 'error');
}
switch ($status) {
case SAVED_NEW:
$this->messenger()->addMessage($this->t('Created the %label IP Range.', ['%label' => $range->label()]));
break;

default:
$this->messenger()->addMessage($this->t('Saved the %label IP Range.', ['%label' => $range->label()]));
}
$form_state->setRedirectUrl($range->toUrl('collection'));
}
Expand Down