670134c3455ad09f897aec759b198581fd0c1ffa
[yaffs-website] / web / modules / contrib / migrate_plus / migrate_example_advanced / migrate_example_advanced_setup / src / Plugin / rest / resource / VarietyItems.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_items",
13  *   label = @Translation("Advanced migration example - Variety data"),
14  *   uri_paths = {
15  *     "canonical" = "/migrate_example_advanced_variety_list/{variety}"
16  *   }
17  * )
18  */
19 class VarietyItems extends ResourceBase {
20
21   /**
22    * Responds to GET requests.
23    *
24    * @param string $variety
25    *   Machine name of the variety to retrieve.
26    *
27    * @return \Drupal\rest\ResourceResponse
28    *   The response containing the requested variety data.
29    */
30   public function get($variety = NULL) {
31     $varieties = [
32       'retsina' => [
33         'name' => 'Retsina',
34         // The categoryid for 'white'.
35         'parent' => 1,
36         'details' => 'Greek',
37       ],
38       'trebbiano' => [
39         'name' => 'Trebbiano',
40         // The categoryid for 'white'.
41         'parent' => 1,
42         'details' => 'Italian',
43       ],
44       'valpolicella' => [
45         'name' => 'Valpolicella',
46         // The categoryid for 'red'.
47         'parent' => 3,
48         'details' => 'Italian Venoto region',
49       ],
50       'bardolino' => [
51         'name' => 'Bardolino',
52         // The categoryid for 'red'.
53         'parent' => 3,
54         'details' => 'Italian Venoto region',
55       ],
56     ];
57     if (isset($varieties[$variety])) {
58       $data = ['variety' => $varieties[$variety]];
59     }
60     else {
61       $data = [];
62     }
63
64     $response = new ResourceResponse($data, 200);
65     return $response;
66   }
67
68   /**
69    * {@inheritdoc}
70    */
71   public function permissions() {
72     // Remove permissions so the resource is available to all.
73     return [];
74   }
75
76 }