Skip to main content
3 of 4
Rollback to Revision 1 - Edit approval overridden by post owner or moderator
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

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