diff --git a/config/schema/select2boxes.schema.yml b/config/schema/select2boxes.schema.yml index f87189f..bed73a7 100644 --- a/config/schema/select2boxes.schema.yml +++ b/config/schema/select2boxes.schema.yml @@ -40,3 +40,6 @@ field.widget.third_party.select2boxes: enable_select2: type: boolean label: 'Enable Select2 widget for dropdowns' + use_taxonomy_term_parent_as_output_group: + type: boolean + label: 'Use the parent item as output group' diff --git a/select2boxes.module b/select2boxes.module index 8241e46..f66f0eb 100644 --- a/select2boxes.module +++ b/select2boxes.module @@ -95,15 +95,25 @@ function select2boxes_field_widget_third_party_settings_form(WidgetInterface $pl ], ], ]; + $element['use_taxonomy_term_parent_as_output_group'] = [ + '#type' => 'checkbox', + '#title' => t('Use the parent item as output group'), + '#description' => t('If selected the parent items will not be selectable. If the hierarchy contanis multiple levels it is the higest level directly descending from the root that will be used.'), + '#default_value' => isset($settings['use_taxonomy_term_parent_as_output_group']) && $settings['use_taxonomy_term_parent_as_output_group'] == '1', + ]; + return $element; + } + elseif ($plugin->getPluginId() == 'select2boxes_autocomplete_single') { + $element['use_taxonomy_term_parent_as_output_group'] = [ + '#type' => 'checkbox', + '#title' => t('Use the parent item as output group'), + '#description' => t('If selected the parent items will not be selectable. If the hierarchy contanis multiple levels it is the higest level directly descending from the root that will be used.'), + '#default_value' => isset($settings['use_taxonomy_term_parent_as_output_group']) && $settings['use_taxonomy_term_parent_as_output_group'] == '1', + ]; return $element; } // Add the options, specific for the single entity reference and list widgets. - elseif ($plugin->getPluginId() == 'select2boxes_autocomplete_list' || $plugin->getPluginId() == 'select2boxes_autocomplete_single') { - // Ignore fields with auto-creation option enabled. - if (isset($field_definition->getSetting('handler_settings')['auto_create'])) { - return []; - } - + elseif ($plugin->getPluginId() == 'select2boxes_autocomplete_list') { // Add an option to allow users to include the flag icons. $types = ['language_field', 'language', 'country']; if (in_array($field_definition->getType(), $types)