[ * 'services' => Presets::services(['model' => App\Models\Service::class, 'feature' => 'services']), * 'projects' => Presets::projects(['model' => App\Models\Project::class, 'feature' => 'projects'], serviceModel: App\Models\Service::class), * ], * * Without `model` the records are kept in the package's own table. The field keys are the column names of the * usual site tables (`title`, `summary`, `is_active`, `sort_order`), so a site that has such tables points `model` at them. */ final class Presets { /** What the simple face says for each field of a preset, in plain words. */ private const SIMPLE = [ 'services' => [ 'title' => ['label' => 'Name of the service', 'help' => 'What you call it, for example "Roof extensions".'], 'summary' => ['label' => 'Short description', 'help' => 'One sentence that shows under the name.'], 'body' => ['label' => 'The full story', 'help' => 'What you do and how you work. This is the text on the page of this service.'], 'photo' => ['label' => 'Main photo'], 'points' => ['label' => 'What you do', 'help' => 'Short lines, one per line.'], 'faq' => ['label' => 'Questions people ask', 'help' => 'Add the questions you hear often, with your answer.'], 'is_active' => ['label' => 'Show this on my website'], ], 'projects' => [ 'title' => ['label' => 'Name of the job', 'help' => 'For example "New kitchen in a farmhouse".'], 'service_id' => ['label' => 'What kind of work was it?'], 'place' => ['label' => 'Town', 'help' => 'The town only, never the street.'], 'year' => ['label' => 'Year it was finished'], 'story' => ['label' => 'What happened', 'help' => 'A few sentences about the job. Leave an empty line between paragraphs.'], 'photo' => ['label' => 'Main photo'], 'photos_agreed' => ['label' => 'The customer said these photos may be on the website'], 'on_home' => ['label' => 'Show this on the home page'], 'is_active' => ['label' => 'Show this on my website'], ], 'testimonials' => [ 'name' => ['label' => 'Who said it'], 'role' => ['label' => 'Where they live or what they do', 'help' => 'For example "Utrecht" or "owner of a bakery".'], 'quote' => ['label' => 'What they said', 'help' => 'Their words, as they gave them.'], 'is_active' => ['label' => 'Show this on my website'], ], 'menu' => [ 'label' => ['label' => 'What the button says'], 'url' => ['label' => 'Where it goes', 'help' => 'A page of your website, like /contact, or a full web address.'], 'opens_new_tab' => ['label' => 'Open it in a new tab'], 'is_active' => ['label' => 'Show this on my website'], ], 'socials' => [ 'label' => ['label' => 'Name', 'help' => 'For example "Facebook".'], 'url' => ['label' => 'Web address of your page'], 'is_active' => ['label' => 'Show this on my website'], ], 'business' => [ 'name' => ['label' => 'Name of your business'], 'owner' => ['label' => 'Your first name', 'help' => 'Used on buttons such as "Call Alex".'], 'phone' => ['label' => 'Your phone number', 'help' => 'As you want people to read it. It shows on every page, and behind the Call button.'], 'whatsapp' => ['label' => 'Your WhatsApp number', 'help' => 'Leave it empty and there are no WhatsApp buttons on the website.'], 'email' => ['label' => 'Your mail address', 'help' => 'It is never printed on the website, so spammers cannot find it. A visitor gets it by pressing a button.'], 'street' => ['label' => 'Street and number'], 'kvk' => ['label' => 'Chamber of Commerce number'], 'vat' => ['label' => 'VAT number', 'help' => 'As on your invoices. Not sure? Leave it empty.'], 'opening_hours' => ['label' => 'When people can reach you', 'help' => 'One line per day or group of days, as you want it read.'], 'towns' => ['label' => 'Towns where you work', 'help' => 'One town per line.'], ], ]; /** What the simple face calls a list as a whole. */ private const SIMPLE_NAMES = [ 'testimonials' => ['label' => 'What customers say', 'singular' => 'Customer review'], 'projects' => ['label' => 'Our jobs', 'singular' => 'Job'], 'menu' => ['label' => 'Buttons at the top', 'singular' => 'Button'], 'socials' => ['label' => 'Your pages on other sites', 'singular' => 'Link'], 'business' => ['title' => 'About your business'], ]; /** @param array $override */ public static function services(array $override = []): array { return self::make('services', [ 'label' => 'Services', 'singular' => 'Service', 'hint' => 'What you do, each with a page of its own', 'columns' => ['title', 'summary', 'is_active'], 'order' => ['sort_order', 'asc'], 'fields' => [ 'title' => ['label' => 'Title', 'type' => 'text', 'required' => true], 'slug' => ['label' => 'Address', 'type' => 'slug', 'from' => 'title', 'required' => true], 'summary' => ['label' => 'One line for a card', 'type' => 'text', 'max' => 300], 'body' => ['label' => 'Text of the page', 'type' => 'markdown'], 'photo' => ['label' => 'Photo', 'type' => 'media'], 'gallery' => ['label' => 'More photos', 'type' => 'media_list', 'advanced' => true], 'points' => ['label' => 'What we do', 'type' => 'list', 'help' => 'Short lines.'], 'faq' => ['label' => 'Questions and answers', 'type' => 'repeater', 'items' => self::questionItems()], 'meta_description' => ['label' => 'Description for search engines', 'type' => 'text', 'max' => 300, 'advanced' => true], 'sort_order' => ['label' => 'Order', 'type' => 'number', 'default' => 0, 'advanced' => true], 'is_active' => ['label' => 'Shown on the site', 'type' => 'toggle', 'default' => true], ], ], $override); } /** * @param array $override * @param ?class-string $serviceModel the model of the services, to pick the kind of work a project belongs to */ public static function projects(array $override = [], ?string $serviceModel = null): array { $fields = [ 'title' => ['label' => 'Title', 'type' => 'text', 'required' => true], 'slug' => ['label' => 'Address', 'type' => 'slug', 'from' => 'title', 'required' => true], ]; if ($serviceModel !== null) { $fields['service_id'] = ['label' => 'Kind of work', 'type' => 'select', 'source' => ['model' => $serviceModel, 'label' => 'title', 'value' => 'id']]; } return self::make('projects', [ 'label' => 'Projects', 'singular' => 'Project', 'hint' => 'Finished jobs, with photos', 'columns' => ['title', 'place', 'year', 'is_active'], 'order' => ['sort_order', 'asc'], 'fields' => $fields + [ 'place' => ['label' => 'Town', 'type' => 'text', 'max' => 120, 'help' => 'The town only, never a street.'], 'year' => ['label' => 'Year', 'type' => 'number'], 'story' => ['label' => 'Story', 'type' => 'textarea', 'help' => 'A few sentences, paragraphs separated by a blank line.'], 'photo' => ['label' => 'Photo', 'type' => 'media'], 'gallery' => ['label' => 'More photos', 'type' => 'media_list', 'advanced' => true], 'before_photo' => ['label' => 'Photo before', 'type' => 'media', 'advanced' => true], 'after_photo' => ['label' => 'Photo after', 'type' => 'media', 'advanced' => true], 'photos_agreed' => ['label' => 'The customer agreed to these photos on the site', 'type' => 'toggle', 'default' => false], 'on_home' => ['label' => 'Show on the home page', 'type' => 'toggle', 'default' => false], 'sort_order' => ['label' => 'Order', 'type' => 'number', 'default' => 0, 'advanced' => true], 'is_active' => ['label' => 'Shown on the site', 'type' => 'toggle', 'default' => true], ], ], $override); } /** @param array $override */ public static function testimonials(array $override = []): array { return self::make('testimonials', [ 'label' => 'Reviews', 'singular' => 'Review', 'hint' => 'What customers say about you', 'columns' => ['name', 'role', 'is_active'], 'order' => ['sort_order', 'asc'], 'fields' => [ 'name' => ['label' => 'Name', 'type' => 'text', 'required' => true], 'role' => ['label' => 'Place or function', 'type' => 'text'], 'quote' => ['label' => 'What they said', 'type' => 'textarea', 'required' => true], 'photo' => ['label' => 'Photo', 'type' => 'media', 'advanced' => true], 'sort_order' => ['label' => 'Order', 'type' => 'number', 'default' => 0, 'advanced' => true], 'is_active' => ['label' => 'Shown on the site', 'type' => 'toggle', 'default' => true], ], ], $override); } /** * Work and projects of a person or a company, for a CV or "about" page: a title, role, period, a story, points, links and * the technology used. `type` says which kind of entry it is (`work` or `project`; the site may offer other kinds with * `$override['fields']['type']['options']`). * * @param array $override */ public static function experience(array $override = []): array { return self::make('experience', [ 'label' => 'Experience', 'singular' => 'Experience', 'hint' => 'Work and projects for the CV', 'columns' => ['title', 'type', 'period', 'is_active'], 'order' => ['sort_order', 'asc'], 'fields' => [ 'type' => ['label' => 'Kind', 'type' => 'select', 'required' => true, 'default' => 'work', 'options' => ['work' => 'Work', 'project' => 'Project']], 'title' => ['label' => 'Title', 'type' => 'text', 'required' => true], 'role' => ['label' => 'Role', 'type' => 'text'], 'period' => ['label' => 'Period', 'type' => 'text', 'max' => 60, 'help' => 'As it should be read, for example 2021 - now.'], 'summary' => ['label' => 'One line', 'type' => 'text'], 'story' => ['label' => 'Story', 'type' => 'textarea', 'help' => 'A few sentences, paragraphs separated by a blank line.'], 'bullets' => ['label' => 'Points', 'type' => 'list'], 'links' => ['label' => 'Links', 'type' => 'repeater', 'items' => ['label' => ['label' => 'Text', 'type' => 'text'], 'url' => ['label' => 'Address', 'type' => 'url']]], 'tech' => ['label' => 'Technology', 'type' => 'list'], 'on_cv' => ['label' => 'Show on the CV', 'type' => 'toggle', 'default' => true], 'sort_order' => ['label' => 'Order', 'type' => 'number', 'default' => 0, 'advanced' => true], 'is_active' => ['label' => 'Shown on the site', 'type' => 'toggle', 'default' => true], ], ], $override); } /** @param array $override */ public static function menu(array $override = []): array { return self::make('menu', [ 'label' => 'Menu', 'singular' => 'Menu item', 'hint' => 'The links at the top of the site', 'columns' => ['label', 'url', 'is_active'], 'order' => ['sort_order', 'asc'], 'fields' => [ 'label' => ['label' => 'Text', 'type' => 'text', 'required' => true], 'url' => ['label' => 'Address', 'type' => 'text', 'required' => true, 'help' => 'A page of your site (/contact) or a full address.'], 'opens_new_tab' => ['label' => 'Opens in a new tab', 'type' => 'toggle', 'default' => false], 'sort_order' => ['label' => 'Order', 'type' => 'number', 'default' => 0], 'is_active' => ['label' => 'Shown on the site', 'type' => 'toggle', 'default' => true], ], ], $override); } /** @param array $override */ public static function socials(array $override = []): array { return self::make('socials', [ 'label' => 'Social links', 'singular' => 'Link', 'hint' => 'Your pages on other sites', 'columns' => ['label', 'url', 'is_active'], 'order' => ['sort_order', 'asc'], 'fields' => [ 'label' => ['label' => 'Name', 'type' => 'text', 'required' => true], 'url' => ['label' => 'Address', 'type' => 'url', 'required' => true], 'icon' => ['label' => 'Icon', 'type' => 'text', 'advanced' => true], 'sort_order' => ['label' => 'Order', 'type' => 'number', 'default' => 0], 'is_active' => ['label' => 'Shown on the site', 'type' => 'toggle', 'default' => true], ], ], $override); } /** * The page "Business details" for `manager.pages.definitions['business']`: what the site says about the business in its * header, footer, contact page and legal pages. Entered once, read with `Page::contentFor('business')`. The address for * visitors and the address where requests are mailed to are not meant to be printed in a page. * * @param array $override `title` and `fields` (merged per field) * @return array{title: string, fields: array>} */ public static function business(array $override = []): array { return self::make('business', [ 'title' => 'Business details', 'fields' => [ 'name' => ['label' => 'Name of the business', 'type' => 'text'], 'owner' => ['label' => 'Owner', 'type' => 'text', 'help' => 'The first name is used on buttons such as "Call Alex".'], 'phone' => ['label' => 'Phone number', 'type' => 'text', 'help' => 'As it should be read, for example 06 12 34 56 78. Shown on every page.'], 'whatsapp' => ['label' => 'WhatsApp number', 'type' => 'text', 'help' => 'Leave empty to leave the WhatsApp buttons off the site.'], 'email' => ['label' => 'Mail address for visitors', 'type' => 'text', 'help' => 'Never printed in a page: a visitor gets it by pressing a button.'], 'street' => ['label' => 'Street and number', 'type' => 'text'], 'postcode' => ['label' => 'Postcode', 'type' => 'text'], 'city' => ['label' => 'Town', 'type' => 'text'], 'kvk' => ['label' => 'Chamber of Commerce number', 'type' => 'text'], 'vat' => ['label' => 'VAT number', 'type' => 'text', 'help' => 'As on your invoices. Leave empty when you are not sure.'], 'opening_hours' => ['label' => 'Opening hours', 'type' => 'lines', 'help' => 'One line per day or group of days, as it should be read.'], 'towns' => ['label' => 'Work area: the towns', 'type' => 'lines', 'help' => 'One per line.'], 'maps_url' => ['label' => 'Link to the map', 'type' => 'url'], ], ], $override); } /** @return array> */ private static function questionItems(): array { return ['question' => ['label' => 'Question', 'type' => 'text'], 'answer' => ['label' => 'Answer', 'type' => 'textarea']]; } /** * What the site sets wins; `fields` are merged per field, so one field can change without the rest. * * @param array $preset * @param array $override */ private static function make(string $name, array $preset, array $override): array { // The words of the simple face, for someone who is not a webmaster; a site overrides them like any other field. foreach (self::SIMPLE[$name] ?? [] as $key => $simple) { if (isset($preset['fields'][$key])) { $preset['fields'][$key]['simple'] = $simple; } } $preset['simple'] = self::SIMPLE_NAMES[$name] ?? []; $fields = array_replace_recursive($preset['fields'], (array) ($override['fields'] ?? [])); unset($override['fields']); return [...$preset, ...$override, 'fields' => $fields]; } }