You are here

public function VarietyMultiFiles::get in Migrate Plus 8

Same name and namespace in other branches
  1. 8.5 migrate_example_advanced/migrate_example_advanced_setup/src/Plugin/rest/resource/VarietyMultiFiles.php \Drupal\migrate_example_advanced_setup\Plugin\rest\resource\VarietyMultiFiles::get()
  2. 8.2 migrate_example_advanced/migrate_example_advanced_setup/src/Plugin/rest/resource/VarietyMultiFiles.php \Drupal\migrate_example_advanced_setup\Plugin\rest\resource\VarietyMultiFiles::get()
  3. 8.3 migrate_example_advanced/migrate_example_advanced_setup/src/Plugin/rest/resource/VarietyMultiFiles.php \Drupal\migrate_example_advanced_setup\Plugin\rest\resource\VarietyMultiFiles::get()
  4. 8.4 migrate_example_advanced/migrate_example_advanced_setup/src/Plugin/rest/resource/VarietyMultiFiles.php \Drupal\migrate_example_advanced_setup\Plugin\rest\resource\VarietyMultiFiles::get()

Responds to GET requests.

Parameters

string $type: 'red', 'white', or NULL to return all varieties.

Return value

\Drupal\rest\ResourceResponse The response containing the requested variety data.

File

migrate_example_advanced/migrate_example_advanced_setup/src/Plugin/rest/resource/VarietyMultiFiles.php, line 35
Contains \Drupal\migrate_example_advanced_setup\Plugin\rest\resource\VarietyMultiFiles.

Class

VarietyMultiFiles
Provides varieties as two endpoints, one for reds and one for whites.

Namespace

Drupal\migrate_example_advanced_setup\Plugin\rest\resource

Code

public function get($type = NULL) {
  $data = [];
  if (strtolower($type) != 'white') {
    $data['variety'][] = [
      'name' => 'Amarone',
      'parent' => 3,
      // categoryid for 'red'.
      'details' => 'Italian Venoto region',
    ];
    $data['variety'][] = [
      'name' => 'Barbaresco',
      'parent' => 3,
      // categoryid for 'red'.
      'details' => 'Italian Piedmont region',
    ];
  }
  if (strtolower($type) != 'red') {
    $data['variety'][] = [
      'name' => 'Kir',
      'parent' => 1,
      // categoryid for 'white'.
      'details' => 'French Burgundy region',
    ];
    $data['variety'][] = [
      'name' => 'Pinot Grigio',
      'parent' => 1,
      // categoryid for 'white'.
      'details' => 'From the northeast of Italy',
    ];
  }
  $response = new ResourceResponse($data, 200);
  return $response;
}