Content elements with their child records
Content gives another extension the content-type rule
of create_ (ADR-324): which
content types a draft can fill, what a model may put into one, which of them a
page and a user allow, and the DataHandler datamap of one element with its
child records. nr_landingpage's Page Composer builds its sections through it.
Describing a type and building one element of it
use Netresearch\NrLlm\Service\Tool\ContentType\ContentElementComposer;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
final readonly class MySectionWriter
{
public function __construct(
private ContentElementComposer $composer,
) {}
public function accordion(int $parentPage, BackendUserAuthentication $user): array
{
// What a model may fill, for the prompt; null when not offered.
$shape = $this->composer->describe('accordion', $GLOBALS['LANG'] ?? null, $user);
$map = $this->composer->dataMap(
'accordion',
'NEW_content_0',
[],
['tx_bootstrappackage_accordion_item' => [
['header' => 'Question', 'bodytext' => '<p>Answer.</p>'],
]],
'NEW_page',
$parentPage,
0,
$user,
);
if ($map->isRefused()) {
throw new \RuntimeException(implode(' ', $map->refusals));
}
// The result is read-only: copy it, merge CType, header, pid
// and position into the element's row, and write the copy
// together with the page in one DataHandler call.
$dataMap = $map->dataMap;
$dataMap['tt_content']['NEW_content_0'] += [
'CType' => 'accordion',
'header' => 'FAQ',
'pid' => 'NEW_page',
'colPos' => 0,
];
return $dataMap;
}
}
Copied!
offeredTypes () - The content types a draft can fill on this installation, in the order the TCA declares them.
describe() - One offered type as an array a model reads:
type,label,description(the TCA item's description, a usage hint),fields(column totype,label,requiredand, where they apply,max,items,rich),Text children(inline column totable,maxand theItems fieldsof its records) andflex(FlexForm column to its simple fields). A child column whose items a processor computes carries their names asForms items, or asitems(By column, itsdefault, anditemsper choice of that column) where they depend on an earlier select of the record.itemsmarks a list known to be incomplete (ADR-326). With a user, the columns that user may not set are left out.Partial nullfor a type the rule does not offer. A later version may add keys; none is removed. typesOffered On Page () - The candidates a user may create on a page: those the page's
TCEFORM.andtt_ content. CType. keep Items removekeep (not read for pageItems 0), that the user'sauthonMode CTypeallows, and whose child records the user may write. A candidate the rule does not describe is kept when the page and the user allow it. dataMap () Content: the columns to merge into the caller's element row (furtherElement Data Map fields, FlexForm defaults with the values given infieldsas{Flex, the inline columns naming the child placeholders) and the child rows per table, or the refusals (Form column: {field: value}} is,Refused () $refusals). Every value is checked against the TCA and the page TSconfig of$page; the child records againstUid tables_, exclude fields andmodify auth, and in a draft workspace against the versioning of their table. The element's own type (Mode CTypekeepItems, removeItems andauth) isMode types's question.Offered On Page () $pidis what the rows get: a page uid or the placeholder of a page in the same datamap. Nothing is written here; the caller writes the datamap. The caller checks that the user may edit content on$pagefirst: a processor of a child select runs for that page, and a refusal names its choices.Uid