This is a spin-off of and, IMO, a dependency for #493030: RDF #1: core RDF module.

Within the RDF patch (http://drupal.org/node/493030#comment-2162760), there's this line of code in the rdf_preprocess_node() function:

$variables['date'] = '<span' . drupal_attributes($date_attributes_array) .  '>' . $variables['date'] . '</span>';

This will make themers very, very unhappy. They will ask, "where did this mysterious span come from and how do I get rid of it? or at least put a class on it?".

For more background, see #569362: Document $attributes, $title_attributes, and $content_attributes template variables. In that issue, we solved most of the RDF use-cases by having standardized $attributes and $title_attributes variables in all template files. A couple instances where RDF still needs attributes ON A THEMER ACCESSIBLE ELEMENT not covered by this are the 'date' example mentioned above, and also for the username (to convery authorship of a node/comment), which the RDF patch currently implements in an ugly RDF workaround, but which could be solved nicely if it were possible to wrap the $name / $author variables in another span, as is done with $date, but again, in a themer-acceptable way.

My proposal coming in a follow-up comment.

Comments

effulgentsia’s picture

Status: Active » Needs review
StatusFileSize
new4.2 KB

I hope the code here is clear. If not, I did a poor job commenting, so please point out what could be better, either in architecture, implementation, or documentation.

This patch would allow the code at the top of this issue to be replaced with:

$variables['variable_attributes_array']['date'] = $date_attributes_array;

Same thing could also be done for 'name', removing the workaround that's in there now.

The point of this patch is that the 'span' tag outputted would then be under themer control.

effulgentsia’s picture

This one has better documentation. Also, I simplified template_process(). In #1, I was having it flatten $variable_attributes_array similarly to how $title_attributes_array is flattened, to support situations where a themer wants to wrap the variable directly in the template file. However, on further thinking, I decided that a themer who wants to do that will still need to override theme_template_variable_wrapper() anyway (so it doesn't get double-wrapped), and any themer who is able to override a theme function should also be able to figure out how to call drupal_attributes().

effulgentsia’s picture

One more comment for anyone wondering (as I first did when looking at this problem): isn't this what #theme_wrappers was built for, and why aren't we using it? The answer is "yes", and "because it only works when things get built as renderable elements, and we still have places in core that don't do that, including everywhere that this is still an issue for in RDF". I'm 100% in favor of making everything use renderable elements in D8, but we just weren't able to pull that off in D7.

moshe weitzman’s picture

I suppose we can live with this for a release but I feel like the theme system is starting to creak under its layers of abstraction. Does theme_template_variable_wrapper() really describe anything? I doubt we can find better words for this. If something is indescribable by modern language, maybe we shouldn't be doing it. Just an unhelpful thought. Carry on.

effulgentsia’s picture

At sun's suggestion, here's specifically the change that this would allow in the RDF patch.

Current RDF patch:

function rdf_preprocess_node(&$variables) {
  ...
  // Add RDFa markup for the date.
  if (!empty($variables['rdf_mapping']['created'])) {
    $date_attributes_array = drupal_rdfa_attributes($variables['rdf_mapping']['created'], $variables['created']);
    // @todo how to avoid hard-coding this span?
    $variables['date'] = '<span' . drupal_attributes($date_attributes_array) .  '>' . $variables['date'] . '</span>';
  }
}

function rdf_preprocess_comment(&$variables) {
  ...
  if (!empty($comment->rdf_mapping['created'])) {
    $date_attributes_array = drupal_rdfa_attributes($comment->rdf_mapping['created'], $comment->created);
    // @todo how to avoid hard-coding this span?
    $variables['created'] = '<span' . drupal_attributes($date_attributes_array) .  '>' . $variables['created'] . '</span>';
  }
}

function rdf_preprocess_username(&$variables) {
  ...
  // This first thing we are describing is the relation between the user and
  // the parent resource (e.g. a node). Because the set of predicate link
  // the parent to the user, we must use the 'rev' RDFa attribute to specify
  // that the relationship is reverse.
  $variables['attributes_array']['rev'] = $account->rdf_mapping['uid']['property'];
  // We indicate the parent identifier in the 'resource' attribute,
  // typically this is the entity URI. This is the object in RDF.
  // @todo find a better way to get the link to the parent entity. If there
  // a helper function for that?
  $parent_uri = '';
  if (!empty($account->path['source'])) {
    $parent_uri = url($account->path['source']);
  }
  elseif (!empty($account->cid)) {
    $parent_uri = url('comment/' . $account->cid, array('fragment' => 'comment-' . $account->cid));
  }
  $variables['attributes_array']['resource'] = $parent_uri;
  // The second information we annotate is the name of the user with the
  // 'property' attribute. We do not need to specify the RDF object here
  // because it's the value inside the a tag which will be used
  // automatically according to the RDFa parsing rules.
  $variables['attributes_array']['property'] = $account->rdf_mapping['name']['property'];
}

With this patch, this could become:

function rdf_preprocess_node(&$variables) {
  ...
  // Add RDFa markup for the date.
  if (!empty($variables['rdf_mapping']['created'])) {
    $date_attributes_array = drupal_rdfa_attributes($variables['rdf_mapping']['created'], $variables['created']);
    $variables['variable_attributes_array']['date'] = $date_attributes_array;
  }
  // Add RDFa markup for name (e.g., author)
  $variables['variable_attributes_array']['name'] = SOME_RELATIVELY_SIMPLE_ATTRIBUTES;
}

function rdf_preprocess_comment(&$variables) {
  ...
  if (!empty($comment->rdf_mapping['created'])) {
    $date_attributes_array = drupal_rdfa_attributes($comment->rdf_mapping['created'], $comment->created);
    $variables['variable_attributes_array']['created'] = $date_attributes_array;
  }
  // Add RDFa markup for author
  $variables['variable_attributes_array']['author'] = SOME_RELATIVELY_SIMPLE_ATTRIBUTES;
}

function rdf_preprocess_username(&$variables) {
  ...
  NONE OF THE STUFF IN THE ABOVE EXAMPLE  
}
sun’s picture

I share moshe's concerns, but at the same time (as he seems to do equally) I think there's no better option to introduce conditional wrappers for RDF-support in D7 currently.

I asked effulgentsia to include an example implementation or at least some docs that show-case the intended usage, to make any sense of this patch.

effulgentsia’s picture

If we don't want to add a new theme hook in common.inc and muck with template_process(), I suggested a way to do the same thing localized to the rdf module: http://drupal.org/node/493030#comment-2163754.

moshe weitzman’s picture

Status: Needs review » Closed (duplicate)

Nice idea to localize this cruft to rdf module. Marking this a dupe. See #493030: RDF #1: core RDF module