Skip to content

Commit

Permalink
Merge pull request #366 from craftcms/feature/365-entry-type-relabelling
Browse files Browse the repository at this point in the history
entry type relabelling
  • Loading branch information
brandonkelly authored Feb 18, 2025
2 parents 2a5c5bd + 1820bd4 commit 26bca68
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Added the ability to override entry type names and handles for CKEditor fields. ([#369](https://github.com/craftcms/ckeditor/discussions/369))
- CKEditor fields now show provisional drafts for nested entries when previewing an owner element. ([#340](https://github.com/craftcms/ckeditor/pull/340))
- Fixed an error that occurred if the “Who should see the ‘Source’ button?” field setting was totally blank. ([#359](https://github.com/craftcms/ckeditor/issues/359))

Expand Down
20 changes: 8 additions & 12 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -688,17 +688,10 @@ public function setEntryTypes(array $entryTypes): void
{
$entriesService = Craft::$app->getEntries();

$this->_entryTypes = array_values(array_filter(array_map(function(EntryType|string|int $entryType) use ($entriesService) {
if (is_numeric($entryType)) {
$entryType = $entriesService->getEntryTypeById($entryType);
} elseif (is_string($entryType)) {
$entryTypeUid = $entryType;
$entryType = $entriesService->getEntryTypeByUid($entryTypeUid);
} elseif (!$entryType instanceof EntryType) {
throw new InvalidArgumentException('Invalid entry type');
}
return $entryType;
}, $entryTypes)));
$this->_entryTypes = array_values(array_filter(array_map(
fn($entryType) => $entriesService->getEntryType($entryType),
$entryTypes,
)));
}

/**
Expand All @@ -723,7 +716,10 @@ public function getSettings(): array
$settings['removeNbsp'],
);

$settings['entryTypes'] = array_map(fn(EntryType $entryType) => $entryType->uid, $this->_entryTypes);
$settings['entryTypes'] = array_map(
fn(EntryType $entryType) => $entryType->getUsageConfig(),
$this->getEntryTypes(),
);

return $settings;
}
Expand Down
1 change: 1 addition & 0 deletions src/templates/_field-settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
id: 'entry-types',
name: 'entryTypes[]',
values: field.getEntryTypes(),
allowOverrides: true,
create: true,
errors: field.getErrors('entryTypes'),
data: {'error-key': 'entryTypes'},
Expand Down

0 comments on commit 26bca68

Please sign in to comment.