Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm trying to add labels to each hierarchical depth and after updating to the dev version, I am trying to use the hook supplied in shs.api.php. The nodes field which has the SHS widget applied is called field_make
Here is my custom custom.info file:
name = Simple Hierarchal Select Custom labels
description = "Custom labels for SHS fields"
core = 7.x
files[] = custom.module
And here is my custom.module file:
<?php
function custom_shs_field_make_js_settings_alter(&$settings_js, $field_name, $vocabulary_identifier) {
foreach ($settings_js['shs'] as $field => &$container) {
foreach ($container as $identifier => &$settings) {
// Define labels for each level.
$settings['labels'] = array(
FALSE, // No label for first level.
t('Country'),
t('City'),
);
// Small speed-up for anmiations (defaults to 400ms).
$settings['display']['animationSpeed'] = 100;
}
}
}
After clearing the cache and checking the HTML to see if the label is hidden, it still isn't there. What am I doing wrong?
Comment | File | Size | Author |
---|---|---|---|
#8 | 2015-11-27 07-57-00.png | 33.07 KB | stBorchert |
Comments
Comment #2
stBorchertHm, I've tested the code right now in a custom module and it works as expected.
Could you debug into your implementation or add a
print_r($settings_js['shs'])
at the first line to see if the function is called?Comment #3
techn0guy CreditAttribution: techn0guy commentedIt says
Comment #4
techn0guy CreditAttribution: techn0guy commentedActually I may have put it in the wrong location, I received that notice when I put
print_r($settings_js['shs']);
above the function. I received no notice when I put it right after the opening { of the function.Comment #5
techn0guy CreditAttribution: techn0guy commentedI just put
drupal_set_message(t('An error occurred and processing did not complete.'), 'error');
as the first line of the function and no message displayed. Does this mean that my field name is incorrect?Comment #6
stBorchertPlease try using hook_shs_js_settings_alter() and print out the
$field_name
variable.I guess your field is named field_field_make ;)
Comment #7
techn0guy CreditAttribution: techn0guy commentedI just realized that it has been working this whole time, however it is only working on the node creation form. The labels are showing in the HTML. However, I was trying to get the labels to show in the exposed filter of the view, the labels are still not showing there. That was my intention, not the node creation form. How do I get them to show in the view?
Comment #8
stBorchertI had to look also how this could be done :)
It's very simple: the name of the field used in the views filter is different from the "real" name. In my case (field_location) the filter field has the name "field_location_tid".
Just print out the field name in
hook_shs_js_settings_alter()
and you will get the correct name.Comment #9
techn0guy CreditAttribution: techn0guy commentedAwesome! How would I print out the field name in
hook_shs_js_settings_alter()
?Comment #10
techn0guy CreditAttribution: techn0guy commentedNever mind I just figured it out, for anyone who is wondering it is
Comment #11
stBorchert