![](/img/trans.png)
[英]How can I add a paragraph (as default) in the node form by using hook_form_alter in Drupal 8?
[英]Drupal 8 how to alter paragraph form?
在 drupal 8 中,我在節點中使用段落。 它工作正常,但我堅持改變段落形式。 我想根據其他字段值隱藏一個字段。
如果有人以前做過,請幫忙
我發現下面的代碼很有幫助並解決了我的問題。 我希望它對其他人也有用。
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.