They are defined in modules/search/search.api.php function hook_search_admin(), but I can't seem to get either the title or label to appear using this:

  // Note: reversed to reflect that higher number = higher ranking.
  $options = drupal_map_assoc(range(0, 10));
  foreach (module_invoke_all('ranking') as $var => $values) {
    $form['content_ranking']['factors']['node_rank_' . $var] = array(
      '#title' => $values['title'],      '#attributes' => array('title' => t('Weight for !title', array('!title' => $values['title']))),
      '#title_display' => 'invisible',
      '#type' => 'select',
      '#options' => $options,
      '#default_value' => variable_get('node_rank_' . $var, 0),
    );
  }
  return $form;
}

Just flagging this as an issue as it seems to be working differently than most other forms even with regard to weight.

Comments

jhodgdon’s picture

Status: Active » Postponed (maintainer needs more info)

What are you expecting should happen, as opposed to what is happening? All that is being added here is a title attribute on the SELECT. Are you saying that this is not present in the HTML (which would probably be a bug), or that you are not seeing it in your browser (which I would not be surprised about)?

mgifford’s picture

Just occurred to me that $values['title'] could be empty. I didn't test for that. So,

'#title' => $values['title'],
'#title_display' => 'invisible',

This should produce a <label> in the HTML containing the title for the item to allow someone who is using a screen reader to know what the field is producing.

This should provide a title for the &lt>select> tag which would work as well:
'#attributes' => array('title' => t('Weight for !title', array('!title' => $values['title']))),

Anyways, neither of this is producing the desired change to the HTML.

jhodgdon’s picture

This is a select element, and it should be themed with theme_select(). See http://api.drupal.org/api/function/theme_select/7

It looks to me as though that function is putting attributes on. So if you do:

$form['content_ranking']['factors']['node_rank_' . $var] = array(
      '#attributes' => array('title' => 'abcde')
      '#type' => 'select',
      '#options' => $options,
    );

you should get HTML like

<select title="abcde" ...>(options)</select>

If you are looking for a label outside the SELECT, then the title attribute is not what you want. The label is formatted by theme_form_element(), which calls theme_form_element_label() to make the actual label. And those functions use the #title and #title-display attributes on the element to make the label. See http://api.drupal.org/api/function/theme_form_element_label/7

So if your form has

$form['content_ranking']['factors']['node_rank_' . $var] = array(
      '#title' => "xyz", 
      '#title_display' => 'invisible',
      (etc)
     );

you should get HTML:

<label for="name-of-element" class="element-invisible">xyz</label>

Anyway, if this is not doing what you want then either (a) your theme has overridden the theming functions in an incorrect way, or (b) there is a bug in Drupal core or (c) your form code is not what you think it is.

mgifford’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new863 bytes

The patch is attached. But this is a sample of the HTML produced here:

 <tr class="even"><td>Content is promoted to the front page</td><td><div class="form-item form-type-select form-item-node-rank-promote">
 <select name="node_rank_promote" class="form-select" id="edit-node-rank-promote" ><option value="0" selected="selected">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select>

</div>
</td> </tr>

If you want access to the sandbox here, let me know:
http://drupal7.dev.openconcept.ca/admin/config/search/settings

It's just using Seven. Nothing all that customized. I'm not actually using the hook, just trying to patch core.

jhodgdon’s picture

I'm still trying to understand here. With the patch, are you still not getting the labels you expect/want? Do we need to patch Seven as well?

jhodgdon’s picture

Status: Needs review » Needs work
Issue tags: -Accessibility

OK...

So I took a look at this on my D7 test box. I can confirm that without this patch, there are no labels or title attributes on the SELECT elements on the search admin screen, in Seven.

The problem is that node_search_admin() is making a list of these ranking factors, and then theming it with #theme set to 'node_search_admin'.

And theme_node_search_admin() is unsetting the #title on the SELECT elements before it themes them. See http://api.drupal.org/api/function/theme_node_search_admin/7

So that is the real issue. We need to patch theme_node_search_admin() as well as adding the #title-display attribute, if you want to get an invisible label.

mgifford’s picture

Status: Needs work » Needs review
Issue tags: +Accessibility

Yes, the patch is not producing the expected labels.

Unless this is being overridden in Seven (which I can't see why it would be), this form should just be in core and not in any of the core themes.

jhodgdon’s picture

Status: Needs review » Needs work

Looks like we cross-posted here. Sorry about removing that tag too.

jhodgdon’s picture

Status: Needs work » Needs review
StatusFileSize
new666 bytes

This patch, I think, fixes the problem.

mgifford’s picture

Yes, the patch in #9 fixes the problem. I hadn't expected theme_node_search_admin() in node.module.

And ya, seems we were looking at this issue at the same time.

Can we get #9 & #4 marked RTBC so it can get into core. Should this be re-rolled as a single patch?

jhodgdon’s picture

I don't think we need #4. I think #9 alone does the trick. Please verify.

mgifford’s picture

Status: Needs review » Reviewed & tested by the community

You're right. #9 alone is generating the labels!

With that I think this is good to go.

mgifford’s picture

Issue tags: -Accessibility

#9: 884932-9.patch queued for re-testing.

sun’s picture

#9: 884932-9.patch queued for re-testing.

Status: Reviewed & tested by the community » Needs work
Issue tags: +Accessibility

The last submitted patch, 884932-9.patch, failed testing.

sun’s picture

Status: Needs work » Closed (duplicate)