You are here

public function WebformFieldsResource::get in Webform REST 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/rest/resource/WebformFieldsResource.php \Drupal\webform_rest\Plugin\rest\resource\WebformFieldsResource::get()
  2. 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\resource

Code

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) {

    // Return only the form elements.
    return new ModifiedResourceResponse($webform
      ->getElementsInitialized());
  }
  throw new NotFoundHttpException(t("Can't load webform."));
}