Skip to main content

How do i check if a field is empty in drupal 8?

This is the code for checking if a field is empty

if ($entity->hasField('field_myfield') && !$entity->get('field_myfield')->isEmpty()) { 
// Do something ... 
} 

 

entity