Skip to main content
improved formatting
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

How todo I check the value of a field if its empty within preprocess?

Is there a way to check, in a preprocess function, 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 processfollowing error.

Call to a member function isEmpty()

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");
     }
 
}

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");
     }
 
}

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(&$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");
  }
}
Rollback to Revision 1 - Edit approval overridden by post owner or moderator
Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284
Source Link
clestcruz
  • 249
  • 1
  • 8
  • 22
Loading