0

On my node edit form I've got a field widget that needs some information added to it. Before my alterations, the kint dump of $variables['children'] looks like:

enter image description here

However, after manually setting $variables['children'], the dump looks like:

enter image description here

Before alteration, html renders correctly. However, afterward it is all just rendered as a string with the HTML displaying on the page.

enter image description here

I've tried using the create() method instead that's shown as available under:

enter image description here

...but it doesn't do anything at all.

I've also instead tried changing $variables['element']['display']['#markup'], but that doesn't have any visible effect.

1

You can't modify a markup object, but you can use the create() method on a new markup object to replace the old one.

$variables['children'] = \Drupal\Core\Render\Markup::create('<div>Manually set</div>');

By the way, you are modifying a twig debug message which won't be there in a production environment.

1
  • Ah, \Drupal\Core\Render\Markup::create() is what I was looking for. And thanks for the heads up on the debug element -- ended up finding the proper one in the end.
    – Mrweiner
    Jul 18 '17 at 20:49

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.