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_multiple",
13 * label = @Translation("Advanced migration example - Variety data"),
15 * "canonical" = "/migrate_example_advanced_variety_multiple/{type}"
19 class VarietyMultiFiles extends ResourceBase {
22 * Responds to GET requests.
25 * 'red', 'white', or NULL to return all varieties.
27 * @return \Drupal\rest\ResourceResponse
28 * The response containing the requested variety data.
30 public function get($type = NULL) {
32 if (strtolower($type) != 'white') {
33 $data['variety'][] = [
35 // The categoryid for 'red'.
37 'details' => 'Italian Venoto region',
43 $data['variety'][] = [
44 'name' => 'Barbaresco',
45 // The categoryid for 'red'.
47 'details' => 'Italian Piedmont region',
54 if (strtolower($type) != 'red') {
55 $data['variety'][] = [
57 // The categoryid for 'white'.
59 'details' => 'French Burgundy region',
62 $data['variety'][] = [
63 'name' => 'Pinot Grigio',
64 // The categoryid for 'white'.
66 'details' => 'From the northeast of Italy',
75 $response = new ResourceResponse($data, 200);
82 public function permissions() {
83 // Remove permissions so the resource is available to all.