在Drupal8中,我在node中使用了段落。它工作得很好,但是我不得不改变段落的形式。我想隐藏一个字段的基础上的其他字段的值。
如果有人以前用过它,请帮助我
发布于 2020-09-25 17:22:22
我发现下面的代码很有帮助,并解决了我的问题。我希望它也能对其他人有用。
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]
),
);
}
}
https://stackoverflow.com/questions/64041782
复制相似问题