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_items",
13 * label = @Translation("Advanced migration example - Variety data"),
15 * "canonical" = "/migrate_example_advanced_variety_list/{variety}"
19 class VarietyItems extends ResourceBase {
22 * Responds to GET requests.
24 * @param string $variety
25 * Machine name of the variety to retrieve.
27 * @return \Drupal\rest\ResourceResponse
28 * The response containing the requested variety data.
30 public function get($variety = NULL) {
34 'parent' => 1, // categoryid for 'white'.
38 'name' => 'Trebbiano',
39 'parent' => 1, // categoryid for 'white'.
40 'details' => 'Italian',
43 'name' => 'Valpolicella',
44 'parent' => 3, // categoryid for 'red'.
45 'details' => 'Italian Venoto region',
48 'name' => 'Bardolino',
49 'parent' => 3, // categoryid for 'red'.
50 'details' => 'Italian Venoto region',
53 if (isset($varieties[$variety])) {
54 $data = ['variety' => $varieties[$variety]];
60 $response = new ResourceResponse($data, 200);
67 public function permissions() {
68 // Remove permissions so the resource is available to all.