Problem/Motivation

We currently have UiPatternsSource plugins that define the available SourceField for a given need (using tags). Those plugins only generate the list of the available fields but never their values. The values recovery is hardcoded where those plugins are used (FieldGroupFormatter, FieldFormatter, ViewsRow, etc.). This absolutely negates the interest of having plugins to extend the available options.

For example, in #3341586: Allow to get the label from the field_display_label module we would like to integrate with a contrib modules that defines a field label dedicated to display. With an appropriate implementation, this contrib module should provide its own Source plugin to declare the new field then return its value if it's used in any pattern.

It would be the same if someone would like to add a custom value based on whatever logic they want. It's not possible without altering the contrib code.

Proposed resolution

Refactor the Source plugins so they are called to provide the field value too.
Try to find a way to prevent BC break.

Remaining tasks

Implement without breaking tests
Extend test coverage with some custom Source plugin implementation

User interface changes

None

API changes

Source plugins will have to implement a new method.

Data model changes

None

Comments

DuaelFr created an issue. See original summary.

grimreaper’s picture

Related issues: +#3344518: [2.0.x] Roadmap

Hi,

Thanks for the issue.

I think you have more deep dived into those plugins mecanism than me.

I agree that it is confusing to have on one almost emply plugins which only declares fields and on the other side plugins which need to use the first plugins and then load themselves the data.

I propose either:
- 1) do as you proposed and it is the plugin declareing the field that is also repsonsible to provide the data
- 2) remove the source plugins

But as mentioned, I think you have more manipulated Ui patterns plugins than me.

duaelfr’s picture

Title: Source plugins should also provide SourceField value » [2.0.x] Source plugins should also provide SourceField value
Version: 8.x-1.x-dev » 2.0.x-dev
pdureau’s picture

Status: Active » Needs work
Parent issue: » #3395961: [2.0.0-alpha1] Add new PropTypes & Sources plugins API
pdureau’s picture

Assigned: Unassigned » duaelfr
Status: Needs work » Needs review

We have a new source plugin in UI Patterns 2.x which is now able to retrieve the data:

  /**
   * Returns the processed source plugin data.
   */
  public function getData(): mixed;

Source: https://git.drupalcode.org/project/ui_patterns/-/blob/2.0.x/src/SourceIn...

Because form widgets (successor of UI Patterns Settings plugins) are also source plugins, the base plugin implementation will often be good enough:

  public function getData(): mixed {
    $configuration = $this->getConfiguration();
    return $configuration["form_value"] ?? NULL;
  }

Source: https://git.drupalcode.org/project/ui_patterns/-/blob/2.0.x/src/SourcePl...

Some plugins will override this method to do more complex processing. Example: https://git.drupalcode.org/project/ui_patterns/-/blob/2.0.x/src/Plugin/U...

Dualefr, is it what you expected?

pdureau’s picture

Title: [2.0.x] Source plugins should also provide SourceField value » [[2.0.0-alpha1]] Source plugins should also provide SourceField value
pdureau’s picture

Title: [[2.0.0-alpha1]] Source plugins should also provide SourceField value » [2.0.0-alpha1]] Source plugins should also provide SourceField value
pdureau’s picture

Title: [2.0.0-alpha1]] Source plugins should also provide SourceField value » [2.0.0-alpha1] Source plugins should also provide SourceField value
pdureau’s picture

Assigned: duaelfr » Unassigned
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.