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

vistree created an issue. See original summary.

dimr’s picture

I 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.

swentel’s picture

Version: 8.x-3.9 » 5.0.x-dev
swentel’s picture

Version: 5.0.x-dev » 8.x-3.x-dev
swentel’s picture

Status: Active » Closed (duplicate)