Problem/Motivation

It would be nice to have the field_example module demonstrate how a formatter plugin can expose user definable configuration on the manage display page.

Proposed resolution

Update one of the two existing formatter plugins so that it provides a configuration option. Right now they're both pretty simple formatters and we can make one of the two more complex without detracting from the learning experience.

This updates the \Drupal\field_example\Plugin\Field\FieldFormatter\ColorBackgroudFormatter plugin so that it has a user defined configuration option which can toggle on/off some additional logic that will attempt to automatically set the foreground color of the text depending on the lightness of the background color. This seemed like a real use-case without requiring a lot of extra code unrelated to thing we're trying to demonstrate which is how to make a formatter configurable.

Issue fork examples-3282251

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

eojthebrave created an issue. See original summary.

eojthebrave’s picture

Issue summary: View changes
Status: Active » Needs review

jungle made their first commit to this issue’s fork.

jungle’s picture

Version: 3.0.3 » 3.x-dev
Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs followup

The MR is great. Thanks! The field widget allows color values, e.g. 800080, but the formatter here expects value like #800080, leave this to another issue.

jungle’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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