Skip to main content
1 of 4
clestcruz
  • 249
  • 1
  • 8
  • 22

How to check the value of a field if its empty within preprocess

Is there a way to check if the value of a field within the preprocess is empty? I'm getting an Error: Call to a member function isEmpty() error during the process

function iom_preprocess_block__twitterfeed(&$variables) {

    // Get the twitter_username field from node
    $twitterUsername = \Drupal::routeMatch()
                        ->getParameter('node')
                        ->get('field_twitter_username')
                        ->value; 

     if ($twitterUsername->isEmpty()) {
         dump("Empty");
     }

     else {
         dump("Not Empty");
     }

}
clestcruz
  • 249
  • 1
  • 8
  • 22