Drupal 8如何更改段落形式



在drupal8中,我在node中使用段落。它运行良好,但我不得不更改段落形式。我想在其他字段值的基础上隐藏一个字段。

如果有人在之前处理过,请帮忙

我发现下面的代码很有用,并解决了我的问题。我希望它对其他人也有用。

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]
),
);
}
}

最新更新