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 // The categoryid for 'white'.
39 'name' => 'Trebbiano',
40 // The categoryid for 'white'.
42 'details' => 'Italian',
45 'name' => 'Valpolicella',
46 // The categoryid for 'red'.
48 'details' => 'Italian Venoto region',
51 'name' => 'Bardolino',
52 // The categoryid for 'red'.
54 'details' => 'Italian Venoto region',
57 if (isset($varieties[$variety])) {
58 $data = ['variety' => $varieties[$variety]];
64 $response = new ResourceResponse($data, 200);
71 public function permissions() {
72 // Remove permissions so the resource is available to all.