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?
Comments
Comment #2
dimr commentedI have found the same issue, but testing I have seen that on values as the Class and Wrapper on the Title field I didn't find that bug but I found it on Field items and Field item.
Comment #3
swentel commentedComment #4
swentel commentedComment #5
swentel commentedGoing to track and fix this in #2865218: Make field template suggestions and preprocess work