entities – Get field value from paragraph boolean field programmatically: always empty array / null


I tested this with different names for the field but always with the same problem:

  • In my template_preprocess_paragraph I want to get the value for a boolean field, let’s say it’s machine name is field_test_boolean
  • In the preprocess function I get the paragraph entity $paragraph
  • When I try $paragraph->get('field_test_boolean')->getValue() I always get an empty array
  • When I try $paragraph->field_test_boolean->value I always get NULL

I am quite sure that there is no misspelling when trying to get the value from the field. The returned values never change even when I change the field value in the paragraph edit form. I am really confused…