5db35b5ce848955054a5e2cba7e91d6dec5dbe1d
[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         // The categoryid for 'red'.
36         'parent' => 3,
37         'details' => 'Italian Venoto region',
38         'attributes' => [
39           'rich',
40           'aromatic',
41         ],
42       ];
43       $data['variety'][] = [
44         'name' => 'Barbaresco',
45         // The categoryid for 'red'.
46         'parent' => 3,
47         'details' => 'Italian Piedmont region',
48         'attributes' => [
49           'smoky',
50           'earthy',
51         ],
52       ];
53     }
54     if (strtolower($type) != 'red') {
55       $data['variety'][] = [
56         'name' => 'Kir',
57         // The categoryid for 'white'.
58         'parent' => 1,
59         'details' => 'French Burgundy region',
60         'attributes' => [],
61       ];
62       $data['variety'][] = [
63         'name' => 'Pinot Grigio',
64         // The categoryid for 'white'.
65         'parent' => 1,
66         'details' => 'From the northeast of Italy',
67         'attributes' => [
68           'fruity',
69           'medium-bodied',
70           'slightly sweet',
71         ],
72       ];
73     }
74
75     $response = new ResourceResponse($data, 200);
76     return $response;
77   }
78
79   /**
80    * {@inheritdoc}
81    */
82   public function permissions() {
83     // Remove permissions so the resource is available to all.
84     return [];
85   }
86
87 }