You are here

public function ContextDefinition::toArray in Typed Data API enhancements 8

Exports the definition as an array.

Return value

array An array with values for all definition keys.

Overrides ContextDefinitionInterface::toArray

File

src/Context/ContextDefinition.php, line 49

Class

ContextDefinition
Extends the core context definition class with useful methods.

Namespace

Drupal\typed_data\Context

Code

public function toArray() {
  $values = [];
  $defaults = get_class_vars(__CLASS__);
  foreach (static::$nameMap as $key => $property_name) {

    // Only export values for non-default properties.
    if ($this->{$property_name} !== $defaults[$property_name]) {
      $values[$key] = $this->{$property_name};
    }
  }
  return $values;
}