https://crispy.cat/software/crispage Crispage is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. */ namespace Crispage\Assets; defined("ROOT") or die(); use \Crispage\Auth\CorePermissions; class Module extends \Crispage\Asset { public static function getNames(): array { return ["{%MODULE}", "{%MODULES}"]; } public static function getPermissions(): array { return [ "create" => CorePermissions::MODIFY_LAYOUT, "modify" => CorePermissions::MODIFY_LAYOUT, "modify_own"=> CorePermissions::MODIFY_LAYOUT, "delete" => CorePermissions::MODIFY_LAYOUT, "delete_own"=> CorePermissions::MODIFY_LAYOUT ]; } public static function getSortingInfo(): array { return [ "field" => "location", "desc" => false ]; } public static function getListColumns(): array { global $Crispage; return [ "id" => ["label" => "{%ID}"], "slug" => [ "label" => "{%SLUG}", "filter" => "\\Crispage\\Utils\\TextUtils::codeify" ], "component" => [ "label" => "{%TYPE}", "filter" => "\\Crispage\\Utils\\TextUtils::codeify" ], "location" => [ "label" => "{%LOCATION}", "filter" => "htmlentities" ], "position" => [ "label" => "{%POSITION}", "filter" => null ], "enabled" => [ "label" => "{%STATE}", "filter" => function(bool $s): string { global $Crispage; return $Crispage->i18n->translate( ($s) ? "{%ENABLED}" : "{%DISABLED}" ); } ], "mtime" => [ "label" => "{%MODIFIED}", "filter" => [$Crispage->i18n, "datetime"] ] ]; } public static function getListActions(): array { return [ [ "route" => "module_create", "label" => "{%CREATE_NEW}", "color" => "success" ] ]; } public static function getEditorFields(): array { return [ "enabled" => [ "column" => 0, "component" => "\\Crispage\\Components\\Fields\\BooleanFieldComponent", "com_data" => [ "label" => "{%ENABLED}:" ], "filter" => "boolval" ], "slug" => [ "column" => 1, "component" => "\\Crispage\\Components\\Fields\\TextFieldComponent", "com_data" => [ "label" => "{%SLUG}:", "attrs" => ["placeholder" => "automatic"] ], "filter" => "strval" ], "location" => [ "column" => 1, "component" => "\\Crispage\\Components\\Fields\\TextFieldComponent", "com_data" => [ "label" => "{%LOCATION}:", "attrs" => ["required"] ], "filter" => "strval" ], "position" => [ "column" => 1, "component" => "\\Crispage\\Components\\Fields\\NumberFieldComponent", "com_data" => [ "label" => "{%POSITION}:", "attrs" => ["required"] ], "filter" => "intval" ] ]; } public static function getOptionFields(): array { return [ "config" => [ "component" => "\\Crispage\\Components\\Fields\\ModuleConfigFieldComponent", "com_data" => [], "filter" => function($data): array { global $Crispage; if (!is_array($data)) return []; $asset = $Crispage->assets->get( intval($Crispage->request->params["asset_id"]) ?? 0 ); $Crispage->loadClass($asset->component); $ndata = []; foreach ($asset->component::getModuleFields() as $name => $field) $ndata[$name] = $field["filter"]($data[$name] ?? null); return $ndata; } ] ]; } public string $component; public string $location; public int $position; public bool $enabled; public function __construct(array $props) { parent::__construct($props); $this->component = $props["component"] ?? "\\Crispage\\Components\\DefaultComponent"; $this->location = $props["location"] ?? "default"; $this->position = $props["position"] ?? 0; $this->enabled = $props["enabled"] ?? false; } public function config(string $key, $default = null) { return $this->_options_array["config"][$key] ?? $default; } } ?>