简体   繁体   中英

Drupal 8 how to alter paragraph form?

In drupal 8, I'm using paragraph in node. It's working fine but I got stuck to alter paragraph form. I want to hide one field on base of other field value.

Please help if somebody worked it on before

I found below code helpful and fixed my problem. I hope it will be useful for others also.

 function hook_inline_entity_form_entity_form_alter(&$entity_form, &$form_state) { // $entity_form['#bundle'] paragraph machine name if($entity_form['#entity_type'] == 'paragraph' && $entity_form['#bundle'] == 'location'){ $parents = $entity_form['#parents']; $identifier = $parents[0].'['.implode('][', array_slice($parents, 1)).']'; $entity_form['field_dropoff_time']['#states'] = array( 'visible' => array( 'select[name="'. $identifier .'[field_camp_location_type]"]' => ['value' => 1] ), ); $entity_form['field_pickup_time']['#states'] = array( 'visible' => array( 'select[name="'. $identifier .'[field_camp_location_type]"]' => ['value' => 1] ), ); } }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM