- Status changed to Closed: duplicate
12 months ago 5:05pm 26 December 2023 - π§πͺBelgium swentel
Going to track and fix this in π Make field template suggestions and preprocess work Active
As soon I add a template_preprocess_field function to mytheme.theme, DS field settings are removed/ignored.
I added two wrappers to my field + enabled link to content:
- Link to the content
- Field items -> Classes : "my-btn-container"
- Field item -> Classes : "btn my-btn"
Output:
<div class="my-btn-container">
<div class="btn my-btn">
<a href="/de/my-page" hreflang="de">mehr lesen</a>
</div>
</div>
Now in mytheme.theme I added the following function
function mytheme_preprocess_field__expert__node__field_teaser_li(&$variables) {
$element = $variables['element'];
$nodeTitle = t('Read more about') . ' ' . $element['#object']->getTitle();
// Iterate through the field items.
foreach($variables['items'] as $key => $item) {
$variables['items'][$key]['content']['#options']['attributes']['title'] = $nodeTitle;
}
}
Afterward, the output contains the link title attribute - but the DS wrappers are gone:
Output:
<div class="field field--name-field-teaser-li field--type-string field--label-hidden field--item">
<a href="/de/my-page" title="Mehr erfahren ΓΌber Testpage" hreflang="de">mehr lesen</a>
</div>
What is going on here? How can I preprocess the link title without breaking DS layout?
Closed: duplicate
3.0
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
Going to track and fix this in π Make field template suggestions and preprocess work Active