简体   繁体   English

Drupal 8 如何改变段落形式?

[英]Drupal 8 how to alter paragraph form?

In drupal 8, I'm using paragraph in node.在 drupal 8 中,我在节点中使用段落。 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] ), ); } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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