Problem/Motivation

In validating the API for contrib modules to add block/formatter/widget plugins we wrote a sample field block plugin that just deferred to the Formatter component using the field block settings.
We didn't add this to the repo.

Steps to reproduce

Proposed resolution

Add the plugin to the repo.
Change the Formatter component to add a fallback param that should be rendered if the plugin doesn't exist.
Pass the fallback from the block to the formatter.

Remaining tasks

Implementation
Tests

User interface changes

API changes

Data model changes

Comments

larowlan created an issue.

larowlan’s picture

import React from "react";
import {
  DefaultBlockSettings,
  Formatter as FormatterComponent,
} from "@drupal/decoupled_lb";

import type {
  BlockConfiguration,
  DisplaySettings,
  FieldValues,
  LayoutBlock,
} from "@drupal/decoupled_lb";

interface InlineBlockConfiguration extends BlockConfiguration {
  view_mode: string;
  block_revision_id: string | number;
  field_values: Record<string, Array<FieldValues>>;
  label_display: boolean;
  formatter: DisplaySettings;
}

export const Preview: React.FC<LayoutBlock<InlineBlockConfiguration>> = (
  component,
) => {
  const { configuration } = component;
  const { id } = configuration;
  const [, , name] = id.split(":");
  return (
    <FormatterComponent
      fieldName={name}
      key={name}
      itemValues={component.configuration.field_values}
      formatter={configuration}
    />
  );
};

/** We don't allow editing yet because denormalizing doesn't do anything */
export const Edit = Preview;
export const Settings = DefaultBlockSettings;