In entity node, I want to check if 'abc' field exists or not. If exists, I will get its value by $value->get('abc').

But the content type where this field doesn't exists, gives error:

The website encountered an unexpected error. Please try again later.

How to check if field exists in an entity?


1 Answer 1


You can use the method hasField():

  • 8
    Just in case anyone else gets caught out by this, hasField is only available in Drupal 8. Sep 19, 2016 at 15:54

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.