4c1a49907fc446b10cdb7202564646109bb65a4b
[yaffs-website] / web / modules / contrib / migrate_plus / migrate_example_advanced / migrate_example_advanced_setup / src / Plugin / rest / resource / VarietyMultiFiles.php
1 <?php
2
3 namespace Drupal\migrate_example_advanced_setup\Plugin\rest\resource;
4
5 use Drupal\rest\Plugin\ResourceBase;
6 use Drupal\rest\ResourceResponse;
7
8 /**
9  * Provides varieties as two endpoints, one for reds and one for whites.
10  *
11  * @RestResource(
12  *   id = "migrate_example_advanced_variety_multiple",
13  *   label = @Translation("Advanced migration example - Variety data"),
14  *   uri_paths = {
15  *     "canonical" = "/migrate_example_advanced_variety_multiple/{type}"
16  *   }
17  * )
18  */
19 class VarietyMultiFiles extends ResourceBase {
20
21   /**
22    * Responds to GET requests.
23    *
24    * @param string $type
25    *   'red', 'white', or NULL to return all varieties.
26    *
27    * @return \Drupal\rest\ResourceResponse
28    *   The response containing the requested variety data.
29    */
30   public function get($type = NULL) {
31     $data = [];
32     if (strtolower($type) != 'white') {
33       $data['variety'][] = [
34         'name' => 'Amarone',
35         'parent' => 3,  // categoryid for 'red'.
36         'details' => 'Italian Venoto region',
37         'attributes' => [
38           'rich',
39           'aromatic',
40         ],
41       ];
42       $data['variety'][] = [
43         'name' => 'Barbaresco',
44         'parent' => 3,  // categoryid for 'red'.
45         'details' => 'Italian Piedmont region',
46         'attributes' => [
47           'smoky',
48           'earthy',
49         ],
50       ];
51     }
52     if (strtolower($type) != 'red') {
53       $data['variety'][] = [
54         'name' => 'Kir',
55         'parent' => 1,  // categoryid for 'white'.
56         'details' => 'French Burgundy region',
57         'attributes' => [],
58       ];
59       $data['variety'][] = [
60         'name' => 'Pinot Grigio',
61         'parent' => 1,  // categoryid for 'white'.
62         'details' => 'From the northeast of Italy',
63         'attributes' => [
64           'fruity',
65           'medium-bodied',
66           'slightly sweet',
67         ],
68       ];
69     }
70
71     $response = new ResourceResponse($data, 200);
72     return $response;
73   }
74
75   /**
76    * {@inheritdoc}
77    */
78   public function permissions() {
79     // Remove permissions so the resource is available to all.
80     return [];
81   }
82
83 }