-
Notifications
You must be signed in to change notification settings - Fork 35
Closed
Description
Pseudo pull request I guess - inside of the Slug field:
The showCustomizeButton method doesn't exist.
/**
* Set whether or not the customize button is visible / used to enable slug editing.
*
* @param boolean $showCustomizeButton
* @return $this
*/
public function showCustomizeButton($showCustomizeButton)
{
$this->showCustomizeButton = $showCustomizeButton;
$this->customizeButtonExplicitlySet = true;
return $this;
}
Adding new public variable at the top:
public $customizeButtonExplicitlySet = false;
Then adjust one line inside of jsonSerialize():
/**
* Prepare the element for JSON serialization.
*
* @return array<string, mixed>
*/
public function jsonSerialize(): array
{
$request = app(NovaRequest::class);
if ($request->isUpdateOrUpdateAttachedRequest()) {
$this->readonly();
+ if($this->customizeButtonExplicitlySet === false) $this->showCustomizeButton = true;
}
return array_merge([
'updating' => $request->isUpdateOrUpdateAttachedRequest(),
'from' => $this->from instanceof Field ? $this->from->attribute : str_replace(' ', '_', Str::lower($this->from)),
'separator' => $this->separator,
'showCustomizeButton' => $this->showCustomizeButton,
], parent::jsonSerialize());
}
This will allow users to control whether or not the Customize button appears next to a slug, even in editing, based on the user's reasoning/criteria. In my instance I needed to admin-protect certain slugs.
$admin_protected_slugs = [
'about',
'contact'
];
...
Slug::make('Slug')->from('Title')->separator('-')
->showCustomizeButton(!(boolean)in_array($this->resource->slug, $admin_protected_slugs))
->withMeta($page_meta)->hideFromIndex()->sortable(),
Metadata
Metadata
Assignees
Labels
No labels