Problem/Motivation

I'm having issues with displaying render entity (or any other) formatter for entity reference field (taxonomy term) in custom elements page view (Show Fields).

So no matter which formatter I set, the field is always shown as target_id when checking the view.

Comments

useernamee created an issue. See original summary.

fago’s picture

I dont't think we support individual views-field-formatting, you may just take over the whole entity-row rendering to go via custom-elements entity-rendering, and from there on you can use CE-UI to format individual fields.

>So no matter which formatter I set, the field is always shown as target_id when checking the view.
I see, I guess expected behaviour would be at least to get the traditional-rendered drupal markup, right?

fago’s picture

Title: Custom elements views field overrides and formatter are not working » Custom elements Views: Per-field formatters are not supported/working
useernamee’s picture

This issue is related to #3395592: Support entity-reference fields in field-style views rows but it is not fixed by it.

useernamee’s picture

In lupus_decoupled/modules/lupus_decoupled_views/src/Plugin/views/style/CustomElements.php entity references are not rendered as custom elements (see else part). This also introduces errors for multivalue entity references because the sanatization is expects string but recieves array.

  /**
   * {@inheritdoc}
   */
  public function render() {
    $result = ['rows' => []];
    $row_plugin = $this->view->rowPlugin->getPluginId();
    $entity_view_plugin = str_starts_with($row_plugin, 'entity:');

    // If the Data Entity row plugin is used, this will be an array of entities
    // which will pass through Serializer to one of the registered Normalizers,
    // which will transform it to arrays/scalars. If the Data field row plugin
    // is used, $rows will not contain objects and will pass directly to the
    // Encoder.
    foreach ($this->view->result as $row) {
      if ($entity_view_plugin) {
        $custom_element = $this->getCustomElementGenerator()->generate($row->_entity, $this->view->rowPlugin->options['view_mode']);
      }
      else {
        $custom_element = new CustomElement();
        foreach ($this->view->field as $name => $value) {
          $custom_element->setAttribute($name, $value->render($row));
        }
      }
      $result['rows'][] = $custom_element;
    }

    if ($this->view->pager) {
      $result['pager'] = $this->pagination($result['rows']);
    }

    return $result;
  }

Since field row plugin is not supported I'm not going to investigate this more.