Problem/Motivation
Datatype callbacks are used to convert a field value to a specific format for machine processing. For example, the date_iso8601 callback transforms a date to its ISO8601 equivalent.
Currently, there is no way to pass other parameters to this callback. For example, you might want to have a schemaorg_interaction_count
callback which transforms the data (e.g. 78) to the correctly formatted string ("UserComments:78"). But you wouldn't want to have to create a new function for each of the 9 different kinds of interaction specified on schema.org.
Proposed resolution
Add support for passing additional parameters into the callback.
Comment | File | Size | Author |
---|---|---|---|
#7 | 2020001-07-datatype-callback.patch | 14.39 KB | jesse.d |
#7 | interdiff.txt | 990 bytes | jesse.d |
#4 | 2020001-04-datatype-callback.patch | 14.38 KB | linclark |
#4 | interdiff.txt | 12.14 KB | linclark |
#3 | 2020001-03-datatype-callback.patch | 14.03 KB | linclark |
Comments
Comment #1
linclark CreditAttribution: linclark commentedHere is a first pass. It changes the datatype_callback mapping from this:
to this:
Comment #2
scor CreditAttribution: scor commentedI understand the key 'method' is used because we're typically expecting a class method here, but date_iso8601() is a function. Should we use the key 'callable' instead?
Could we have this patch rerolled to not include other patches so it can possibly be committed before the other patches? It looks good otherwise, and both Drupal\rdf\SchemaOrgDataConverter::interactionCount and Drupal\rdf\CommonDataConverter::rawValue are tested.
Comment #3
linclark CreditAttribution: linclark commentedThis patch just rerolls it without the dependency on the other issue. I'll switch to 'callable' in the next patch.
Comment #4
linclark CreditAttribution: linclark commentedOk, this changes method to callable.
Comment #5
scor CreditAttribution: scor commentedCould '$arguments' be used here instead of '$args' in order to be consistent with the naming used in the YAML file and the rest of the patch? (for example below)
Comment #6
linclark CreditAttribution: linclark commentedGood catch. $args came from an earlier commit, which is how the inconsistency slipped in, but we should be consistent.
Comment #7
jesse.d CreditAttribution: jesse.d commentedMakes the requested change to use $arguments instead of $args in SchemaOrgDataConverter.php.
Comment #8
scor CreditAttribution: scor commentedThis looks good with this change.
Comment #9
alexpottCommitted e9ca0d8 and pushed to 8.x. Thanks!
Comment #10
mlncn CreditAttribution: mlncn commentedWriting the change notices.
Comment #11
mlncn CreditAttribution: mlncn commentedAPI change notification
Summary
Configuration example
In Drupal 7 this was defined in hook_rdf_mapping(). In Drupal 8, this goes in the YAML for a content type. For instance, a created at field and a comment count:
Before
After
and
Comment #12
catch#2083415: [META] Write up all outstanding change notices before release.
Comment #13
linclark CreditAttribution: linclark commented@mlncn, thanks for the change notice text. Did this ever get input as a draft change notice?
Comment #13.0
linclark CreditAttribution: linclark commentedclarifies that the interactions are specified on schema.org.
Comment #14
mlncn CreditAttribution: mlncn commentedAdded a change notice: https://drupal.org/node/2159855
First time doing one of those, please review!
Comment #15
star-szrFurther edits can be made if necessary but that looks good to me @mlncn, thanks! Closing out this issue.
Comment #16
star-szrActually marking as fixed this time :)