You are here

public function RestWSBaseFormat::getData in RESTful Web Services 7.2

Same name and namespace in other branches
  1. 7 restws.formats.inc \RestWSBaseFormat::getData()

Gets a simple PHP array using URI references for some wrapped data.

This is the counter-part of self::getPropertyValues().

2 calls to RestWSBaseFormat::getData()
RestWSBaseFormat::queryResource in ./restws.formats.inc
Implements RestWSFormatInterface::queryResource().
RestWSBaseFormat::viewResource in ./restws.formats.inc
Gets the representation of a resource.

File

./restws.formats.inc, line 205
RESTful web services module formats.

Class

RestWSBaseFormat
A base for all simple formats that are just serializing/unserializing an array of property values.

Code

public function getData($wrapper) {
  $data = array();
  $filtered = restws_property_access_filter($wrapper);
  foreach ($filtered as $name => $property) {
    try {
      if ($property instanceof EntityDrupalWrapper) {

        // For referenced entities only return the URI.
        if ($id = $property
          ->getIdentifier()) {
          $data[$name] = $this
            ->getResourceReference($property
            ->type(), $id);
        }
      }
      elseif ($property instanceof EntityValueWrapper) {
        $data[$name] = $property
          ->value();
      }
      elseif ($property instanceof EntityListWrapper || $property instanceof EntityStructureWrapper) {
        $data[$name] = $this
          ->getData($property);
      }
    } catch (EntityMetadataWrapperException $e) {

      // A property causes problems - ignore that.
    }
  }
  return $data;
}