To support microdata, field formatters need to add the attributes directly. I will upload a patch that works for the current microdata API.


linclark’s picture

new8.05 KB
Damien Tournoud’s picture

Thanks for this! But which version of this module has you used as the basis of this patch? We don't have any template anymore in the module since the big refactoring that happened back in June.

linclark’s picture

oh whoops.... I hadn't updated my code since early June.

I'll have to do a git pull and get it working again. Thanks!

scor’s picture

is there any way we can make the default mappings more generic so that they can not only be used for microdata for also for RDFa and RDF in general?

linclark’s picture

That's not so much an issue with AddressField as it is with microdata's hooks. I'd suggest posting it on the MD queue.

scor’s picture

I'm not sure I expressed myself properly. the actual default mappings are good and make sense for the addressfield module. What I was talking about is the hook in which they are defined. what I'd rather see is something like hook_rdf_field_defaults() where these mappings are defined, so that any module interested in these mappings such as microdata and RDFx (RDF UI) can leverage these. but in any case I'll bring up this in the MD queue which is more appropriate to discuss this. thanks for working on this Lin!

linclark’s picture

Title:microdata support» Support microdata in addressfield
Status:Active» Needs review
new10.26 KB

This patch:

  • Enables microdata for the field in hook_field_info and for the properties in the property callback. This results in a microdata configuration form being attached to the field instance settings form.
  • Takes the resultant microdata attributes array that is attached to the entity and in addressfield_field_formatter_view passes it to the format plugins using the context variable.
  • In the format plugins, uses a new helper function (_addressfield_get_attributes) to process the class attributes and microdata attributes into a single attributes array for each property.
    Note: in the original name_oneline formatter, the class name-block was used instead of name-oneline, which makes it the only class that doesn't match the property name. I'm not sure if that was intentional or not. This patch changes it to name-oneline.
  • It also defines a default mapping for that users can choose to use on the field instance settings page.

In order to test this:

  • Enable microdata module
  • Add an address field
  • On the field instance settings form, click the radio button for at the bottom of the page and "Use default mapping"
  • Save the field
  • Add a node with an address
  • Copy the source code to and click on the JSON tab. You should see a JSON object that has the properties from your content.

The way I insert the microdata into context and then use it in the format plugins might not be the best. Also, open to suggestions for the microdata API if you have any thoughts on how to make it easier for field formatter developers.

linclark’s picture

new10.55 KB

I updated the patch due to #1278200: Add hook_microdata_value_type_alter.

This patch does everything in #8. It also:

  • Sets the microdata type for the 'addressfield' property type to 'item' by implementing hook_microdata_value_type_alter().
klonos’s picture

Using latest dev versions of core, Address Field, Microdata and required modules, when I edit a "Postal address" field (provided by Address Field) I get this error:

Notice: Undefined index: #value_type in microdata_get_instance_mapping_form() (line 174 of /var/www/my-site/sites/all/modules/microdata/

I have applied the patch in #8

rbayliss’s picture

new10.85 KB

It looks like hook_microdata_value_type_alter has been renamed to hook_microdata_value_types_alter(). Also, the previous patch doesn't alter the administrative area field. Note that this patch changes the class of this field from state to administrative-area.

linclark’s picture

new10.86 KB

This brings the patch up to date, and I will likely be moving into RC soon.

Any thoughts from the maintainers on how likely a commit is?

gittosj’s picture

Tested and works perfectly - thank you and great work!

pinkonomy’s picture

Does this patch also support ?

randallknutson’s picture

new10.89 KB

Updating so it will apply to latest 1.0-beta4

dr.user’s picture

Patch #14 works for me.

johnv’s picture

Issue summary:View changes
Related issues:+#797912: Rich Snippets integration

It seems this pach is now outdated, since the last months some patches/modules have been published:
Schema_org module supports Addressfield
#797912: Rich Snippets integration

bojanz’s picture

Given #16, is the patch in this issue still relevant?

Mac_Weber’s picture

Status:Needs review» Closed (won't fix)

@bojanz I think you maintainers could recommend the Schema_org module at the AddressField main page and close both this issue and also:
#797912: Rich Snippets integration