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

Comments

StatusFileSize
new8.05 KB

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.

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!

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?

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.

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!

Title:microdata supportSupport microdata in addressfield
Status:Active» Needs review
StatusFileSize
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 schema.org 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 schema.org at the bottom of the page and "Use default mapping"
  • Save the field
  • Add a node with an address
  • Copy the source code to http://foolip.org/microdatajs/live/ 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.

StatusFileSize
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().

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/microdata.admin.inc).

I have applied the patch in #8

StatusFileSize
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.

StatusFileSize
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?

Tested and works perfectly - thank you and great work!

Does this patch also support schema.org ?

StatusFileSize
new10.89 KB

Updating so it will apply to latest 1.0-beta4

Patch #14 works for me.

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