Custom elements Views: Per-field formatters are not supported/working

Created on 16 July 2024, 3 months ago
Updated 4 September 2024, about 1 month ago

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.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇞🇮Slovenia useernamee Ljubljana

Live updates comments and jobs are added and updated live.
  • views

    Involves, uses, or integrates with views. In Drupal 8 core, use the “VDC” tag instead.

Sign in to follow issues

Comments & Activities

  • Issue created by @useernamee
  • 🇊🇹Austria fago Vienna

    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?

  • 🇊🇹Austria fago Vienna
  • 🇞🇮Slovenia useernamee Ljubljana

    This issue is related to 📌 Use CE Generator to build View rows Needs work but it is not fixed by it.

  • 🇞🇮Slovenia useernamee Ljubljana

    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.

Production build 0.71.5 2024