Loading src/ApiMarkup.php +13 −6 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Session\AccountProxyInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Utility\Token; use Drupal\formassembly\Entity\FormAssemblyEntity; use GuzzleHttp\Client; Loading @@ -28,6 +29,8 @@ use Psr\Log\LoggerInterface; */ class ApiMarkup extends ApiBase { use StringTranslationTrait; /** * GuzzleHttp\Client definition. * Loading Loading @@ -149,16 +152,20 @@ class ApiMarkup extends ApiBase { // Make FA rest call and return form markup. $url = $this->getUrl('/rest/forms/view/' . $entity->faid->value); $url->setOptions(['query' => $params]); $request = $this->httpClient->get($url->toString(TRUE)->getGeneratedUrl()); // Guzzle throws an Exception on http 400/500 errors. // Ensure we have a 200. if ($request->getStatusCode() != 200) { throw new \UnexpectedValueException( 'Http return code 200 expected. Code ' . $request->getStatusCode() . ' received.' ); } try { $request = $this->httpClient->get($url->toString(TRUE)->getGeneratedUrl()); return $request->getBody()->getContents(); } catch (\Exception $e) { $this->logger->error('Form :id failed to load. Http return code 200 expected. Code ' . $e->getCode() . ' received.', [ ':id' => $entity->faid->value, ]); return '<div class="wFormContainer"><div class="wFormFailed">' . $this->t('Form failed to load.') . '</div></div>'; } } /** * Get the HTML for a FormAssembly next path using returned tfa_next value. Loading Loading
src/ApiMarkup.php +13 −6 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Session\AccountProxyInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Utility\Token; use Drupal\formassembly\Entity\FormAssemblyEntity; use GuzzleHttp\Client; Loading @@ -28,6 +29,8 @@ use Psr\Log\LoggerInterface; */ class ApiMarkup extends ApiBase { use StringTranslationTrait; /** * GuzzleHttp\Client definition. * Loading Loading @@ -149,16 +152,20 @@ class ApiMarkup extends ApiBase { // Make FA rest call and return form markup. $url = $this->getUrl('/rest/forms/view/' . $entity->faid->value); $url->setOptions(['query' => $params]); $request = $this->httpClient->get($url->toString(TRUE)->getGeneratedUrl()); // Guzzle throws an Exception on http 400/500 errors. // Ensure we have a 200. if ($request->getStatusCode() != 200) { throw new \UnexpectedValueException( 'Http return code 200 expected. Code ' . $request->getStatusCode() . ' received.' ); } try { $request = $this->httpClient->get($url->toString(TRUE)->getGeneratedUrl()); return $request->getBody()->getContents(); } catch (\Exception $e) { $this->logger->error('Form :id failed to load. Http return code 200 expected. Code ' . $e->getCode() . ' received.', [ ':id' => $entity->faid->value, ]); return '<div class="wFormContainer"><div class="wFormFailed">' . $this->t('Form failed to load.') . '</div></div>'; } } /** * Get the HTML for a FormAssembly next path using returned tfa_next value. Loading