-
Notifications
You must be signed in to change notification settings - Fork 615
/
EntriesController.php
771 lines (647 loc) · 26.8 KB
/
EntriesController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/
namespace craft\controllers;
use Craft;
use craft\base\Element;
use craft\elements\Entry;
use craft\elements\User;
use craft\errors\InvalidElementException;
use craft\errors\UnsupportedSiteException;
use craft\helpers\DateTimeHelper;
use craft\helpers\UrlHelper;
use craft\models\Section;
use craft\models\Site;
use craft\services\Structures;
use craft\web\assets\editentry\EditEntryAsset;
use yii\base\InvalidConfigException;
use yii\web\BadRequestHttpException;
use yii\web\ForbiddenHttpException;
use yii\web\NotFoundHttpException;
use yii\web\Response;
use yii\web\ServerErrorHttpException;
/**
* The EntriesController class is a controller that handles various entry related tasks such as retrieving, saving,
* swapping between entry types, and deleting entries.
*
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 3.0.0
*/
class EntriesController extends BaseEntriesController
{
/**
* @event ElementEvent The event that is triggered when an entry’s template is rendered for Live Preview.
* @deprecated in 3.2.0
*/
const EVENT_PREVIEW_ENTRY = 'previewEntry';
/**
* Called when a user brings up an entry for editing before being displayed.
*
* @param string $section The section’s handle
* @param int|null $entryId The entry’s ID, if editing an existing entry.
* @param int|null $draftId The entry draft’s ID, if editing an existing draft.
* @param int|null $revisionId The entry revision’s ID, if editing an existing revision.
* @param string|null $site The site handle, if specified.
* @param Entry|null $entry The entry being edited, if there were any validation errors.
* @return Response
* @throws NotFoundHttpException if the requested site handle is invalid
* @throws ForbiddenHttpException
*/
public function actionEditEntry(string $section, int $entryId = null, int $draftId = null, int $revisionId = null, string $site = null, Entry $entry = null): Response
{
$variables = [
'sectionHandle' => $section,
'entryId' => $entryId,
'draftId' => $draftId,
'revisionId' => $revisionId,
'entry' => $entry
];
if ($site !== null) {
$siteHandle = $site;
$variables['site'] = Craft::$app->getSites()->getSiteByHandle($siteHandle);
if (!$variables['site']) {
throw new NotFoundHttpException('Invalid site handle: ' . $siteHandle);
}
}
if (($response = $this->_prepEditEntryVariables($variables)) !== null) {
return $response;
}
$this->getView()->registerAssetBundle(EditEntryAsset::class);
/** @var Site $site */
$site = $variables['site'];
/** @var Entry $entry */
$entry = $variables['entry'];
/** @var Section $section */
$section = $variables['section'];
// Make sure they have permission to edit this entry
$this->enforceSitePermission($entry->getSite());
$this->enforceEditEntryPermissions($entry);
$currentUser = Craft::$app->getUser()->getIdentity();
$variables['permissionSuffix'] = ':' . $entry->getSection()->uid;
if (Craft::$app->getEdition() === Craft::Pro && $section->type !== Section::TYPE_SINGLE) {
// Author selector variables
// ---------------------------------------------------------------------
$variables['userElementType'] = User::class;
$authorPermission = 'editEntries' . $variables['permissionSuffix'];
$variables['authorOptionCriteria'] = [
'can' => $authorPermission,
];
try {
if (($variables['author'] = $entry->getAuthor()) === null) {
// Default to the current user
$variables['author'] = $currentUser;
}
} catch (InvalidConfigException $e) {
// The author doesn't exist anymore
$variables['author'] = $currentUser;
}
}
// Parent Entry selector variables
// ---------------------------------------------------------------------
if (
$section->type === Section::TYPE_STRUCTURE &&
(int)$section->maxLevels !== 1
) {
$variables['elementType'] = Entry::class;
// Prevent the current entry, or any of its descendants, from being options
$excludeIds = Entry::find()
->descendantOf($entry)
->anyStatus()
->ids();
$excludeIds[] = $entry->getSourceId();
$variables['parentOptionCriteria'] = [
'siteId' => $site->id,
'sectionId' => $section->id,
'status' => null,
'where' => ['not in', 'elements.id', $excludeIds]
];
if ($section->maxLevels) {
if ($entry->id) {
// Figure out how deep the ancestors go
$maxDepth = Entry::find()
->select('level')
->descendantOf($entry)
->anyStatus()
->leaves()
->scalar();
$depth = 1 + ($maxDepth ?: $entry->level) - $entry->level;
} else {
$depth = 1;
}
$variables['parentOptionCriteria']['level'] = '<= ' . ($section->maxLevels - $depth);
}
// Get the initially selected parent
$parentId = $this->request->getParam('parentId');
if ($parentId === null) {
// Is it already set on the model (e.g. if we're loading a draft)?
if ($entry->newParentId !== null) {
$parentId = $entry->newParentId;
} else {
$parentId = $entry->getAncestors(1)
->anyStatus()
->ids();
}
}
if (is_array($parentId)) {
$parentId = reset($parentId) ?: null;
}
if ($parentId) {
$variables['parent'] = Craft::$app->getEntries()->getEntryById($parentId, $site->id);
}
}
// Other variables
// ---------------------------------------------------------------------
// Body class
$variables['bodyClass'] = 'edit-entry site--' . $site->handle;
// Page title
$variables['docTitle'] = $this->docTitle($entry);
$variables['title'] = $this->pageTitle($entry);
// Breadcrumbs
$variables['crumbs'] = [
[
'label' => Craft::t('app', 'Entries'),
'url' => UrlHelper::url('entries')
]
];
if ($section->type === Section::TYPE_SINGLE) {
$variables['crumbs'][] = [
'label' => Craft::t('app', 'Singles'),
'url' => UrlHelper::url('entries/singles')
];
} else {
$variables['crumbs'][] = [
'label' => Craft::t('site', $section->name),
'url' => UrlHelper::url('entries/' . $section->handle)
];
if ($section->type === Section::TYPE_STRUCTURE) {
/** @var Entry $ancestor */
foreach ($entry->getAncestors()->all() as $ancestor) {
$variables['crumbs'][] = [
'label' => $ancestor->title,
'url' => $ancestor->getCpEditUrl()
];
}
}
}
// Multiple entry types?
$entryTypes = $entry->getAvailableEntryTypes();
if (count($entryTypes) > 1) {
$variables['showEntryTypes'] = true;
foreach ($entryTypes as $entryType) {
$variables['entryTypeOptions'][] = [
'label' => Craft::t('site', $entryType->name),
'value' => $entryType->id
];
}
$this->getView()->registerJs('new Craft.EntryTypeSwitcher();');
} else {
$variables['showEntryTypes'] = false;
}
// Can the user delete the entry?
$variables['canDeleteSource'] = $section->type !== Section::TYPE_SINGLE && (
($entry->authorId == $currentUser->id && $currentUser->can('deleteEntries' . $variables['permissionSuffix'])) ||
($entry->authorId != $currentUser->id && $currentUser->can('deletePeerEntries' . $variables['permissionSuffix']))
);
// Render the template!
return $this->renderTemplate('entries/_edit', $variables);
}
/**
* Switches between two entry types.
*
* @return Response
* @throws ForbiddenHttpException
*/
public function actionSwitchEntryType(): Response
{
$this->requirePostRequest();
$this->requireAcceptsJson();
$entry = $this->_getEntryModel();
$this->enforceSitePermission($entry->getSite());
$this->enforceEditEntryPermissions($entry);
$this->_populateEntryModel($entry);
$variables = [];
$variables['sectionId'] = $entry->sectionId;
$variables['entry'] = $entry;
$variables['showEntryTypes'] = true;
if (($response = $this->_prepEditEntryVariables($variables)) !== null) {
return $response;
}
$view = $this->getView();
$form = $variables['entryType']->getFieldLayout()->createForm($variables['entry']);
$tabs = $form->getTabMenu();
return $this->asJson([
'tabsHtml' => count($tabs) > 1 ? $view->renderTemplate('_includes/tabs', [
'tabs' => $tabs,
]) : null,
'fieldsHtml' => $form->render(),
'headHtml' => $view->getHeadHtml(),
'bodyHtml' => $view->getBodyHtml(),
]);
}
/**
* Saves an entry.
*
* @param bool $duplicate Whether the entry should be duplicated
* @return Response|null
* @throws ServerErrorHttpException if reasons
* @throws ForbiddenHttpException
*/
public function actionSaveEntry(bool $duplicate = false)
{
$this->requirePostRequest();
$entry = $this->_getEntryModel();
$entryVariable = $this->request->getValidatedBodyParam('entryVariable') ?? 'entry';
// Permission enforcement
$this->enforceSitePermission($entry->getSite());
$this->enforceEditEntryPermissions($entry, $duplicate);
$currentUser = Craft::$app->getUser()->getIdentity();
// Is this another user's entry (and it's not a Single)?
if (
$entry->id &&
!$duplicate &&
$entry->authorId != $currentUser->id &&
$entry->getSection()->type !== Section::TYPE_SINGLE &&
$entry->enabled
) {
// Make sure they have permission to make live changes to those
$this->requirePermission('publishPeerEntries:' . $entry->getSection()->uid);
}
// Keep track of whether the entry was disabled as a result of duplication
$forceDisabled = false;
// If we're duplicating the entry, swap $entry with the duplicate
if ($duplicate) {
try {
$wasEnabled = $entry->enabled;
$entry = Craft::$app->getElements()->duplicateElement($entry);
if ($wasEnabled && !$entry->enabled) {
$forceDisabled = true;
}
} catch (InvalidElementException $e) {
/** @var Entry $clone */
$clone = $e->element;
if ($this->request->getAcceptsJson()) {
return $this->asJson([
'success' => false,
'errors' => $clone->getErrors(),
]);
}
$this->setFailFlash(Craft::t('app', 'Couldn’t duplicate entry.'));
// Send the original entry back to the template, with any validation errors on the clone
$entry->addErrors($clone->getErrors());
Craft::$app->getUrlManager()->setRouteParams([
'entry' => $entry
]);
return null;
} catch (\Throwable $e) {
throw new ServerErrorHttpException(Craft::t('app', 'An error occurred when duplicating the entry.'), 0, $e);
}
}
// Populate the entry with post data
$this->_populateEntryModel($entry);
if ($forceDisabled) {
$entry->enabled = false;
}
// Even more permission enforcement
if ($entry->enabled) {
if ($entry->id) {
$this->requirePermission('publishEntries:' . $entry->getSection()->uid);
} else if (!$currentUser->can('publishEntries:' . $entry->getSection()->uid)) {
$entry->enabled = false;
}
}
// Save the entry (finally!)
if ($entry->enabled && $entry->getEnabledForSite()) {
$entry->setScenario(Element::SCENARIO_LIVE);
}
try {
$success = Craft::$app->getElements()->saveElement($entry);
} catch (UnsupportedSiteException $e) {
$entry->addError('siteId', $e->getMessage());
$success = false;
}
if (!$success) {
if ($this->request->getAcceptsJson()) {
return $this->asJson([
'errors' => $entry->getErrors(),
]);
}
$this->setFailFlash(Craft::t('app', 'Couldn’t save entry.'));
// Send the entry back to the template
Craft::$app->getUrlManager()->setRouteParams([
$entryVariable => $entry
]);
return null;
}
if ($this->request->getAcceptsJson()) {
$return = [];
$return['success'] = true;
$return['id'] = $entry->id;
$return['title'] = $entry->title;
$return['slug'] = $entry->slug;
if ($this->request->getIsCpRequest()) {
$return['cpEditUrl'] = $entry->getCpEditUrl();
}
if (($author = $entry->getAuthor()) !== null) {
$return['authorUsername'] = $author->username;
}
$return['dateCreated'] = DateTimeHelper::toIso8601($entry->dateCreated);
$return['dateUpdated'] = DateTimeHelper::toIso8601($entry->dateUpdated);
$return['postDate'] = ($entry->postDate ? DateTimeHelper::toIso8601($entry->postDate) : null);
return $this->asJson($return);
}
$this->setSuccessFlash(Craft::t('app', 'Entry saved.'));
return $this->redirectToPostedUrl($entry);
}
/**
* Duplicates an entry.
*
* @return Response|null
* @throws ServerErrorHttpException if reasons
* @since 3.2.3
*/
public function actionDuplicateEntry()
{
return $this->runAction('save-entry', ['duplicate' => true]);
}
/**
* Deletes an entry.
*
* @return Response|null
* @throws BadRequestHttpException if the requested entry cannot be found
*/
public function actionDeleteEntry()
{
$this->requirePostRequest();
$entryId = $this->request->getBodyParam('sourceId') ?? $this->request->getRequiredBodyParam('entryId');
$siteId = $this->request->getBodyParam('siteId');
$entry = Craft::$app->getEntries()->getEntryById($entryId, $siteId);
if (!$entry) {
throw new BadRequestHttpException("Invalid entry ID: $entryId");
}
$currentUser = Craft::$app->getUser()->getIdentity();
if ($entry->authorId == $currentUser->id) {
$this->requirePermission('deleteEntries:' . $entry->getSection()->uid);
} else {
$this->requirePermission('deletePeerEntries:' . $entry->getSection()->uid);
}
if (!Craft::$app->getElements()->deleteElement($entry)) {
if ($this->request->getAcceptsJson()) {
return $this->asJson(['success' => false]);
}
$this->setFailFlash(Craft::t('app', 'Couldn’t delete entry.'));
// Send the entry back to the template
Craft::$app->getUrlManager()->setRouteParams([
'entry' => $entry
]);
return null;
}
if ($this->request->getAcceptsJson()) {
return $this->asJson(['success' => true]);
}
$this->setSuccessFlash(Craft::t('app', 'Entry deleted.'));
return $this->redirectToPostedUrl($entry);
}
/**
* Preps entry edit variables.
*
* @param array &$variables
* @return Response|null
* @throws NotFoundHttpException if the requested section or entry cannot be found
* @throws ForbiddenHttpException if the user is not permitted to edit content in the requested site
*/
private function _prepEditEntryVariables(array &$variables)
{
// Get the section
// ---------------------------------------------------------------------
if (!empty($variables['sectionHandle'])) {
$variables['section'] = Craft::$app->getSections()->getSectionByHandle($variables['sectionHandle']);
} else if (!empty($variables['sectionId'])) {
$variables['section'] = Craft::$app->getSections()->getSectionById($variables['sectionId']);
}
if (empty($variables['section'])) {
throw new NotFoundHttpException('Section not found');
}
// Get the site
// ---------------------------------------------------------------------
$siteIds = $this->editableSiteIds($variables['section']);
if (empty($variables['site'])) {
/** @noinspection PhpUnhandledExceptionInspection */
$variables['site'] = Craft::$app->getSites()->getCurrentSite();
if (!in_array($variables['site']->id, $siteIds, false)) {
$variables['site'] = Craft::$app->getSites()->getSiteById($siteIds[0]);
}
$site = $variables['site'];
} else {
// Make sure they were requesting a valid site
/** @var Site $site */
$site = $variables['site'];
if (!in_array($site->id, $siteIds, false)) {
throw new ForbiddenHttpException('User not permitted to edit content in this site');
}
}
// Get the entry
// ---------------------------------------------------------------------
if (empty($variables['entry'])) {
if (empty($variables['entryId'])) {
throw new BadRequestHttpException('Request missing required entryId param');
}
$variables['entry'] = $this->_loadEntry(
$site,
$variables['section'],
$variables['entryId'],
$variables['draftId'] ?? null,
$variables['revisionId'] ?? null
);
if (!$variables['entry']) {
// If they're attempting to access adraft/revision, or if the entry may be available in another
// site, try to redirect them
if (
count($siteIds) > 1 ||
!empty($variables['draftId']) ||
!empty($variables['revisionId'])
) {
$sourceEntry = Entry::find()
->id($variables['entryId'])
->siteId($siteIds)
->preferSites([$site->id])
->unique()
->anyStatus()
->one();
if ($sourceEntry) {
return $this->redirect($sourceEntry->getCpEditUrl(), 301);
}
}
throw new NotFoundHttpException('Entry not found');
}
}
// Determine whether we're showing the site label & site-specific entry status
// ---------------------------------------------------------------------
// Show the site label in the revision menu as long as the section is enabled for multiple sites,
// even if the entry itself is only enabled for one site
$variables['showSiteLabel'] = (
Craft::$app->getIsMultiSite() &&
count($variables['section']->getSiteSettings()) > 1
);
$variables['isMultiSiteEntry'] = (
Craft::$app->getIsMultiSite() &&
count($variables['entry']->getSupportedSites()) > 1
);
// Get the entry type
// ---------------------------------------------------------------------
// Override the entry type?
$typeId = $this->request->getParam('typeId');
if (!$typeId) {
// Default to the section's first entry type
$typeId = $variables['entry']->typeId ?? $variables['entry']->getAvailableEntryTypes()[0]->id;
}
$variables['entry']->typeId = $typeId;
$variables['entryType'] = $variables['entry']->getType();
// Prevent the last entry type's field layout from being used
$variables['entry']->fieldLayoutId = null;
return null;
}
/**
* Loads the requested entry.
*
* @param Site $site
* @param Section $section
* @param int $entryId
* @param int|null $draftId
* @param int|null $revisionId
* @return Entry|null
*/
private function _loadEntry(Site $site, Section $section, int $entryId, int $draftId = null, int $revisionId = null)
{
if ($draftId) {
$entry = Entry::find()
->draftId($draftId)
->structureId($section->structureId)
->siteId($site->id)
->anyStatus()
->one();
} else if ($revisionId) {
$entry = Entry::find()
->revisionId($revisionId)
->structureId($section->structureId)
->siteId($site->id)
->anyStatus()
->one();
} else {
$entry = Entry::find()
->id($entryId)
->structureId($section->structureId)
->siteId($site->id)
->anyStatus()
->one();
}
if ($entry) {
return $entry;
}
// If a draft or revision was requested in a Structure section, see if it's just missing a `structureelements` record
if ($section->structureId) {
if ($draftId) {
$entry = Entry::find()
->draftId($draftId)
->siteId($site->id)
->anyStatus()
->one();
} else if ($revisionId) {
$entry = Entry::find()
->revisionId($revisionId)
->siteId($site->id)
->anyStatus()
->one();
}
if ($entry) {
// Get the source entry
$sourceEntry = Entry::find()
->id($entryId)
->siteId($site->id)
->anyStatus()
->one();
if ($sourceEntry) {
// Insert the draft/revision alongside the source entry
Craft::$app->getStructures()->moveAfter($section->structureId, $entry, $sourceEntry, Structures::MODE_INSERT);
return $entry;
}
}
}
return null;
}
/**
* Fetches or creates an Entry.
*
* @return Entry
* @throws NotFoundHttpException if the requested entry cannot be found
*/
private function _getEntryModel(): Entry
{
$entryId = $this->request->getBodyParam('draftId') ?? $this->request->getBodyParam('sourceId') ?? $this->request->getBodyParam('entryId');
$siteId = $this->request->getBodyParam('siteId');
if ($entryId) {
$entry = Craft::$app->getEntries()->getEntryById($entryId, $siteId);
if (!$entry) {
throw new NotFoundHttpException('Entry not found');
}
} else {
$entry = new Entry();
$entry->sectionId = $this->request->getRequiredBodyParam('sectionId');
if ($siteId) {
$entry->siteId = $siteId;
}
}
return $entry;
}
/**
* Populates an Entry with post data.
*
* @param Entry $entry
*/
private function _populateEntryModel(Entry $entry)
{
// Set the entry attributes, defaulting to the existing values for whatever is missing from the post data
$entry->typeId = $this->request->getBodyParam('typeId', $entry->typeId);
$entry->slug = $this->request->getBodyParam('slug', $entry->slug);
if (($postDate = $this->request->getBodyParam('postDate')) !== null) {
$entry->postDate = DateTimeHelper::toDateTime($postDate) ?: null;
}
if (($expiryDate = $this->request->getBodyParam('expiryDate')) !== null) {
$entry->expiryDate = DateTimeHelper::toDateTime($expiryDate) ?: null;
}
$enabledForSite = $this->enabledForSiteValue();
if (is_array($enabledForSite)) {
// Set the global status to true if it's enabled for *any* sites, or if already enabled.
$entry->enabled = in_array(true, $enabledForSite, false) || $entry->enabled;
} else {
$entry->enabled = (bool)$this->request->getBodyParam('enabled', $entry->enabled);
}
$entry->setEnabledForSite($enabledForSite ?? $entry->getEnabledForSite());
$entry->title = $this->request->getBodyParam('title', $entry->title);
if (!$entry->typeId) {
// Default to the section's first entry type
$entry->typeId = $entry->getAvailableEntryTypes()[0]->id;
}
// Prevent the last entry type's field layout from being used
$entry->fieldLayoutId = null;
$fieldsLocation = $this->request->getParam('fieldsLocation', 'fields');
$entry->setFieldValuesFromRequest($fieldsLocation);
// Author
$authorId = $this->request->getBodyParam('author', ($entry->authorId ?: Craft::$app->getUser()->getIdentity()->id));
if (is_array($authorId)) {
$authorId = $authorId[0] ?? null;
}
$entry->authorId = $authorId;
// Parent
if (($parentId = $this->request->getBodyParam('parentId')) !== null) {
if (is_array($parentId)) {
$parentId = reset($parentId) ?: '';
}
$entry->newParentId = $parentId ?: '';
}
// Revision notes
$entry->setRevisionNotes($this->request->getBodyParam('revisionNotes'));
}
}