Views entity field raw property is always empty

Created on 23 April 2018, about 6 years ago
Updated 12 June 2024, 13 days ago

Problem/Motivation

The views entity field raw property is always empty, this property is useful when you want the value without twig debug (if it's on) syntax.

Proposed resolution

The raw property is being set in "template_preprocess_views_view_fields", it is being set based on the field_alias property, which isn't available for the "SearchApiEntityField". I propose to set the "field_alias" property on the associated views field handler.

Remaining tasks

  1. Review
  2. Commit

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Needs work

Version

1.0

Component

Views integration

Created by

πŸ‡³πŸ‡±Netherlands bojan_dev

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ͺπŸ‡ΈSpain pcambra Spain, πŸ‡ͺπŸ‡Ί

    I've found the same issue after a few years, showing fields from Search API, I need to check by the raw value and it is empty.

    Here's the workaround I'm using:

    function mytheme_preprocess_views_view_fields(&$variables) {
      $view = $variables['view'];
      if ($view->id() == 'view_id' && $view->current_display == 'display_name') {
        foreach ($view->field as $id => $field) {
          $items = $view->field[$id]->getItems($variables['row']);
          if (!empty($items)) {
            $item = reset($items);
            if (isset($item['raw'])) {
              $variables['fields'][$id]->raw = $item['raw'] ?: NULL;
            }
          }
        }
      }
    }
    

    I've tried the patches here but no dice. I'll be happy to help if there's any direction to pull from :)

Production build 0.69.0 2024