/** * {@inheritdoc} */ public function getProperties($include_computed = FALSE) { $properties = array(); foreach ($this->definition->getPropertyDefinitions() as $name => $definition) { if ($include_computed || !$definition->isComputed()) { $properties[$name] = $this->get($name); } } return $properties; }
/** * Returns tokens for a complex data definition. * * @param \Drupal\Core\TypedData\ComplexDataDefinitionInterface $complex_data_definition * * @return array * An array of token keys and corresponding labels. */ protected function getTokensFromComplexData(ComplexDataDefinitionInterface $complex_data_definition) { $tokens = []; // Loop over all properties. foreach ($complex_data_definition->getPropertyDefinitions() as $property_name => $property_definition) { // Item definitions do not always have a label. Use the list definition // label if the item does not have one. $property_label = $property_definition->getLabel(); if ($property_definition instanceof ListDataDefinitionInterface) { $property_definition = $property_definition->getItemDefinition(); $property_label = $property_definition->getLabel() ?: $property_label; } // If the property is complex too, recurse to find child properties. if ($property_definition instanceof ComplexDataDefinitionInterface) { $property_tokens = $this->getTokensFromComplexData($property_definition); foreach ($property_tokens as $token => $label) { $tokens[$property_name . ':' . $token] = count($property_tokens) > 1 ? $property_label . ': ' . $label : $property_label; } } // Only expose references as tokens. // @todo Consider to expose primitive and non-reference typed data // definitions too, like strings, integers and dates. The current UI // will not scale to that. if ($property_definition instanceof DataReferenceDefinitionInterface) { $tokens[$property_name] = $property_definition->getLabel(); } } return $tokens; }