- Issue created by @duaelfr
- πΊπΈUnited States jrockowitz Brooklyn, NY
Your request makes sense. Let me think about the implications before we make the change.
Below are hooks that could have
$schema_type
and$schema_property
defined. Another approach is to add a $context that would allows$schema_mapping
,$schema_type
, and$schema_property
.hook_schemadotorg_jsonld_schema_type_field_alter(array &$data, \Drupal\Core\Field\FieldItemListInterface $items, \Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata); hook_schemadotorg_jsonld_schema_property_alter(mixed &$value, \Drupal\Core\Field\FieldItemInterface $item, \Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata); hook_schemadotorg_jsonld_schema_properties_alter(array &$values, \Drupal\Core\Field\FieldItemListInterface $items, \Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata);
- πΊπΈUnited States jrockowitz Brooklyn, NY
Passing the \Drupal\Core\Field\FieldItemInterface or \Drupal\Core\Field\FieldItemListInterface to the below hooks feels like the right thing to do, and we MUST pass the BubbleableMetadata, which allows JSON-LD to be cached.
hook_schemadotorg_jsonld_schema_type_field_alter(array &$data, \Drupal\Core\Field\FieldItemListInterface $items, \Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata); hook_schemadotorg_jsonld_schema_property_alter(mixed &$value, \Drupal\Core\Field\FieldItemInterface $item, \Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata); hook_schemadotorg_jsonld_schema_properties_alter(array &$values, \Drupal\Core\Field\FieldItemListInterface $items, \Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata);
A maximum of 2 alterable arguments is supported. In case more arguments need to be passed and alterable, modules provide additional variables assigned by reference in the last $context argument:
@see https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Extension...
I experimented with adding $context, which contains the items, mapping, schema_type, and schema_property, and that started to feel ugly because users have started parsing through the $context. Moving $items to $context also breaks anyone's current implementation of these hooks.
The best compromise I can come up with is to provide a
\Drupal\schemadotorg\Utility\SchemaDotOrgFieldHelper
, which makes it easier to get the mapping, scheme type, and schema property.Please review the attached proposed MR.
- Merge request !221Issue #3500942: hook_schemadotorg_jsonld_schema_type_field_alter should get... β (Open) created by jrockowitz
- πΊπΈUnited States jrockowitz Brooklyn, NY
I think the SchemaDotOrgFieldHelper does improve things.