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

[5.x] Run actions from publish forms #6375

Merged
merged 72 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
1c644d8
Run actions from the edit entry view
jacksleight Jul 25, 2022
de72777
WIP
jacksleight Nov 18, 2022
8611bf8
WIP
jacksleight Nov 19, 2022
7b93bfb
Merge branch 'statamic:3.3' into actions-detail
jacksleight Dec 1, 2022
e496f8e
Implement redirect on entry duplication
jacksleight Dec 1, 2022
d2f11f1
Merge branch '3.4' into actions-detail
jacksleight Feb 1, 2023
1139a41
Merge branch '4.x' into actions-detail
jacksleight May 10, 2023
0729391
Run tests again
jacksleight May 12, 2023
10a8179
Merge branch '4.x' into actions-detail
jasonvarga Sep 5, 2023
eb9332c
move actions after edit blueprint
jasonvarga Sep 5, 2023
17aaed9
Merge branch '4.x' into actions-detail
jacksleight Dec 15, 2023
c74662f
Update duplicate entry action
jacksleight Dec 15, 2023
d007a02
Update duplicate entry action
jacksleight Dec 15, 2023
1c7940f
Rename mixin to HasActions
jacksleight Dec 15, 2023
2a62a98
Reanme listActions to itemActions
jacksleight Dec 15, 2023
6a782e1
Rename publish_form context key to view
jacksleight Dec 15, 2023
3b1b1e7
Rename publish_form context key to view
jacksleight Dec 15, 2023
42f80b7
Add view key to all list contexts
jacksleight Dec 15, 2023
099e34e
Rename listActionUrl
jacksleight Dec 15, 2023
6136d19
Add blank callback method
jacksleight Dec 15, 2023
3094e39
Move method
jacksleight Dec 15, 2023
74f640c
Terms support (and some other tweaks)
jacksleight Dec 15, 2023
bd93be4
Support users
jacksleight Dec 15, 2023
a641a44
Rename callback method
jacksleight Dec 18, 2023
8233b74
Refactor a bunch of thingd
jacksleight Dec 18, 2023
f7f74a7
Assets support
jacksleight Dec 18, 2023
25ea12e
Rename filtered actions list
jacksleight Dec 18, 2023
d73aa2a
Ensure view context is always set
jacksleight Dec 19, 2023
a02baff
User delete redirect
jacksleight Dec 19, 2023
d4351d8
Fix error creating new entries and terms
jacksleight Dec 19, 2023
090ef40
Reanme initialReferenceId to just id
jacksleight Dec 19, 2023
fc11080
Remove duplicate callback call
jacksleight Dec 19, 2023
42ccbdb
Refactor user extractFromFields
jacksleight Dec 19, 2023
bc76eaf
Fix whitespace
jacksleight Dec 19, 2023
42287d1
Fix test
jacksleight Dec 19, 2023
8bd45b9
Ensure actions always have view context param
jacksleight Dec 19, 2023
eb0fc4e
Rename menuActions to actionsMenu
jacksleight Dec 19, 2023
9f8091b
Fix whitespace
jacksleight Dec 19, 2023
1c89ed0
Also hide dividers if they're last
jacksleight Dec 19, 2023
de03616
Also hide dividers if they're last
jacksleight Dec 19, 2023
e380cd1
That shouldn't be there
jacksleight Jan 12, 2024
46a5927
Merge branch '5.x' into actions-detail
jacksleight May 10, 2024
dee630f
Merge branch '5.x' into actions-detail
jacksleight May 14, 2024
7b88dd3
Update title watcher
jacksleight May 14, 2024
931456f
Remove copy asset URL action from menu
jacksleight May 16, 2024
2327363
Merge branch '5.x' into actions-detail
jasonvarga May 16, 2024
c5fa2af
use trait
jasonvarga May 16, 2024
3fc43bd
unreachable
jasonvarga May 16, 2024
84d5b2e
visibility
jasonvarga May 16, 2024
617cb14
Providing view of list is unnecessary since its the default in the Ac…
jasonvarga May 16, 2024
67396e1
nitpick
jasonvarga May 16, 2024
9f2d5be
abstract
jasonvarga May 16, 2024
fea9ceb
Revert and use arr::get instead
jasonvarga May 16, 2024
1a877af
Exclude entry actions in the actions rather than in vue.
jasonvarga May 17, 2024
36e6234
Send back data in a consistent way to saving
jasonvarga May 17, 2024
5b56433
The actions werent being updated ...
jasonvarga May 17, 2024
735322b
Even though we aren't showing the publish actions, update it anyway t…
jasonvarga May 17, 2024
3cb96cc
use id from values
jasonvarga May 17, 2024
20310b3
extract trait
jasonvarga May 17, 2024
19f2816
use term resourse for consistency
jasonvarga May 17, 2024
2330504
extract trait
jasonvarga May 17, 2024
16d582d
send ids consistent with the other forms
jasonvarga May 17, 2024
ce01561
exclude user actions in php
jasonvarga May 17, 2024
cc59cea
grab id from values
jasonvarga May 17, 2024
c329959
missed from 617cb14a
jasonvarga May 17, 2024
625050e
nitpick
jasonvarga May 17, 2024
b74ce3c
context
jasonvarga May 17, 2024
82e68f4
This must have accidentally been re-added in a merge. It was removed …
jasonvarga May 17, 2024
5eed6b4
Actions will show a dirty state warning ...
jasonvarga May 17, 2024
5e8bf68
Ability to disable the dirty warning text when it doesn't matter, lik…
jasonvarga May 17, 2024
eda9a0f
Make impersonate confirmable with appropriate messaging which makes m…
jasonvarga May 17, 2024
4305646
Make it work on terms and users
jasonvarga May 17, 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
17 changes: 17 additions & 0 deletions resources/js/components/entries/PublishForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
</h1>

