drago-ex / project-settings
Individual settings for the application.
Package info
github.com/drago-ex/project-settings
Type:drago-tools-resource
pkg:composer/drago-ex/project-settings
Requires
- php: >=8.3 <9
- drago-ex/application: ^5.0
- drago-ex/database: ^5.0
- drago-ex/form: ^4.0
- drago-ex/migration: ^1.0
- drago-ex/permission: ^2.0
- drago-ex/project-backend: ^1.0
- drago-ex/project-backend-ui: ^1.0
- drago-ex/translator: ^4.0.1
- nette/application: ^3.0
- nette/di: ^3.0
- tracy/tracy: ^2.0
Requires (Dev)
- drago-ex/project-tools: ^1.0
- nette/tester: ^2.5
- phpstan/phpstan-nette: ^2.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Settings of the application stored in the database, such as the website name and description, edited in the administration and available in every template.
Requirements
- PHP >= 8.3, < 9
- MySQL or MariaDB
- Drago Project
Installation
composer require drago-ex/project-settings
Project Tools copies the files of the package into the project,
where you adapt them. It also replaces the brand of Drago UI (Accessory/Widget/@brand.latte,
used by all layouts) once with one that shows the website setting.
Database
The migration creates the table settings (name and value), empty:
php vendor/bin/migration db:migrate --packages
Then add the website name and description:
INSERT INTO settings (name, value) VALUES ('website', 'My website'), ('description', 'What the website is about');
Warning
Without these rows the settings page of the administration shows an empty form: it edits only the settings that exist and does not create them, so the name and the description cannot be set there.
bin/project-setup of Drago Project does both steps for you: it runs the migration and, in a terminal, asks for the
name and the description.
Administration
{link :Backend:Settings:}
The menu item comes from Backend/Settings/SettingsMenu.php (a MenuProvider) of
Drago UI. The form has a field for every row of settings,
labelled by its name; it does not create rows (see Database). Add another setting as a row, e.g. by an
INSERT in a migration of your project (migrations/), and the translation of its name to
Backend/Settings/Translate/cs.neon.
Use in Presenters and Templates
The brand of every layout reads the website name from the settings, so add the trait to BasePresenter, which
all presenters extend (Project Preset installs both files below
already wired):
use App\Core\Settings\SettingsRequire; use Nette\Application\UI\Presenter; abstract class BasePresenter extends Presenter { use SettingsRequire; }
and the property to BaseTemplate (the trait sets it before rendering; without it PHP reports a dynamic property):
use App\Core\Settings\Settings; use Drago\Application\UI\ExtraTemplate; abstract class BaseTemplate extends ExtraTemplate { public Settings $settings; }
{varType App\Core\Settings\Settings $settings} {$settings->get('website')} {$settings->get('description')}
Templates read the settings directly; reading a setting without its row throws an exception.
Permissions
The rules are in Backend/Settings/acl.neon: the resource Backend:Settings, for the administrator only, with
the privileges view (the page) and edit (saving the settings).
Project Permission can give them to other roles.
The same file describes the privileges (permissionLabels) for the permissions page of Project Permission.