Example for a CSHS-enabled term reference field on a custom form?

Created on 18 May 2023, over 2 years ago
Updated 4 July 2024, over 1 year ago

Thank you for providing an example of CSHS in a custom form. To take that further though, is there a way to apply CSHS to a term reference field in a custom form?

πŸ’¬ Support request
Status

Active

Version

4.0

Component

Miscellaneous

Created by

πŸ‡ΊπŸ‡ΈUnited States dmudie Bend, OR USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @dmudie
  • πŸ‡ΊπŸ‡ΈUnited States dmudie Bend, OR USA

    I ended up generating options like this but please comment if there is a better way. Thanks.

    $term_options = [];
    $terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree('vid-name',0,NULL,TRUE);
    foreach ($terms as $term) {
    	$termId = $term->id();
    	if($term->parent->target_id) {
    		$term_options[$termId] = new CshsOption($term->getName(),$term->parent->target_id);
    	} else {
    		$term_options[$termId] = new CshsOption($term->getName());
    	}
    }
    
  • πŸ‡ΊπŸ‡ΈUnited States jeffschuler Boulder, Colorado

    Thanks @dmudie! This was really helpful.

    I still wonder if there's a cleaner way to do this.

Production build 0.71.5 2024