Skip to main content

@vinhd proposition is correct, by the way you can also use the isEmpty() method from the field list interface. It can be more adapted for complex field types.

if ( $node->hasField('field_your_field') && !$node->get('field_your_field')->isEmpty() ) {
 //... do something
}