How do I check the value of a field if its empty? Is there a way to check, in a preprocess function, if the value of a field is empty?

I'm getting the following error.


  Call to a member function isEmpty()


function iom_preprocess_block__twitterfeed(&amp;$variables) {
  // Get the twitter_username field from node.
  $twitterUsername = \Drupal::routeMatch()
    -&gt;getParameter('node')
    -&gt;get('field_twitter_username')
    -&gt;value; 

  if ($twitterUsername-&gt;isEmpty()) {
    dump("Empty");
  }
  else {
    dump("Not Empty");
  }
}
@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-&gt;hasField('field_your_field') &amp;&amp; !$node-&gt;get('field_your_field')-&gt;isEmpty() ) {
 //... do something
}