Skip to content

Show/hide slug field option #13905

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

Merged
merged 9 commits into from
Dec 28, 2023
Prev Previous commit
Next Next commit
don't allow setting slug via gql is showSlugField is false
  • Loading branch information
i-just committed Nov 3, 2023
commit 561f55e2c543c3ec3910bf2645c85cebbf88c32f
13 changes: 13 additions & 0 deletions src/gql/resolvers/mutations/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ public function saveEntry(mixed $source, array $arguments, mixed $context, Resol
unset($arguments['enabled']);
}

// If saving an entry the slug is provided, check if we should allow changing it.
if (array_key_exists('slug', $arguments)) {
try {
$showSlugField = $entry->showSlugField();
} catch (InvalidConfigException) {
$showSlugField = true;
}

if (!$showSlugField) {
unset($arguments['slug']);
}
}

// TODO refactor saving draft to its own method in 4.0
if (array_key_exists('draftId', $arguments)) {
$entry->setScenario(Element::SCENARIO_ESSENTIALS);
Expand Down