<dropdown-list class="mr-4" v-if="canEditBlueprint">
jasonvarga marked this conversation as resolved.
Show resolved Hide resolved
<data-list-inline-actions
:item="values.id"
:url="listActionUrl"
:actions="listActions"
@started="actionStarted"
@completed="actionCompleted"
/>
<dropdown-item :text="__('Edit Blueprint')" :redirect="actions.editBlueprint" />
</dropdown-list>

Expand Down Expand Up @@ -294,12 +301,14 @@ import SaveButtonOptions from '../publish/SaveButtonOptions.vue';
import RevisionHistory from '../revision-history/History.vue';
import HasPreferences from '../data-list/HasPreferences';
import HasHiddenFields from '../publish/HasHiddenFields';
import HasListActions from '../publish/HasListActions';

export default {

mixins: [
HasPreferences,
HasHiddenFields,
HasListActions,
],

components: {
Expand Down Expand Up @@ -341,11 +350,14 @@ export default {
collectionHasRoutes: Boolean,
previewTargets: Array,
autosaveInterval: Number,
initialListActions: Array,
listActionUrl: String,
},

data() {
return {
actions: this.initialActions,
listActions: this.initialListActions,
saving: false,
localizing: false,
trackDirtyState: true,
Expand Down Expand Up @@ -491,6 +503,11 @@ export default {

methods: {

afterListActionSuccessfullyCompleted(response) {
this.values = { ...this.values, ...response.data.values };
this.listActions = response.data.listActions;
},

clearErrors() {
this.error = null;
this.errors = {};
Expand Down
29 changes: 29 additions & 0 deletions resources/js/components/publish/HasListActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export default {

methods: {

actionStarted() {
this.saving = true;
},

actionCompleted(successful=null, response) {
this.saving = false;

if (successful === false) return;

this.$events.$emit('reset-action-modals');

if (response.callback) {
Statamic.$callbacks.call(response.callback[0], ...response.callback.slice(1));
}

if (response.message !== false) {
this.$toast.success(response.message || __("Action completed"));
}

this.afterListActionSuccessfullyCompleted(response);
},

}

}
2 changes: 2 additions & 0 deletions resources/views/entries/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
listing-url="{{ cp_route('collections.show', $collection) }}"
:preview-targets="{{ json_encode($previewTargets) }}"
:autosave-interval="{{ json_encode($autosaveInterval) }}"
:initial-list-actions="{{ json_encode($listActions) }}"
list-action-url="{{ cp_route('collections.entries.actions.run', $collection) }}"
></entry-publish-form>

@endsection
10 changes: 10 additions & 0 deletions src/Actions/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,14 @@ public function run($items, $values)
{
$items->each->delete();
}

public function redirect($items, $values)
{
if (! array_get($this->context, 'publish_form', false)) {
return;
}

// Also need to handle terms etc, todo
return cp_route('collections.show', $items->first()->collection()->handle());
}
}
15 changes: 14 additions & 1 deletion src/Actions/DuplicateEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

class DuplicateEntry extends Action
{
protected $entries;

public static function title()
{
return __('Duplicate');
Expand All @@ -21,7 +23,7 @@ public function visibleTo($item)

public function run($items, $values)
{
$items->each(function (Entry $original) {
$this->entries = $items->map(function (Entry $original) {
$originalParent = $this->getEntryParentFromStructure($original);
[$title, $slug] = $this->generateTitleAndSlug($original);

Expand Down Expand Up @@ -54,9 +56,20 @@ public function run($items, $values)
->appendTo($originalParent->id(), $entry)
->save();
}

return $entry;
});
}

public function redirect($items, $values)
{
if (! array_get($this->context, 'publish_form', false)) {
return;
}

return $this->entries->first()->editUrl();
}

protected function getEntryParentFromStructure(Entry $entry)
{
if (! $entry->structure()) {
Expand Down
16 changes: 14 additions & 2 deletions src/Http/Controllers/CP/ActionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ public function run(Request $request)
}

if (is_string($response)) {
return ['message' => $response];
$response = ['message' => $response];
}

return $response ?: [];
$response = $response ?: [];

if (array_get($context, 'publish_form', false)) {
$response['data'] = $this->getItemData($items->first(), $context);
}

return $response;
}

public function bulkActions(Request $request)
Expand All @@ -65,4 +71,10 @@ public function bulkActions(Request $request)
}

abstract protected function getSelectedItems($items, $context);

// Should be abstract todo
protected function getItemData($item, $context)
{
return [];
}
}
2 changes: 2 additions & 0 deletions src/Http/Controllers/CP/Collections/EntriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Statamic\Contracts\Entries\Entry as EntryContract;
use Statamic\CP\Breadcrumbs;
use Statamic\Exceptions\BlueprintNotFoundException;
use Statamic\Facades\Action;
use Statamic\Facades\Asset;
use Statamic\Facades\Entry;
use Statamic\Facades\Site;
Expand Down Expand Up @@ -112,6 +113,7 @@ public function edit(Request $request, $collection, $entry)
'createRevision' => $entry->createRevisionUrl(),
'editBlueprint' => cp_route('collections.blueprints.edit', [$collection, $blueprint]),
],
'listActions' => Action::for($entry, ['collection' => $collection->handle(), 'publish_form' => true]),
'values' => array_merge($values, ['id' => $entry->id()]),
'meta' => $meta,
'collection' => $collection->handle(),
Expand Down
51 changes: 51 additions & 0 deletions src/Http/Controllers/CP/Collections/EntryActionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Statamic\Http\Controllers\CP\Collections;

use Statamic\Facades\Action;
use Statamic\Facades\Entry;
use Statamic\Http\Controllers\CP\ActionController;

Expand All @@ -13,4 +14,54 @@ protected function getSelectedItems($items, $context)
return Entry::find($item);
});
}

protected function getItemData($entry, $context)
{
$collection = $entry->collection();

$blueprint = $entry->blueprint();

[$values] = $this->extractFromFields($entry, $blueprint);

return [
'values' => $values,
'listActions' => Action::for($entry, $context),
];
}

protected function extractFromFields($entry, $blueprint)
{
// The values should only be data merged with the origin data.
// We don't want injected collection values, which $entry->values() would have given us.
$target = $entry;
$values = $target->data();
while ($target->hasOrigin()) {
$target = $target->origin();
$values = $target->data()->merge($values);
}
$values = $values->all();

if ($entry->hasStructure()) {
$values['parent'] = array_filter([optional($entry->parent())->id()]);
}

if ($entry->collection()->dated()) {
$datetime = substr($entry->date()->toDateTimeString(), 0, 16);
$datetime = ($entry->hasTime()) ? $datetime : substr($datetime, 0, 10);
$values['date'] = $datetime;
}

$fields = $blueprint
->fields()
->addValues($values)
->preProcess();

$values = $fields->values()->merge([
'title' => $entry->value('title'),
'slug' => $entry->slug(),
'published' => $entry->published(),
]);

return [$values->all(), $fields->meta()];
}
}