Skip to content

Commit

Permalink
[SD-687] set maximum depth of site taxonomy
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-gao committed Feb 27, 2025
1 parent d5510d1 commit 20f4f52
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions modules/tide_site/tide_site.module
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ function tide_site_field_widget_single_element_form_alter(&$element, FormStateIn
}

// Restrict options to 2 levels of depth for Site field.
$max_depth = max(2, (int) getenv('MAX_SITE_TAXONOMY_DEPTH') ?: 2);
if (TideSiteFields::isSiteField($field_definition->getName(), TideSiteFields::FIELD_SITE)) {
$tree = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree('sites', 0, 2);
$tree = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree('sites', 0, $max_depth);
if (isset($element['#options'])) {
$element['#options'] = array_intersect_key($element['#options'], array_flip(array_column($tree, 'tid')));
}
Expand Down Expand Up @@ -177,8 +178,7 @@ function tide_site_form_taxonomy_overview_terms_alter(&$form, FormStateInterface
* @todo Extract into a service.
*/
function _tide_site_form_taxonomy_overview_terms_validate(&$form, FormStateInterface $form_state) {
$max_depth = 1;

$max_depth = max(1, ((int) getenv('MAX_SITE_TAXONOMY_DEPTH') ?: 1) - 1);
$vocabulary = $form_state->get(['taxonomy', 'vocabulary']);
if ($vocabulary->id() === 'sites') {
$invalid_tids = [];
Expand Down

0 comments on commit 20f4f52

Please sign in to comment.