Drupal 禁用段落表单中的字段

Drupal 禁用段落表单中的字段,drupal,drupal-8,paragraphs,Drupal,Drupal 8,Paragraphs,有人知道如何在Drupal8中更改段落(ajax)后端表单中的字段吗?我想禁用一个字段,但要使其可见 谢谢您可以使用hook\u form\u alter()或hook\u form\u ID\u alter()禁用表单字段 我总是建议您使用hook\u form\u form\u ID\u alter()。假设test是您的模块名,user\u register\u form是表单的Id test_form_user_register_form_alter(&$form, &$

有人知道如何在Drupal8中更改段落(ajax)后端表单中的字段吗?我想禁用一个字段,但要使其可见


谢谢

您可以使用hook\u form\u alter()或hook\u form\u ID\u alter()禁用表单字段

我总是建议您使用hook\u form\u form\u ID\u alter()。假设test是您的模块名,user\u register\u form是表单的Id

test_form_user_register_form_alter(&$form, &$form_state, $form_id) {
  $form['fieldname'] = array(
    '#type' => 'textfield',
    '#title' => t('Text label'),
    '#attributes' => array('disabled' => 'disabled'),
  );
}
快乐编码

function hook__form_FORM_ID_alter(&$form,\Drupal\Core\Form\FormStateInterface 
$form_state, $form_id) {
//output your form structure to know what to target in the form array($form[])
#kint( $form['title']);
$form['title']['#disabled'] = TRUE;

}

上面的代码禁用了要修改的“表单ID”中的标题字段(Drupal 8.5)。

有一个补丁添加了段落子表单钩子更改,以使针对特定段落类型中的特定字段变得更容易。退房