I am trying to figure out Drupal 8’s $ variables
array …
So I have a MYTHEME.theme
file, complete with a working MYTHEME_preprocess_field()
method (I know it works because I use it for other fields that need customization).
Right now I’m focusing on the title of an article displayed on the front page of my site. I can access it with the following:
if ($ variables['field_name'] == 'title') { $ title = $ variables['element'][0]['#context']['value']; // ... }
What I want to do is replace all instances of ®
(the registration mark) with <sup>®</sup>
. However, setting this value in the array to something else does not change it on the site.
Is there something I’m missing? A few sources I found said to alter (or add) the ['#markup']
element in the array, but there’s a dearth of information about this online.
How do I change the value of a field? This seems like it should be something basic and easy to do.