0

I tried to get the string messages and create a condition based on the string, but I don't know how to pull the string value.

This is an example of message.

enter image description here

  • Can you provide more details, where you have written this kint(). Just try to access the variable by $args['error']->string->__toString(). – Razeem Ahmad Mar 28 '18 at 5:40
  • @RazeemAhmad string is a protected property. It cannot be accessed outside the class or the class hierarchy. – kiamlaluno Mar 28 '18 at 7:41
  • Thanks @kiamlaluno for pointing that! I wonder how can we access those variables?? – Razeem Ahmad Mar 28 '18 at 7:49
1

You don't need to pull the string, you can use the markup object in a string comparision directly:

$markup = \Drupal\Core\Render\Markup::create('Test');

if ($markup == 'Test') {
  // the markup string is "Test"
}

When you want to use triple equals then you have to type cast the object to a string first:

if ((string) $markup === 'Test') {
  // the markup string is "Test"
}
  • Im sorry but where did you get the 'Test'? Is the mark up is the method to get the the message value? – Oltus West Mar 28 '18 at 8:14
  • $markup is an example, in your case this is $xyz['error'][0] where xyz is the variable name you put in kint(). – 4k4 Mar 28 '18 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.