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
Comment #1
jhodgdonWhat 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)?
Comment #2
mgiffordJust 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 <>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.
Comment #3
jhodgdonThis 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:
you should get HTML like
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
you should get HTML:
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.
Comment #4
mgiffordThe patch is attached. But this is a sample of the HTML produced here:
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.
Comment #5
jhodgdonI'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?
Comment #6
jhodgdonOK...
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.
Comment #7
mgiffordYes, 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.
Comment #8
jhodgdonLooks like we cross-posted here. Sorry about removing that tag too.
Comment #9
jhodgdonThis patch, I think, fixes the problem.
Comment #10
mgiffordYes, 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?
Comment #11
jhodgdonI don't think we need #4. I think #9 alone does the trick. Please verify.
Comment #12
mgiffordYou're right. #9 alone is generating the labels!
With that I think this is good to go.
Comment #13
mgifford#9: 884932-9.patch queued for re-testing.
Comment #14
sun#9: 884932-9.patch queued for re-testing.
Comment #16
sunPlease merge this patch into #882694: Add missing form element titles for accessibility. Thanks.