3 namespace Drupal\migrate_example_advanced_setup\Plugin\rest\resource;
5 use Drupal\rest\Plugin\ResourceBase;
6 use Drupal\rest\ResourceResponse;
9 * Provides varieties as two endpoints, one for reds and one for whites.
12 * id = "migrate_example_advanced_variety_multiple",
13 * label = @Translation("Advanced migration example - Variety data"),
15 * "canonical" = "/migrate_example_advanced_variety_multiple/{type}"
19 class VarietyMultiFiles extends ResourceBase {
22 * Responds to GET requests.
25 * 'red', 'white', or NULL to return all varieties.
27 * @return \Drupal\rest\ResourceResponse
28 * The response containing the requested variety data.
30 public function get($type = NULL) {
32 if (strtolower($type) != 'white') {
33 $data['variety'][] = [
35 'parent' => 3, // categoryid for 'red'.
36 'details' => 'Italian Venoto region',
42 $data['variety'][] = [
43 'name' => 'Barbaresco',
44 'parent' => 3, // categoryid for 'red'.
45 'details' => 'Italian Piedmont region',
52 if (strtolower($type) != 'red') {
53 $data['variety'][] = [
55 'parent' => 1, // categoryid for 'white'.
56 'details' => 'French Burgundy region',
59 $data['variety'][] = [
60 'name' => 'Pinot Grigio',
61 'parent' => 1, // categoryid for 'white'.
62 'details' => 'From the northeast of Italy',
71 $response = new ResourceResponse($data, 200);
78 public function permissions() {
79 // Remove permissions so the resource is available to all.