/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { try { $response = $this->client->nspiCall('/agent-api/subscription', array('identifier' => trim($form_state->getValue('acquia_identifier'))), trim($form_state->getValue('acquia_key'))); } catch (ConnectorException $e) { // Set form error to prevent switching to the next page. if ($e->isCustomized()) { // Allow to connect with expired subscription if ($e->getCustomMessage('code') == Subscription::EXPIRED) { $form_state->setValue('subscription', 'Expired subscription.'); return; } acquia_connector_report_restapi_error($e->getCustomMessage('code'), $e->getCustomMessage()); $form_state->setErrorByName(''); } else { $form_state->setErrorByName('', t('Server error, please submit again.')); } return; } $response = $response['result']; if (empty($response['body']['subscription_name'])) { $form_state->setErrorByName('acquia_identifier', t('No subscriptions were found.')); } else { $form_state->setValue('subscription', $response['body']['subscription_name']); } }