Skip to content
Merged

Dev #3336

Show file tree
Hide file tree
Changes from all 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
22 changes: 21 additions & 1 deletion app/Nova/GirlsInDigitalFaqItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ public static function uriKey(): string
/** Only manage FAQ items from the Girls in Digital page (HasMany). */
public static $displayInNavigation = false;

public static function authorizedToCreate(Request $request): bool
{
return true;
}

public static function authorizedToUpdate(Request $request, $model): bool
{
return true;
}

public static function authorizedToDelete(Request $request, $model): bool
{
return true;
}

private static function localesSorted(): array
{
$locales = config('app.locales', ['en']);
Expand Down Expand Up @@ -95,7 +110,12 @@ public function fields(Request $request): array
$fields = [
ID::make()->onlyOnForms(),
\Laravel\Nova\Fields\Hidden::make('Page', 'page_id')
->default(fn ($request) => $request->viaResourceId ?? 1),
->default(function ($request) {
if ($request instanceof \Laravel\Nova\Http\Requests\NovaRequest && method_exists($request, 'viaResourceId')) {
return $request->viaResourceId() ?? 1;
}
return $request->query('viaResourceId', 1);
}),
Text::make('Question (default)', 'question')->nullable()->rules('nullable', 'string'),
Trix::make('Answer (default)', 'answer')->nullable()->help('Use the toolbar for bold, italic, links, lists.'),
\Laravel\Nova\Fields\Number::make('Order', 'position')->min(0)->help('Lower numbers appear first.'),
Expand Down
30 changes: 17 additions & 13 deletions app/Nova/GirlsInDigitalPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ private function buildFields(Request $request): array

Panel::make('Section toggles', [
\Laravel\Nova\Fields\Heading::make('Turn on "Use dynamic content" in each section below to show DB content on the front.'),
])->collapsable(),
])->collapsable()->collapsedByDefault(),

Panel::make('Hero', $heroFields)->collapsable()->collapsedByDefault(),

Expand Down Expand Up @@ -328,18 +328,22 @@ public static function afterSave(NovaRequest $request, $model): void
$allKeys = self::allButtonKeys();
$positionMap = array_flip($allKeys);
foreach ($updates as $key => $fields) {
$existing = GirlsInDigitalButton::where('page_id', $model->id)->where('key', $key)->first();
$payload = [
'label' => array_key_exists('label', $fields) ? (string) $fields['label'] : ($existing?->label ?? ''),
'url' => array_key_exists('url', $fields) ? (string) $fields['url'] : ($existing?->url ?? '#'),
'open_new_tab' => array_key_exists('open_new_tab', $fields) ? (bool) $fields['open_new_tab'] : ($existing?->open_new_tab ?? false),
'enabled' => array_key_exists('enabled', $fields) ? (bool) $fields['enabled'] : ($existing?->enabled ?? true),
'position' => $positionMap[$key] ?? $existing?->position ?? 0,
];
GirlsInDigitalButton::updateOrCreate(
['page_id' => $model->id, 'key' => $key],
$payload
);
try {
$existing = GirlsInDigitalButton::where('page_id', $model->id)->where('key', $key)->first();
$payload = [
'label' => array_key_exists('label', $fields) ? (string) $fields['label'] : ($existing?->label ?? ''),
'url' => array_key_exists('url', $fields) ? (string) $fields['url'] : ($existing?->url ?? '#'),
'open_new_tab' => array_key_exists('open_new_tab', $fields) ? (bool) $fields['open_new_tab'] : ($existing?->open_new_tab ?? false),
'enabled' => array_key_exists('enabled', $fields) ? (bool) $fields['enabled'] : ($existing?->enabled ?? true),
'position' => $positionMap[$key] ?? $existing?->position ?? 0,
];
GirlsInDigitalButton::updateOrCreate(
['page_id' => $model->id, 'key' => $key],
$payload
);
} catch (\Throwable $e) {
report($e);
}
}
unset($model->_button_updates);
} catch (\Throwable $e) {
Expand Down
Loading