Problem/Motivation

Some advanced markup techniques—like that provided by schema.org—require field wrappers to have custom attributes, rather than just classes. This is becoming an increasingly important SEO issue as search engines give preference to sites providing this data. However, there is currently no simple way to add these attributes to fields without creating numerous custom templates or field formatters.

Proposed resolution

When using the Expert field template in Display Suite, allow each element to include an arbitrary number of custom attributes.

User interface changes

The simplest and most flexible way to accomplish this would be to provide an "Attributes" text field for each element, just like is done now for classes. Site builders could then type in whatever they want and the whole thing could be inserted into the element tag.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jstoller’s picture

Title: Allow custom attributes on field wrappers » Allow custom attributes on DS field wrappers
Issue tags: +microformats

Just a thought, but given the semantics for attributes are somewhat more involved than for classes, it might be nice to have some basic validation on the field. I wouldn't validate the attributes themselves, since this should be about increasing flexibility, but we should probably make sure every opening quote has a corresponding closing quote. Basically, it would be nice if we prevented someone from taking down their entire site with one malformed attribute.

mrfelton’s picture

We have a need for this too, in order to be able to add named anchors to specific elements.

swentel’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev

Moving to 7.x-2.x branch, I'll add that this weekend.

swentel’s picture

marked #1471642: Add node $title_attributes in $content_attributes field title as a duplicate. Still in doubt how to handle this:

- a) add a checkbox to print out attributes in general (so the generated ones)
- b) add a textfield to add custom attributes
- c) have both options

swentel’s picture

Also, can we fix it for the title or not (see the duplicate issue)

mrfelton’s picture

Assigned: Unassigned » mrfelton
mrfelton’s picture

Here is the first part, which does the attributes. Still need to add a checkbox for the default attributes and include them in the output if checked.

mrfelton’s picture

Status: Active » Needs review
FileSize
19.98 KB

Updated patch, adds the additional options, and rearranges the form into fieldsets and adds state api implementation to make it 'slightly' more manageable. The UI feels very heavy though when all the options are enabled.

Also, the implementation of the default attributes needs checking, as I'm not 100% clear which element these are supposed to be applied to.

mrfelton’s picture

Oops, the hide colon option was broken. Updated patch fixes that.

swentel’s picture

Status: Needs review » Needs work

Looks that this is missing default classes checkbox, no ? Also I don't see the label element and classes don't appear in the UI either.
(note, the latest commit moved a lot of code around in folders)

swentel’s picture

Title: Allow custom attributes on DS field wrappers » Allow custom attributes, default classes, prefixes and suffixes on Expert field template

Marked #1529730: add prefix and suffix to expert field template to here

Let's do it all together!

loominade’s picture

Title: Allow custom attributes, default classes, prefixes and suffixes on Expert field template » Allow custom attributes on DS field wrappers + affixes

#1529730: add prefix and suffix to expert field template assumes also to add prefix and suffix + their wrappers in this issue

edit:
oh, sorry

swentel’s picture

Committed a first part for adding attributes + tests for it. Note it's not using the fieldset layout for now. Still needs the checkboxes for default classes and attributes and the even/one class on the field item wrapper

Pre- and suffixes will be held out for now.

swentel’s picture

Assigned: mrfelton » jyve
Status: Needs work » Fixed

This has all been committed, reassigning to jyve so he remembers to look a bit at the CSS because expert just exploded :)

mrfelton’s picture

Awesome.

p.s.

Pass the following option to git commit to attribute authorship to this user:

--author="mrfelton <mrfelton@305669.no-reply.drupal.org>"

Learn more about proper Git attribution.

;)

Status: Fixed » Closed (fixed)

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

rodrigoaguilera’s picture

So theres is no way to add affixes to a field?
maybe you can point me to another module