【发布时间】:2020-09-24 07:47:47
【问题描述】:
在 drupal 8 中,我在节点中使用段落。它工作正常,但我被困在改变段落形式。我想在其他字段值的基础上隐藏一个字段。
如果有人以前做过,请帮忙
【问题讨论】:
在 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]
),
);
}
}
【讨论】: