Skip to content
Snippets Groups Projects
Commit a090f86d authored by Aaron Bauman's avatar Aaron Bauman
Browse files

Submit a test pull query on Mapping edit form validate to make sure the where clause works ok.

parent 6fe0e521
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,8 @@ use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\ReplaceCommand;
use Drupal\Core\Form\FormStateInterface;
use Drupal\salesforce_mapping\MappingConstants;
use Drupal\salesforce\Event\SalesforceEvents;
use Drupal\salesforce\Event\SalesforceErrorEvent;
/**
* Salesforce Mapping Form base.
......@@ -258,6 +260,16 @@ abstract class SalesforceMappingFormCrudBase extends SalesforceMappingFormBase {
// @TODO replace with Dependency Injection
$form_state->setError($element, $this->t('%name field is required.', ['%name' => $element['#title']]));
}
// dpm($form_state->getValues());
if ($this->entity->doesPull()) {
try {
$testQuery = $this->client->query($this->entity->getPullQuery());
}
catch (\Exception $e) {
$form_state->setError($form['pull']['pull_where_clause'], $this->t('Test pull query returned an error. Please check logs for error details.'));
\Drupal::service('event_dispatcher')->dispatch(SalesforceEvents::ERROR, new SalesforceErrorEvent($e));
}
}
}
/**
......
......@@ -16,8 +16,21 @@ class RestException extends \RuntimeException implements ExceptionInterface {
*
*/
public function __construct(ResponseInterface $response, $message = "", $code = 0, Throwable $previous = NULL) {
parent::__construct($message, $code, $previous);
$this->response = $response;
$message .= $this->getResponseBody();
parent::__construct($message, $code, $previous);
}
public function getResponse() {
return $this->response;
}
public function getResponseBody() {
$body = $this->response->getBody();
if ($body) {
return $body->getContents();
}
return '';
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment