/**
  * {@inheritdoc}
  */
 public function getDerivativeDefinitions($base_plugin_definition)
 {
     foreach ($this->typedDataManager->getDefinitions() as $data_type_id => $data_type_definition) {
         if (is_subclass_of($data_type_definition['class'], ComplexDataInterface::class, TRUE)) {
             /** @var \Drupal\Core\TypedData\ComplexDataDefinitionInterface $base_definition */
             $base_definition = $this->typedDataManager->createDataDefinition($data_type_id);
             foreach ($base_definition->getPropertyDefinitions() as $property_name => $property_definition) {
                 if ($property_definition instanceof BaseFieldDefinition || $property_definition instanceof FieldConfig) {
                     $this->generateDerivativeDefinition($base_plugin_definition, $data_type_id, $data_type_definition, $base_definition, $property_name, $property_definition);
                 }
             }
         }
     }
     return $this->derivatives;
 }
 /**
  * Returns a typed data object.
  *
  * This helper for quick creation of typed data objects.
  *
  * @param string $data_type
  *   The data type to create an object for.
  * @param mixed[] $value
  *   The value to set.
  *
  * @return \Drupal\Core\TypedData\TypedDataInterface
  *   The created object.
  */
 protected function getTypedData($data_type, $value)
 {
     $definition = $this->typedDataManager->createDataDefinition($data_type);
     $data = $this->typedDataManager->create($definition);
     $data->setValue($value);
     return $data;
 }
 /**
  * Extracts an array of tokens and labels of the required data type.
  *
  * This method can specify a data type to extract from contexts. A classic
  * example of this would be wanting to find all the 'entity_reference'
  * properties on an entity. This method will iterate over all supplied
  * contexts returning an array of tokens of type 'entity_reference' with a
  * corresponding label that denotes their relationship to the provided
  * array of contexts.
  *
  * @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
  *   The array of contexts with which we are currently dealing.
  * @param mixed string|array $data_types
  *   Data types to extract from the array of contexts.
  *
  * @return array
  *   An array of token keys and corresponding labels.
  */
 public function getTokensOfDataType($contexts, $data_types)
 {
     if (!is_array($data_types)) {
         $data_types = [$data_types];
     }
     $tokens = [];
     foreach ($contexts as $context_id => $context) {
         $data_definition = $this->manager->createDataDefinition($context->getContextDefinition()->getDataType());
         /**
          * @var \Drupal\Core\Field\BaseFieldDefinition $property
          */
         if ($data_definition instanceof ComplexDataDefinitionInterface) {
             foreach ($data_definition->getPropertyDefinitions() as $property_name => $property) {
                 if (in_array($property->getType(), $data_types)) {
                     $tokens["{$context_id}:{$property_name}"] = $this->getRelatedPropertyLabel($property, $context, $context_id);
                 }
             }
         }
     }
     return $tokens;
 }