Views individual subfield formatter support

Created on 25 November 2024, 4 months ago

Problem/Motivation

Individual subfields in views don't currently allow formatter selection as hook_views_data is defining each field to use the standard field plugin.

Proposed resolution

Create a custom views field plugin that incorporates formatter plugins into settings form and processes the formatted value vs. the raw value.

User interface changes

Views formatter settings for each subfield would be available.

📌 Task
Status

Active

Version

3.0

Component

Code

Created by

🇺🇸United States apmsooner

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @apmsooner
  • Merge request !74Views initial subfield formatter logic. → (Open) created by apmsooner
  • 🇺🇸United States apmsooner

    Opening an initial MR to get the ball rolling on this. It's not 100% yet but functioning as expected at least so far.

  • 🇮🇹Italy giuse69

    hi, so far patch 74 does not work throwing php exception of field unknown

  • 🇺🇸United States apmsooner

    Try clearing cache and if still errors, please look at your logs and post here anything thats helpful. I'm not seeing any php errors in my testing.

  • 🇮🇹Italy giuse69

    Hi, I had cleared the cache. The scenario is as follows:
    -) one vocabulary "country"
    -) another vocabulary "area", where there is a custom field "items" with unlimited values. Its subfields are: "item" that is a reference to "country" and "inclusion" that is the type of inclusion of the country in that area.
    -) a view on country vocabulary to show in which areas a country is. Contextual filter = term id, relationship = "Relate each Taxonomy term with a field_area_items_item set to the taxonomy term".
    -) Showing field "Taxonomy term: Items" gives no output and there is no PHP error - first problem.
    -) Showing field "Taxonomy term: Items:inclusion" throws PHP exception "Uncaught PHP Exception InvalidArgumentException: "Field field_area_items is unknown." at /web/core/lib/Drupal/Core/Entity/ContentEntityBase.php line 616" - second problem.

    Let me know if you need more info.
    thanks

    Giuse

  • 🇺🇸United States apmsooner

    The patch sort of works but multi-lingual results in some errors in the view that I'm not able to resolve immediately. The need for individual subfield formatters is low priority for now and I want to focus on getting a stable release out as well as features that hit a broader need.

  • 🇮🇹Italy giuse69

    Ok, I will wait. Let me just add that, as I wrote in https://www.drupal.org/project/custom_field/issues/3476033 Support not just values in custom template Active , for me the issue is not on subfields but on the custom field itself: when I try to use a custom field in a view of taxonomy terms in a multilingual site, it never works correctly: either it does not show anything, or it throws a PHP error, or it messes up the query and unrequested taxonomy terms show up.
    While if I use directly its subfields in the view, the result is correct, just without the chance of selecting tokens or formatters.
    Thanks for your precious work

  • 🇮🇹Italy giuse69

    Hi Andy, will you explicitly write here when the patch is ready for testing?

  • Status changed to Needs work 6 days ago
  • 🇺🇸United States emilorol

    Is there any update on this?

    Having multiple fields exposed in the views is working like a charm, we are just missing the part of displaying the values instead of keys.

    Will this change be part of the current module?

  • 🇺🇸United States emilorol

    I tried applying the changes as a patch:

            "patches": {
                "drupal/custom_field": {
                    "Views individual subfield formatter support": "https://git.drupalcode.org/project/custom_field/-/merge_requests/74.diff"
                }
            }
    

    and I got the following error:

      - Applying patches for drupal/custom_field
        https://git.drupalcode.org/project/custom_field/-/merge_requests/74.diff (Views individual subfield formatter support)
       Could not apply patch! Skipping. The error was: Cannot apply patch https://git.drupalcode.org/project/custom_field/-/merge_requests/74.diff
    
    In Patches.php line 331:
                                                                                                                                                  
      Cannot apply patch Views individual subfield formatter support (https://git.drupalcode.org/project/custom_field/-/merge_requests/74.diff)! 
    
  • 🇺🇸United States apmsooner

    The patch needs to be started over against the 3.1x branch. Alot has changed since and I havn't had a chance to revisit this. If not this next release, the one after I should get to it.

  • 🇺🇸United States emilorol

    Let me take a wack at it. I need this functionality for a project.

Production build 0.71.5 2024