Skip to content

[5.x] Add a creating-entry hook to allow default values to be set #8643

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

Open
wants to merge 5 commits into
base: 5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
1 change: 1 addition & 0 deletions .phpunit.cache/test-results

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion src/Http/Controllers/CP/Collections/EntriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Validation\ValidationException;
use Statamic\Contracts\Entries\Entry as EntryContract;
use Statamic\CP\Breadcrumbs;
use Statamic\Events\EntryBlueprintFound;
use Statamic\Exceptions\BlueprintNotFoundException;
use Statamic\Facades\Action;
use Statamic\Facades\Asset;
Expand All @@ -21,10 +22,12 @@
use Statamic\Query\Scopes\Filters\Concerns\QueriesFilters;
use Statamic\Support\Arr;
use Statamic\Support\Str;
use Statamic\Support\Traits\Hookable;

class EntriesController extends CpController
{
use ExtractsFromEntryFields,
Hookable,
QueriesFilters;

public function index(FilteredRequest $request, $collection)
Expand Down Expand Up @@ -298,7 +301,11 @@ public function create(Request $request, $collection, $site)
$blueprint->ensureFieldHasConfig('author', ['visibility' => 'read_only']);
}

$values = Entry::make()->collection($collection)->values()->all();
$entry = Entry::make()->collection($collection);

$this->runHooks('creating-entry', $entry);

$values = $entry->values()->all();

if ($collection->hasStructure() && $request->parent) {
$values['parent'] = $request->parent;
Expand Down
Loading