protected function getTermContextFromField($field_type) {
    // Be aware that drupal field definitions can be complex.
    // e.g text_with_summary has a text, a summary, a number of lines, etc
    // we are only dealing with the resulting ->value() of all this separate
    // pieces and mapping only that as a whole.
    // Default mapping to return in case no $field_type matches
    // field_mappings array keys.
    $default_mapping = [
      "@type" => "xsd:string",
    ];

    // Only load mappings from hooks if we haven't done it
    // yet for this instance.
    if (empty($this->fieldMappings)) {
      // Cribbed from rdf module's rdf_get_namespaces.
      foreach (\Drupal::moduleHandler()->getImplementations(self::FIELD_MAPPPINGS_HOOK) as $module) {
        $function = $module . '_' . self::FIELD_MAPPPINGS_HOOK;
        foreach ($function() as $field => $mapping) {
          if (array_key_exists($field, $this->fieldMappings)) {
            $this->logger->warning(
              t('Tried to map @field_type to @new_type, but @field_type is already mapped to @orig_type.', [
                '@field_type' => $field,
                '@new_type' => $mapping['@type'],
                '@orig_type' => $this->fieldMappings[$field]['@type'],
              ])
            );
          }
          else {
            $this->fieldMappings[$field] = $mapping;
          }
        }
      }
    }
    return array_key_exists($field_type, $this->fieldMappings) ? $this->fieldMappings[$field_type] : $default_mapping;
  }
protected function getTermContextFromField($field_type) {
    // Be aware that drupal field definitions can be complex.
    // e.g text_with_summary has a text, a summary, a number of lines, etc
    // we are only dealing with the resulting ->value() of all this separate
    // pieces and mapping only that as a whole.
    // Default mapping to return in case no $field_type matches
    // field_mappings array keys.
    $default_mapping = [
      "@type" => "xsd:string",
    ];

    // Only load mappings from hooks if we haven't done it
    // yet for this instance.
    if (empty($this->fieldMappings)) {
      // Cribbed from rdf module's rdf_get_namespaces.
      foreach (\Drupal::moduleHandler()->getImplementations(self::FIELD_MAPPPINGS_HOOK) as $module) {
        $function = $module . '_' . self::FIELD_MAPPPINGS_HOOK;
        foreach ($function() as $field => $mapping) {
          if (array_key_exists($field, $this->fieldMappings)) {
            $this->logger->warning(
              t('Tried to map @field_type to @new_type, but @field_type is already mapped to @orig_type.', [
                '@field_type' => $field,
                '@new_type' => $mapping['@type'],
                '@orig_type' => $this->fieldMappings[$field]['@type'],
              ])
            );
          }
          else {
            $this->fieldMappings[$field] = $mapping;
          }
        }
      }
    }
    return array_key_exists($field_type, $this->fieldMappings) ? $this->fieldMappings[$field_type] : $default_mapping;
  }
protected function getTermContextFromField ( $ field_type ) { // Be aware that drupal field definitions can be complex. // e.g text_with_summary has a text, a summary, a number of lines, etc // we are only dealing with the resulting ->value() of all this separate // pieces and mapping only that as a whole. // Default mapping to return in case no $field_type matches // field_mappings array keys. $ default_mapping = [ "@type" => "xsd:string" , ] ; // Only load mappings from hooks if we haven't done it // yet for this instance. if ( empty ( $ this -> fieldMappings ) ) { // Cribbed from rdf module's rdf_get_namespaces. foreach ( \ Drupal :: moduleHandler ( ) -> getImplementations ( self :: FIELD_MAPPPINGS_HOOK ) as $ module ) { $ function = $ module . '_' . self :: FIELD_MAPPPINGS_HOOK ; foreach ( $ function ( ) as $ field => $ mapping ) { if ( array_key_exists ( $ field , $ this -> fieldMappings ) ) { $ this -> logger -> warning ( t ( 'Tried to map @field_type to @new_type, but @field_type is already mapped to @orig_type.' , [ '@field_type' => $ field , '@new_type' => $ mapping [ '@type' ] , '@orig_type' => $ this -> fieldMappings [ $ field ] [ '@type' ] , ] ) ) ; } else { $ this -> fieldMappings [ $ field ] = $ mapping ; } } } } return array_key_exists ( $ field_type , $ this -> fieldMappings ) ? $ this -> fieldMappings [ $ field_type ] : $ default_mapping ; }
Naive approach on Drupal field to JSON-LD type mapping.

TODO: Would be fine to have this definitions in an
configEntity way in the future.

@param string $field_type
As provided by \Drupal\Core\Field\FieldDefinitionInterface::getType().

@return array
A json-ld term definition if there is a match
or array("@type" => "xsd:string") in case of no match.
Naive approach on Drupal field to JSON - LD type mapping .