diff --git a/docroot/modules/custom/mass_hierarchy/src/Form/HierarchyChildrenForm.php b/docroot/modules/custom/mass_hierarchy/src/Form/HierarchyChildrenForm.php index f03fb89fd0..0105e6d227 100644 --- a/docroot/modules/custom/mass_hierarchy/src/Form/HierarchyChildrenForm.php +++ b/docroot/modules/custom/mass_hierarchy/src/Form/HierarchyChildrenForm.php @@ -2,10 +2,14 @@ namespace Drupal\mass_hierarchy\Form; +use Drupal\Core\Ajax\AjaxResponse; +use Drupal\Core\Ajax\RedirectCommand; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Routing\TrustedRedirectResponse; use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\Core\Url; use Drupal\entity_hierarchy\Form\HierarchyChildrenForm as EntityHierachyHierarchyChildrenForm; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -22,6 +26,27 @@ public function form(array $form, FormStateInterface $form_state) { $form['#attached']['library'][] = 'entity_hierarchy/entity_hierarchy.nodetypeform'; + // Retrieve the current query string parameter value, defaulting to FALSE. + $current_hide = \Drupal::request()->query->get('hide-types', FALSE); + + // Add the "Hide specific types" checkbox with AJAX functionality. + $form['hide_specific_types'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Hide people, contacts, events, news'), + '#description' => $this->t('Check this box to hide specific types from the hierarchy view.'), + '#default_value' => $current_hide, + '#ajax' => [ + 'callback' => '::redirectWithQuery', + 'wrapper' => 'hierarchy-children-form-wrapper', + 'effect' => 'fade', + ], + ]; + + // Add a wrapper to the entire form to enable AJAX updates. + $form['#prefix'] = '