Skip to content

Commit

Permalink
“‘New’ Button Label” setting
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Mar 14, 2024
1 parent 8da0879 commit 546c67d
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 7 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 “‘New’ Button Label” setting. ([#159](https://github.com/craftcms/ckeditor/discussions/159))
- Copy/pasting nested entry cards now duplicates the nested entries. ([#186](https://github.com/craftcms/ckeditor/issues/186), [#192](https://github.com/craftcms/ckeditor/pull/192))
- Fixed a bug where it was possible to copy/paste nested entry cards between CKEditor fields. ([#192](https://github.com/craftcms/ckeditor/pull/192))

Expand Down
23 changes: 23 additions & 0 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ function(array $match) use ($oldEntryIds, $newEntryIds) {
*/
public bool $showUnpermittedFiles = false;

/**
* @var string|null The “New entry” button label.
* @since 4.0.0
*/
public ?string $createButtonLabel = null;

/**
* @var EntryType[] The field’s available entry types
* @see getEntryTypes()
Expand Down Expand Up @@ -568,6 +574,7 @@ public function getSettingsHtml(): ?string
'value' => null,
],
], $transformOptions),
'defaultCreateButtonLabel' => $this->defaultCreateButtonLabel(),
]);
}

Expand Down Expand Up @@ -761,6 +768,7 @@ protected function inputHtml(mixed $value, ?ElementInterface $element, $inline):
'accessibleFieldName' => $this->_accessibleFieldName($element),
'describedBy' => $this->_describedBy($view),
'entryTypeOptions' => $this->_getEntryTypeOptions(),
'createButtonLabel' => $this->createButtonLabel(),
'findAndReplace' => [
'uiType' => 'dropdown',
],
Expand Down Expand Up @@ -1071,6 +1079,21 @@ private function _prepNestedEntriesForDisplay(string $value, ?int $elementSiteId
return $value;
}

private function createButtonLabel(): string
{
if (isset($this->createButtonLabel)) {
return Craft::t('site', $this->createButtonLabel);
}
return $this->defaultCreateButtonLabel();
}

private function defaultCreateButtonLabel(): string
{
return Craft::t('app', 'New {type}', [
'type' => Entry::lowerDisplayName(),
]);
}

private function isCpRequest(): bool
{
return (
Expand Down
10 changes: 10 additions & 0 deletions src/templates/_field-settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@
data: {'error-key': 'entryTypes'},
}) }}

{{ forms.textField({
label: '“New” Button Label'|t('app'),
instructions: 'The text label for the entry creation button.'|t('app'),
id: 'create-button-label',
name: 'createButtonLabel',
value: field.createButtonLabel,
placeholder: defaultCreateButtonLabel,
errors: field.getErrors('createButtonLabel')
}) }}

<hr>

<a class="fieldtoggle" data-target="assets">{{ 'Assets'|t('app') }}</a>
Expand Down
2 changes: 0 additions & 2 deletions src/web/assets/ckeditor/CkeditorAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ public function registerAssetFiles($view): void
$this->registerRefHandles($view);
$view->registerTranslations('app', [
'Edit {type}',
'entry',
'New {type}',
]);
$view->registerTranslations('ckeditor', [
'Entries cannot be copied between CKEditor fields.',
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/ckeditor/dist/ckeditor5-craftcms.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/ckeditor/dist/ckeditor5-craftcms.js.map

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions src/web/assets/ckeditor/src/entries/entriesui.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ export default class CraftEntriesUI extends Plugin {

const dropdownView = createDropdown(locale);
dropdownView.buttonView.set({
label: Craft.t('app', 'New {type}', {
type: Craft.t('app', 'entry'),
}),
label: editor.config.get('createButtonLabel'),
tooltip: true,
withText: true,
//commandValue: null,
Expand Down

0 comments on commit 546c67d

Please sign in to comment.