需求:
将自定义字段remote uuid放到右侧UUID下方,如图:
remote uuid是自定义字段,添加后默认在编辑页面的左列展示;现在要将其放到右列显示。一开始尝试通过weight来调整,发现怎么调都不对;于是通过调试找到对应的twig,如图:
发现右侧内容都是在form的advanced中,再去对比现有的右侧字段,发现都有一个group的属性,调试了下:
function myMODULE_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$form_arr = ['node_xxx_form', 'node_xxx_edit_form'];
if (in_array($form_id, $form_arr) && isset($form['remote_uuid'])) {
$form['remote_uuid']['#group'] = 'advanced';
$form['remote_uuid']['#weight'] = -20;
$form['remote_uuid']['#attributes']['class'] = ['entity-meta__header'];
}
}
效果图如下,成功将字段放到了右侧,但是我想通过weight调整上下位置的时候,一直无效,应该不是 '#weight’这里修改。
将UUID的属性打印出来,发现content的状态,作者,发布时间都在UUID下面,干脆将remote uuid也放进去:
function myMODULE_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$form_arr = ['node_xxx_form', 'node_xxx_edit_form'];
if (in_array($form_id, $form_arr) && isset($form['remote_uuid'])) {
$form['remote_uuid']['#weight'] = -10;
$form['meta']['remote_uuid'] = $form['remote_uuid'];
unset($form['remote_uuid']);
}
}
效果如下,总算达到了我的要求;再来添加,编辑测试下是否影响保存,结果完全没问题。