public function WebformFieldsResource::get in Webform REST 8.3
Same name and namespace in other branches
- 8.2 src/Plugin/rest/resource/WebformFieldsResource.php \Drupal\webform_rest\Plugin\rest\resource\WebformFieldsResource::get()
- 4.x src/Plugin/rest/resource/WebformFieldsResource.php \Drupal\webform_rest\Plugin\rest\resource\WebformFieldsResource::get()
Responds to GET requests, returns webform elements.
Parameters
string $webform_id: Webform ID.
Return value
\Drupal\rest\ResourceResponse HTTP response object containing webform elements.
Throws
\Symfony\Component\HttpKernel\Exception\HttpException Throws HttpException in case of error.
File
- src/
Plugin/ rest/ resource/ WebformFieldsResource.php, line 36
Class
- WebformFieldsResource
- Creates a resource for retrieving webform elements.
Namespace
Drupal\webform_rest\Plugin\rest\resourceCode
public function get($webform_id) {
if (empty($webform_id)) {
throw new BadRequestHttpException(t("Webform ID wasn't provided"));
}
// Load the webform.
$webform = Webform::load($webform_id);
// Basic check to see if something's returned.
if ($webform) {
// Grab the form in its entirety.
$form = $webform
->getSubmissionForm();
// Return only the form elements.
return new ModifiedResourceResponse($webform
->getElementsInitialized());
}
throw new NotFoundHttpException(t("Can't load webform."));
}