Skip to content

Firefly III: a personal finances manager

Add fallback for empty front page account preferences thing.

James Cole7c56c14fa0bd
diff --git a/app/Http/Controllers/PreferencesController.php b/app/Http/Controllers/PreferencesController.php
index b5e3dc07b6..c0fb2157f4 100644
--- a/app/Http/Controllers/PreferencesController.php
+++ b/app/Http/Controllers/PreferencesController.php
@@ -58,10 +58,11 @@ class PreferencesController extends Controller
public function index(AccountRepositoryInterface $repository)
{
$accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
+ $accountIds = $accounts->pluck('id')->toArray();
$viewRangePref = app('preferences')->get('viewRange', '1M');
/** @noinspection NullPointerExceptionInspection */
$viewRange = $viewRangePref->data;
- $frontPageAccounts = app('preferences')->get('frontPageAccounts', []);
+ $frontPageAccounts = app('preferences')->get('frontPageAccounts', $accountIds);
$language = app('preferences')->get('language', config('firefly.default_language', 'en_US'))->data;
$listPageSize = app('preferences')->get('listPageSize', 50)->data;
$customFiscalYear = app('preferences')->get('customFiscalYear', 0)->data;
@@ -69,6 +70,12 @@ class PreferencesController extends Controller
$fiscalYearStart = date('Y') . '-' . $fiscalYearStartStr;
$tjOptionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data;
+ // an important fallback is that the frontPageAccount array gets refilled automatically
+ // when it turns up empty.
+ if (\count($frontPageAccounts->data) === 0) {
+ $frontPageAccounts = $accountIds;
+ }
+
return view(
'preferences.index',
compact(
@@ -98,7 +105,7 @@ class PreferencesController extends Controller
{
// front page accounts
$frontPageAccounts = [];
- if (\is_array($request->get('frontPageAccounts'))) {
+ if (\is_array($request->get('frontPageAccounts')) && \count($request->get('frontPageAccounts')) > 0) {
foreach ($request->get('frontPageAccounts') as $id) {
$frontPageAccounts[] = (int)$id;
}