public function WebhooksSettingsForm::submitForm in Acquia Content Hub 8
Form submission 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 ConfigFormBase::submitForm
File
- src/
Form/ WebhooksSettingsForm.php, line 157
Class
- WebhooksSettingsForm
- Defines the form to register the webhooks.
Namespace
Drupal\acquia_contenthub\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$webhook_url = NULL;
if ($form_state
->hasValue('webhook_url')) {
$webhook_url = $form_state
->getValue('webhook_url');
}
$webhook_register = (bool) $form_state
->getValue('webhook_uuid');
// Establish current uuid from config.
$config = $this->configFactory
->getEditable('acquia_contenthub.admin_settings');
$webhook_uuid = $config
->get('webhook_uuid');
// User clicked Submit, but url is already registered.
if ($webhook_register && $webhook_uuid) {
$this
->messenger()
->addWarning($this
->t('No change in webhook status was taken.'));
}
elseif ($webhook_register) {
$success = $this->contentHubSubscription
->registerWebhook($webhook_url);
if (!$success) {
$this
->messenger()
->addError($this
->t('There was a problem trying to register this webhook.'));
}
}
else {
$success = $this->contentHubSubscription
->unregisterWebhook($webhook_url);
if (!$success) {
$this
->messenger()
->addError($this
->t('There was a problem trying to unregister this webhook.'));
}
}
}