0

In D8 I have a form with several fields. One specific field is a number. Input widget is Integer.

This field is prevalued with hook_form_alter like:

$nid     = \Drupal::request()->query->get("source"); // query string param
$node    = \Drupal\node\Entity\Node::load($nid);
$pe_punten = $node->get('field_pe_punten')->value;

I would like to achieve that the user has no access but can see this value. To disable it I can do:

$form['field_pe_punten']['#access'] = FALSE;

But how to replace this input widget with a piece of text which says "10 points"

I red several other QA but could not find out how to do this?

1

use #disabled like below:

$form['field_pe_punten']['#disabled'] = 'disabled';
  • Great never knew this property – Justme Aug 17 '18 at 6:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.