Problem/Motivation

It would be good to support field per bundle configuration to take advantage of specific instances. For example, Photoswipe requires the bundle for certain settings such as target_bundle. This enables the selection of a specific image field on the target media entity.

Currently this is not possible with fieldblock.

There's a comment in FieldBlock.php:

   * A FieldBlock works on an entity type across bundles, and thus only has
   * access to field storage definitions. In order to be able to use formatters,
   * we create a generic field definition out of that storage definition.

Having access to the bundle would enable access to the specific FieldConfig rather than a generic field definition.

e.g.

$bundle_fields = $this->entityFieldManager->getFieldDefinitions($entity_type, $bundle);

Steps to reproduce

  1. Install fieldblock and photoswipe.
  2. Add a media reference field to a content type
  3. Place a content block in a region, selecting the reference field
  4. Under "Formatter" select "Photoswipe"
  5. Under "Formatter settings" the select list for "Image field of the referenced entity" will be empty.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#2 fieldblock bundles.png46.12 KBimclean

Issue fork fieldblock-3422529

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

imclean created an issue. See original summary.

imclean’s picture

FileSize
46.12 KB

I've created a proof of concept which lists relevant fields separately per bundle as well as an "all bundles" option, which is the default and works the same as it does now without any changes to config.

Before I refine the code for sharing I'd like some feedback on the approach. This is how the field list would present.

imclean’s picture

Status: Active » Needs review
imclean’s picture

I'm looking at adding support for third party settings. I think this only makes sense per instance so can probably be included here as well.

imclean’s picture

I've added support for third party settings. To test, enable Photoswipe's submodule Photoswipe Dynamic Caption and configure.