Skip to content

Commit

Permalink
Merge pull request #296 from craftcms/bugfix/295-site-id-adjustments
Browse files Browse the repository at this point in the history
Keep passing `siteId` around
  • Loading branch information
brandonkelly authored Oct 19, 2024
2 parents acae379 + 4132393 commit cbbebe2
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- CKEditor container divs now have `data-config` attributes, set to the CKEditor config’s handle. ([#284](https://github.com/craftcms/ckeditor/issues/284))
- Fixed a bug where page breaks were being lost.
- Fixed a bug where menus within overflown toolbar items weren’t fully visible. ([#286](https://github.com/craftcms/ckeditor/issues/286))
- Fixed an error that occurred when editing a nested entry, if it didn’t exist in the primary site. ([#295](https://github.com/craftcms/ckeditor/issues/295))

## 4.2.0 - 2024-08-15

Expand Down
1 change: 1 addition & 0 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,7 @@ protected function prepValueForInput($value, ?ElementInterface $element, bool $s
return Html::tag('craft-entry', options: [
'data' => [
'entry-id' => $entry->isProvisionalDraft ? $entry->getCanonicalId() : $entry->id,
'site-id' => $entry->siteId,
'card-html' => $cardHtml,
],
]);
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.

1 change: 1 addition & 0 deletions src/web/assets/ckeditor/src/entries/entriescommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default class CraftEntriesCommand extends Command {
...Object.fromEntries(selection.getAttributes()),
cardHtml: options.cardHtml,
entryId: options.entryId,
siteId: options.siteId,
});

// ... and insert it into the document. Put the selection on the inserted element.
Expand Down
10 changes: 8 additions & 2 deletions src/web/assets/ckeditor/src/entries/entriesediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default class CraftEntriesEditing extends Plugin {

schema.register('craftEntryModel', {
inheritAllFrom: '$blockObject',
allowAttributes: ['cardHtml', 'entryId'],
allowAttributes: ['cardHtml', 'entryId', 'siteId'],
allowChildren: false,
});
}
Expand All @@ -73,10 +73,12 @@ export default class CraftEntriesEditing extends Plugin {
model: (viewElement, {writer: modelWriter}) => {
const cardHtml = viewElement.getAttribute('data-card-html');
const entryId = viewElement.getAttribute('data-entry-id');
const siteId = viewElement.getAttribute('data-site-id') ?? null;

return modelWriter.createElement('craftEntryModel', {
cardHtml: cardHtml,
entryId: entryId,
siteId: siteId,
});
},
});
Expand All @@ -86,9 +88,11 @@ export default class CraftEntriesEditing extends Plugin {
model: 'craftEntryModel',
view: (modelItem, {writer: viewWriter}) => {
const entryId = modelItem.getAttribute('entryId') ?? null;
const siteId = modelItem.getAttribute('siteId') ?? null;
const cardContainer = viewWriter.createContainerElement('div', {
class: 'cke-entry-card',
'data-entry-id': entryId,
'data-site-id': siteId,
});
addCardHtmlToContainer(modelItem, viewWriter, cardContainer);

Expand All @@ -102,9 +106,11 @@ export default class CraftEntriesEditing extends Plugin {
model: 'craftEntryModel',
view: (modelItem, {writer: viewWriter}) => {
const entryId = modelItem.getAttribute('entryId') ?? null;
const siteId = modelItem.getAttribute('siteId') ?? null;

return viewWriter.createContainerElement('craft-entry', {
'data-entry-id': entryId,
'data-site-id': siteId,
});
},
});
Expand Down Expand Up @@ -160,7 +166,7 @@ export default class CraftEntriesEditing extends Plugin {
}

const entryId = modelItem.getAttribute('entryId') ?? null;
const siteId = Craft.siteId;
const siteId = modelItem.getAttribute('siteId') ?? null;

try {
// Let the element editor handle the autosave first, in case the nested entry
Expand Down
14 changes: 11 additions & 3 deletions src/web/assets/ckeditor/src/entries/entriesui.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ export default class CraftEntriesUI extends Plugin {
const selection = this.editor.model.document.selection;
const viewElement = selection.getSelectedElement();
const entryId = viewElement.getAttribute('entryId');
const siteId = viewElement.getAttribute('siteId') ?? null;

this._showEditEntrySlideout(entryId);
this._showEditEntrySlideout(entryId, siteId);
}
});
}
Expand Down Expand Up @@ -191,7 +192,9 @@ export default class CraftEntriesUI extends Plugin {
const selection = this.editor.model.document.selection;
const viewElement = selection.getSelectedElement();
const entryId = viewElement.getAttribute('entryId');
this._showEditEntrySlideout(entryId);
const siteId = viewElement.getAttribute('siteId') ?? null;

this._showEditEntrySlideout(entryId, siteId);
});

return button;
Expand All @@ -203,9 +206,12 @@ export default class CraftEntriesUI extends Plugin {
* @param entryId
* @private
*/
_showEditEntrySlideout(entryId) {
_showEditEntrySlideout(entryId, siteId) {
Craft.createElementEditor(this.elementType, {
elementId: entryId,
params: {
siteId: siteId,
},
});
}

Expand Down Expand Up @@ -259,12 +265,14 @@ export default class CraftEntriesUI extends Plugin {
draftId: data.element.draftId,
params: {
fresh: 1,
siteId: data.element.siteId,
},
});

slideout.on('submit', (ev) => {
editor.commands.execute('insertEntry', {
entryId: ev.data.id,
siteId: ev.data.siteId,
});
});
}
Expand Down

0 comments on commit cbbebe2

Please sign in to comment.