Problem/Motivation

When Schema.org Blueprints creates Custom Field sub-field allowed_values, the saved option rows use key and value.

The Custom Field module expects option rows to use key and label. Because of this mismatch, the keys are present on the field settings form but the label inputs are empty.

Observed at:

/admin/structure/types/manage/person/fields/node.person.schema_contact_point

For the Contact Point contact_type sub-field, the option keys are created as mobile, home, and work, but their labels are blank.

Steps to reproduce

  1. Install Schema.org Blueprints with schemadotorg_custom_field.
  2. Create or inspect the Person content type mapping with the Contact Point custom field.
  3. Visit /admin/structure/types/manage/person/fields/node.person.schema_contact_point.
  4. Expand the contact_type sub-field settings.
  5. Inspect the allowed values table.

Proposed resolution

Use Custom Field's expected allowed_values shape:

[
  'key' => 'mobile',
  'label' => 'Mobile',
]

instead of:

[
  'key' => 'mobile',
  'value' => 'Mobile',
]

Also update SchemaDotOrgCustomFieldJsonLdManager::schemaPropertyAlter() to read label when converting selected custom field values to JSON-LD labels.

Remaining tasks

  • Create an issue fork.
  • Open a merge request with the fix.
  • Review test coverage.

User interface changes

Allowed value labels appear in Custom Field sub-field settings instead of blank label inputs.

API changes

None.

Data model changes

None.

Test result

ddev phpunit web/modules/sandbox/schemadotorg/modules/schemadotorg_custom_field/tests/src/Kernel/SchemaDotOrgCustomFieldManagerKernelTest.php web/modules/sandbox/schemadotorg/modules/schemadotorg_custom_field/tests/src/Kernel/SchemaDotOrgCustomFieldJsonLdKernelTest.php web/modules/sandbox/schemadotorg/modules/schemadotorg_custom_field/tests/src/Kernel/SchemaDotOrgCustomFieldRoleJsonLdKernelTest.php

Result:

Tests: 4, Assertions: 101
OK, but there were issues!
Deprecations: 20, PHPUnit Deprecations: 7.
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jrockowitz created an issue. See original summary.

  • jrockowitz committed 2a190eb2 on 1.0.x
    Issue #3593347 by jrockowitz: Fix custom field allowed value labels
    
jrockowitz’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.