diff --git a/config/schema/external_entities.storage_client.schema.yml b/config/schema/external_entities.storage_client.schema.yml index 9d54f64..a297702 100755 --- a/config/schema/external_entities.storage_client.schema.yml +++ b/config/schema/external_entities.storage_client.schema.yml @@ -27,6 +27,9 @@ plugin.plugin_configuration.external_entities_storage_client.rest: page_size_parameter_type: type: string label: 'Page size parameter type' + single_response_in_array: + type: boolean + label: 'Response for single item is wrapped in array' api_key: type: mapping label: 'API key' diff --git a/src/Plugin/ExternalEntities/StorageClient/Rest.php b/src/Plugin/ExternalEntities/StorageClient/Rest.php index 0214ff4..de46f6f 100755 --- a/src/Plugin/ExternalEntities/StorageClient/Rest.php +++ b/src/Plugin/ExternalEntities/StorageClient/Rest.php @@ -163,6 +163,13 @@ class Rest extends ExternalEntityStorageClientBase implements PluginFormInterfac '#default_value' => $this->configuration['pager']['page_size_parameter_type'], ]; + $form['single_response_in_array'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Response for single item is wrapped in array'), + '#description' => $this->t('Response from Drupal Views REST Export is wrapped in an array.'), + '#default_value' => $this->configuration['single_response_in_array'] ?? FALSE, + ]; + $form['api_key']['header_name'] = [ '#type' => 'textfield', '#title' => $this->t('Header name'), @@ -297,10 +304,12 @@ class Rest extends ExternalEntityStorageClientBase implements PluginFormInterfac $body = $response->getBody(); - return $this + $data = $this ->getResponseDecoderFactory() ->getDecoder($this->configuration['response_format']) ->decode($body); + + return !$this->configuration['single_response_in_array'] || !is_array($data) ? $data : reset($data); } /**