You are here

public function WSDecoderBase::addData in Web Service Data 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/WSDecoderBase.php \Drupal\wsdata\Plugin\WSDecoderBase::addData()

Add data to an empty object or replace all existing data.

In some cases, it may require multiple web service requests to load language specific content. You can add each request data result to the same processor object. getData() should then return the merged data keyed by language.

If your webservice returns all data for all languages in a single request, leave $lang to NULL (not LANGUAGE_NONE). LANGUAGE_NONE is considered a valid language and triggers the language keying.

Parameters

mixed $data: A set of data to decode.

string $lang: Optional - Language key for the data being added.

mixed $context: Optional - A list of all the other settings and details for the call.

Overrides WSDecoderInterface::addData

1 call to WSDecoderBase::addData()
WSDecoderBase::__construct in src/Plugin/WSDecoderBase.php
Constructs a \Drupal\Component\Plugin\PluginBase object.

File

src/Plugin/WSDecoderBase.php, line 195

Class

WSDecoderBase
Base class for Wsdecoder plugin plugins.

Namespace

Drupal\wsdata\Plugin

Code

public function addData($data, $lang = NULL, $context = []) {
  $this->context = $context;
  if (!is_null($lang) and !empty($data)) {
    $this->languages[$lang] = $lang;
    $this->data[$lang] = $this
      ->decode($data);
  }
  else {

    // Default action, just decode the data.
    $this->data = $this
      ->decode($data);
  }
}