Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cms 1091 ability to move entries to a new section #14541

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
84eee0b
move entries to section element action (WIP)
i-just Mar 5, 2024
d6f79aa
remove console logs
i-just Mar 5, 2024
1d261bb
make it work via keyboard
i-just Mar 5, 2024
8c0ef2a
Merge branch '5.0' into feature/cms-1091-ability-to-move-entries-to-a…
i-just Mar 6, 2024
d0951af
and now do it properly
i-just Mar 6, 2024
3aee4de
better messages
i-just Mar 6, 2024
2b88732
quietly deal with authors incompatibilities
i-just Mar 6, 2024
971d386
permissions!
i-just Mar 6, 2024
5af4894
Merge branch '5.0' into feature/cms-1091-ability-to-move-entries-to-a…
i-just Mar 6, 2024
ce8d275
Merge branch '5.0' into feature/cms-1091-ability-to-move-entries-to-a…
i-just Mar 8, 2024
dd8040e
allow move when too many authors
i-just Mar 8, 2024
1192188
move drafts & revisions too
i-just Mar 8, 2024
e2a2420
safeguard applying drafts & reverting to revisions
i-just Mar 8, 2024
b527083
Update tooltip to work on disabled elements
brianjhanson Mar 9, 2024
f650ae1
Merge branch '5.0' into feature/cms-1091-ability-to-move-entries-to-a…
i-just Mar 11, 2024
78f2e7a
Merge pull request #14561 from craftcms/feature/tooltip-on-diabled-el…
i-just Mar 11, 2024
0f40cfa
Merge branch 'feature/cms-1091-ability-to-move-entries-to-a-new-secti…
i-just Mar 11, 2024
2d3a431
tooltip for disabled revert to revision
i-just Mar 11, 2024
4a50089
compiled assets
i-just Mar 11, 2024
7fb8f0e
Merge branch '5.0' into feature/cms-1091-ability-to-move-entries-to-a…
brandonkelly Mar 11, 2024
f8713d1
bug fix!
i-just Mar 13, 2024
ca78bca
Merge branch '5.0' into feature/cms-1091-ability-to-move-entries-to-a…
i-just Mar 13, 2024
fe40e8e
aria attrs
i-just Mar 13, 2024
2a59362
lighter focus ring for dark elements
i-just Mar 13, 2024
9fe0ac0
check element is movable ahead of time
i-just Mar 14, 2024
35824ce
Merge branch '5.0' into feature/cms-1091-ability-to-move-entries-to-a…
i-just Mar 14, 2024
c9597b2
allow drafts too
i-just Mar 14, 2024
e82fbb3
bug fix for nested elements
i-just Mar 14, 2024
aa7f70a
reorganise js a bit
i-just Mar 14, 2024
e59e36c
maybe hooked up status messages
i-just Mar 14, 2024
a354d18
temp
i-just Mar 14, 2024
8200227
Revert "temp"
i-just Mar 14, 2024
01c63b7
keep the ability to add data attr to the button anyway
i-just Mar 14, 2024
ac9b8b8
add live region to modals & use in entry mover
i-just Mar 14, 2024
747877b
focus ring adjustments
i-just Mar 15, 2024
f2490fe
Merge branch '5.0' into feature/cms-1091-ability-to-move-entries-to-a…
i-just Mar 15, 2024
ddeba56
Merge branch '5.0' of github.com:craftcms/cms into feature/cms-1091-a…
brianjhanson Mar 19, 2024
2a8fa12
Update tooltip labels
brianjhanson Mar 19, 2024
8300b3e
Fix tooltips for sidebar jobs
brianjhanson Mar 19, 2024
951751b
Merge branch '5.0' into feature/cms-1091-ability-to-move-entries-to-a…
brandonkelly Mar 19, 2024
7e6b31d
build
brandonkelly Mar 19, 2024
6320e9f
"Move to…"
brandonkelly Mar 19, 2024
2a92bac
Message tweaks
brandonkelly Mar 19, 2024
952073e
Merge branch '5.1' into feature/cms-1091-ability-to-move-entries-to-a…
brandonkelly Mar 19, 2024
f86e782
different way of showing incompatible entry type tooltip
i-just Mar 20, 2024
4a301fa
keep moving within Entry (not Element)
i-just Mar 26, 2024
62177ee
ability to add additional chip/card attrs from element type
i-just Mar 26, 2024
0c760ac
Merge branch '5.x' into feature/cms-1091-ability-to-move-entries-to-a…
brandonkelly Apr 20, 2024
f8bda27
Merge branch '5.1' into feature/cms-1091-ability-to-move-entries-to-a…
brandonkelly Apr 20, 2024
70bcc97
Set data-movable via htmlAttributes()
brandonkelly Apr 20, 2024
a1b1d82
Merge branch '5.1' into feature/cms-1091-ability-to-move-entries-to-a…
brandonkelly Apr 20, 2024
69be479
Cleanup
brandonkelly Apr 21, 2024
80dfbd3
Merge branch '5.3' of github.com:craftcms/cms into feature/cms-1091-a…
brianjhanson Jul 23, 2024
ae11df4
Update `@since` tags
brandonkelly Jul 23, 2024
41bb410
Show selectable section chips in the Move Entry modal
brandonkelly Jul 23, 2024
dcb2da5
Merge branch '5.3' into feature/cms-1091-ability-to-move-entries-to-a…
brandonkelly Jul 23, 2024
1cb646c
A11y improvements
brandonkelly Jul 23, 2024
fc32371
<fieldset> + move the spinner to the button
brandonkelly Jul 23, 2024
1cf2aae
Fix id attribute for heading, remove radiogroup role from fieldset
Jul 24, 2024
2eb8d9e
Merge branch '5.3' into feature/cms-1091-ability-to-move-entries-to-a…
brandonkelly Jul 24, 2024
441db30
Cleanup
brandonkelly Jul 24, 2024
e386cfc
Release notes
brandonkelly Jul 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Content Management
- Added the “Link” field type, which replaces “URL”, and can store URLs, `mailto` and `tel` URIs, and entry/asset/category relations. ([#15251](https://github.com/craftcms/cms/pull/15251), [#15400](https://github.com/craftcms/cms/pull/15400))
- Added the ability to move entries between sections that allow the same entry type, via a new “Move to…” bulk action. ([#8153](https://github.com/craftcms/cms/discussions/8153), [#14541](https://github.com/craftcms/cms/pull/14541))
- Entry and category conditions now have a “Has Descendants” rule. ([#15276](https://github.com/craftcms/cms/discussions/15276))
- “Replace file” actions now display success notices on complete. ([#15217](https://github.com/craftcms/cms/issues/15217))
- Double-clicking on folders within asset indexes and folder selection modals now navigates the index/modal into the folder. ([#15238](https://github.com/craftcms/cms/discussions/15238))
Expand All @@ -16,6 +17,7 @@
- The notification heading is no longer read to screen readers when no notifications are active. ([#15294](https://github.com/craftcms/cms/pull/15294))
- The login modal that appears once a user’s session has ended now has a `lang` attribute, in case it differs from the user’s preferred language.
- Improved the focus ring styling for dark buttons. ([#15364](https://github.com/craftcms/cms/pull/15364))
- Single-select element selection modals now assign `role="radio"` to listed elements’ checkboxes.

### Administration
- Relation fields are now multi-instance. ([#15400](https://github.com/craftcms/cms/pull/15400))
Expand All @@ -39,7 +41,10 @@
- Added `craft\base\RelationFieldInterface`. ([#15400](https://github.com/craftcms/cms/pull/15400))
- Added `craft\base\RelationFieldTrait`. ([#15400](https://github.com/craftcms/cms/pull/15400))
- Added `craft\config\GeneralConfig::addAlias()`. ([#15346](https://github.com/craftcms/cms/pull/15346))
- Added `craft\elements\Entry::isEntryTypeCompatible()`.
- Added `craft\elements\actions\MoveToSection`.
- Added `craft\events\DefineShowFieldLayoutComponentInFormEvent`. ([#15260](https://github.com/craftcms/cms/issues/15260))
- Added `craft\events\MoveEntryEvent`.
- Added `craft\fields\Link`.
- Added `craft\fields\data\LinkData`.
- Added `craft\fields\linktypes\Asset`.
Expand All @@ -50,6 +55,10 @@
- Added `craft\fields\linktypes\Email`.
- Added `craft\fields\linktypes\Phone`.
- Added `craft\fields\linktypes\Url`.
- Added `craft\services\Elements::ensureBulkOp()`.
- Added `craft\services\Entries::EVENT_AFTER_MOVE_TO_SECTION`.
- Added `craft\services\Entries::EVENT_BEFORE_MOVE_TO_SECTION`.
- Added `craft\services\Entries::moveEntryToSection()`.
- `craft\helpers\DateTimeHelper::toIso8601()` now has a `$setToUtc` argument.
- `craft\helpers\UrlHelper::cpUrl()` now returns URLs based on the primary site’s base URL (if it has one), for console requests if the `baseCpUrl` config setting isn’t set, and the `@web` alias wasn’t explicitly defined. ([#15374](https://github.com/craftcms/cms/issues/15374))
- Deprecated `craft\fields\BaseRelationField::$localizeRelations`.
Expand Down
11 changes: 9 additions & 2 deletions packages/craftcms-sass/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,15 @@ $menuBorderRadius: $mediumBorderRadius;
}

@mixin light-focus-ring() {
--focus-ring: 0 0 0 1px hsl(var(--light-focus-hsl)),
0 0 0 3px hsla(var(--light-focus-hsl), 0.7);
--focus-ring: 0 0 0 1px
hsl(#{hue($blue200)}, #{saturation($blue200)}, #{lightness($blue200)}),
0 0 0 3px hsla(var(--light-focus-hsl), 1);
}

@mixin dark-btn-light-bg-focus-ring() {
--focus-ring: 0 0 0 1px
hsl(#{hue($blue200)}, #{saturation($blue200)}, #{lightness($blue200)}),
0 0 0 3px hsla(var(--dark-focus-hsl), 0.8);
}

@mixin custom-color-focus-ring($primary, $secondary: null) {
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/ElementsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ private function _additionalButtons(
// Apply draft
if ($isDraft && !$isCurrent && $canSave && $canSaveCanonical) {
$components[] = Html::button(Craft::t('app', 'Apply draft'), [
'class' => ['btn', 'secondary', 'formsubmit'],
'class' => ['btn', 'secondary', 'formsubmit', 'tooltip-draft-btn'],
'data' => [
'action' => 'elements/apply-draft',
'redirect' => Craft::$app->getSecurity()->hashData('{cpEditUrl}'),
Expand All @@ -904,7 +904,7 @@ private function _additionalButtons(
Html::hiddenInput('elementId', (string)$canonical->id) .
Html::hiddenInput('revisionId', (string)$element->revisionId) .
Html::button(Craft::t('app', 'Revert content from this revision'), [
'class' => ['btn', 'formsubmit'],
'class' => ['btn', 'formsubmit', 'revision-draft-btn'],
]) .
Html::endForm();
}
Expand Down
145 changes: 145 additions & 0 deletions src/controllers/EntriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

use Craft;
use craft\base\Element;
use craft\db\Query;
use craft\db\Table;
use craft\elements\Entry;
use craft\enums\PropagationMethod;
use craft\errors\InvalidElementException;
Expand All @@ -18,9 +20,12 @@
use craft\helpers\Cp;
use craft\helpers\DateTimeHelper;
use craft\helpers\ElementHelper;
use craft\helpers\Html;
use craft\helpers\UrlHelper;
use craft\models\Section;
use craft\models\Section_SiteSettings;
use Exception;
use Illuminate\Support\Collection;
use Throwable;
use yii\web\BadRequestHttpException;
use yii\web\ForbiddenHttpException;
Expand Down Expand Up @@ -383,6 +388,146 @@ public function actionSaveEntry(bool $duplicate = false): ?Response
);
}

/**
* Get sections that we can move selected entries to and return the list html for the modal.
*
* @return Response
* @throws BadRequestHttpException
* @since 5.3.0
*/
public function actionMoveToSectionModalData(): Response
{
$this->requireCpRequest();

$entryIds = $this->request->getRequiredParam('entryIds');
$siteId = $this->request->getRequiredParam('siteId');
$currentSectionUid = $this->request->getRequiredParam('currentSectionUid');

// get entry types by entry IDs
$entryTypes = (new Query())
->select(['et.id'])
->from(['et' => Table::ENTRYTYPES])
->leftJoin(['e' => Table::ENTRIES], '[[e.typeId]] = [[et.id]]')
->where(['in', 'e.id', $entryIds])
->distinct()
->all();
$entryTypes = array_map(fn($item) => $item['id'], $entryTypes);

$user = Craft::$app->getUser()->getIdentity();

// filter all sections to those that have all the entry types we just got
$compatibleSections = Collection::make(Craft::$app->getEntries()->getEditableSections())
->filter(function(Section $section) use ($entryTypes, $siteId, $currentSectionUid, $user) {
// don't allow moving to a single section
if ($section->type === Section::TYPE_SINGLE) {
return false;
}

// limit to the sections available for the site we're doing this for
if (!isset($section->getSiteSettings()[$siteId])) {
return false;
}

// exclude section we started this move from
if ($currentSectionUid !== null && $section->uid === $currentSectionUid) {
return false;
}

// ensure person can save entries in the section we're moving to
if (!$user->can("saveEntries:$section->uid")) {
return false;
}


$sectionEntryTypes = array_map(fn($et) => $et->id, $section->entryTypes);

return !empty(array_intersect($entryTypes, $sectionEntryTypes));
})
->sortBy(fn(Section $section) => $section->getUiLabel())
->all();

if (empty($compatibleSections)) {
$listHtml = Html::tag(
'p',
Craft::t('app', 'Couldn’t find any sections that all selected elements could be moved to.'),
['class' => 'zilch']
);
} else {
$listHtml = '';
foreach ($compatibleSections as $section) {
$listHtml .= Cp::chipHtml($section, [
'selectable' => true,
'class' => 'fullwidth',
]);
}
}

return $this->asJson(['listHtml' => $listHtml]);
}

/**
* Move entries to a new section.
*
* @return Response
* @throws BadRequestHttpException
* @since 5.3.0
*/
public function actionMoveToSection(): Response
{
$this->requireCpRequest();

$sectionId = $this->request->getRequiredParam('sectionId');
$section = Craft::$app->getEntries()->getSectionById($sectionId);
if (!$section) {
throw new BadRequestHttpException('Cannot find the section to move the entries to.');
}

$entryIds = $this->request->getRequiredParam('entryIds');
if (empty($entryIds)) {
throw new BadRequestHttpException('entryIds cannot be empty.');
}
$entries = Entry::find()
->id($entryIds)
->status(null)
->drafts(null)
->all();
if (empty($entries)) {
throw new BadRequestHttpException('Cannot find the entries to move to the new section.');
}

$errors = [];
foreach ($entries as $entry) {
try {
Craft::$app->getEntries()->moveEntryToSection($entry, $section);
} catch (Exception|InvalidElementException|UnsupportedSiteException $e) {
Craft::error('Could not delete move entry to a different section: ' . $e->getMessage(), __METHOD__);
$errors[] = $e->getMessage();
}
}

if (!empty($errors)) {
if (count($errors) === count($entries)) {
return $this->asFailure(Craft::t(
'app',
'Couldn’t move entries to the “{name}” section.',
['name' => $section->name]
));
}

return $this->asSuccess(Craft::t(
'app',
'Some entries have been moved to the “{name}” section.',
['name' => $section->name]
));
}

return $this->asSuccess(Craft::t(
'app',
'Entries have been moved to the “{name}” section.',
['name' => $section->name]
));
}

/**
* Fetches or creates an Entry.
*
Expand Down
Loading
Loading