32

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?

67

You can use the method hasField():

$entity->hasField('abc')
| improve this answer | |
  • 6
    Just in case anyone else gets caught out by this, hasField is only available in Drupal 8. – Monkeybrain Sep 19 '16 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.