Allow custom fields (not mapped to Schema.org) to be added to a mapping

Created on 10 July 2023, over 1 year ago

Problem/Motivation

Occasionally, Schema.org may not include a needed property or field. When a Schema.org type is created, custom fields could be included.

Steps to reproduce

Proposed resolution

Allow custom fields (not mapped to Schema.org) to be added to a mapping

Below are modules that create custom or additional fields when a Schema.org mapping is created.

  • schemadotorg_editorial
  • schemadotorg_metatag
  • schemadotorg_subtype
  • schemadotorg_taxonomy

Here is an example of a hook that could add a custom field.

/**
 * Implements hook_schemadotorg_mapping_defaults_alter().
 */
function MODULE_schemadotorg_mapping_defaults_alter(array &$defaults, string $entity_type_id, ?string $bundle, string $schema_type): void {
  if ($entity_type_id === 'node') {
    $defaults['properties']['field_custom'] = [
      'name' => 'field_custom',
      'type' => 'string',
      'label' => 'Custom',
    ];
  }
}

Notes

Custom fields are being stored via the mapping.
Custom fields are not displayed via the mapping UI unless a module creates a UI. (i.e. subtype and layout)

Remaining tasks

  • Rework mapping defaults to support custom fields
  • Update the starterkit summary to support custom fields
  • Update the UI to support custom fields
  • Write tests

User interface changes

Custom fields will be displayed.

API changes

Custom fields will be supported.

Data model changes

Custom field can be included in starterkit's mapping defaults.

✨ Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024