diff --git a/src/Form/DelivererConfigurationForm.php b/src/Form/DelivererConfigurationForm.php index d291dbd..a6eb0ca 100644 --- a/src/Form/DelivererConfigurationForm.php +++ b/src/Form/DelivererConfigurationForm.php @@ -38,6 +38,15 @@ class DelivererConfigurationForm extends PluginConfigurationForm { /** * {@inheritdoc} */ + public function validateForm(array &$form, FormStateInterface $form_state) { + if ($this->exists($form_state->getValue('id'))) { + $form_state->setErrorByName('id', $this->t('A plugin with @id already exists.', ['@id' => $form_state->getValue('id')])); + } + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $form = parent::buildForm($form, $form_state); $entity = $this->getEntity(); diff --git a/src/Tests/InmailWebTest.php b/src/Tests/InmailWebTest.php index 963803e..cafe9a4 100644 --- a/src/Tests/InmailWebTest.php +++ b/src/Tests/InmailWebTest.php @@ -108,6 +108,19 @@ class InmailWebTest extends WebTestBase { $this->assertUrl('admin/config/system/inmail/deliverers'); $this->assertText('Test IMAP Fetcher'); + // Add an IMAP fetcher with an existing id. + $this->drupalGet('admin/config/system/inmail/deliverers/add'); + // Select the IMAP plugin. + $edit = array( + 'label' => 'Test IMAP Fetcher', + 'id' => 'test_imap', + 'plugin' => 'imap', + ); + $this->drupalPostAjaxForm(NULL, $edit, 'plugin'); + // Try to save and assert message for existing plugin id. + $this->drupalPostForm(NULL, $edit, 'Save'); + $this->assertText('A plugin with test_imap already exists.'); + // Add a Drush deliverer. It implements different interfaces and // PluginConfigurationForm has to support that. $this->drupalGet('admin/config/system/inmail/deliverers/add');