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.
Here's how to have it work with the Term Reference Tree widget. Without this code, a check will be done on form validation, but the options list will contain unavailable terms, which is not user-friendly at all.
I don't submit a patch because I made it quickly for my needs on the stable version.
/**
* Implements hook_field_widget_WIDGET_TYPE_form_alter().
*
* This implements the create grant for term reference tree widgets.
*/
function taxonomy_access_field_widget_term_reference_tree_form_alter(&$element, &$form_state, $context) {
// We need to act later because the options array is not built yet.
$element['#after_build'][] = '_taxonomy_access_field_widget_term_reference_tree_after_build';
$form_state['cardinality'] = $context['field']['cardinality'];
}
function _taxonomy_access_field_widget_term_reference_tree_after_build($element, &$form_state) {
_taxonomy_access_configure_options_widget($element, $form_state['cardinality']);
return $element;
}
Comments
Comment #1
GaëlGThis won't work for some non-required fields.
Comment #2
golds CreditAttribution: golds commentedI simply replaced the widget type when user can't see all taxonomy terms on this field.