2022-03-08 15:55:41 +01:00
<?php namespace ProcessWire;
class AdminThemeReno extends AdminTheme implements Module, ConfigurableModule {
/**
* Per the Module interface, return an array of information about the Module
*
*/
public static function getModuleInfo() {
return array(
'title' => 'Reno',
'version' => 17,
'summary' => __('Admin theme for ProcessWire 2.5+ by Tom Reno (Renobird)', __FILE__),
'autoload' => "template=admin",
'author' => "Tom Reno (Renobird)",
'requires' => 'AdminThemeDefault',
);
}
static $defaultIcons = array(
"home" => "fa-home",
"signout" => "fa-power-off",
"profile" => "fa-user",
"page" => "fa-file-text",
"setup" => "fa-wrench",
"module" => "fa-briefcase",
"access" => "fa-unlock",
"form-builder" => "fa-list-alt",
"notices" => "fa-bell",
);
public function __construct() {
2024-04-04 14:37:20 +02:00
parent::__construct();
2022-03-08 15:55:41 +01:00
foreach(self::$defaultIcons as $key => $value) {
$this->$key = $value;
}
}
public function getModuleConfigInputfields(array $data) {
2024-04-04 14:37:20 +02:00
$modules = $this->wire()->modules;
$config = $this->wire()->config;
$templates = $this->wire()->templates;
2022-03-08 15:55:41 +01:00
$this->init();
$inputfields = $this->wire(new InputfieldWrapper());
// colorscheme
2024-04-04 14:37:20 +02:00
/** @var InputfieldRadios $field */
$field = $modules->get('InputfieldRadios');
2022-03-08 15:55:41 +01:00
$field->attr('name', 'colors');
$field->label = $this->_('Color Set');
$field->icon = "fa-eyedropper";
$field->addOption('', $this->_('Reno'));
$field->addOption('classic', $this->_('Classic'));
$field->addOption('blue', $this->_('Blue'));
// Scan for custom colour schemes in /site/modules/AdminTheme/AdminTheme{Name}/styles/
// Thanks Pete @notanotherdev
$dirs = array(
dirname(__FILE__) . '/styles/',
2024-04-04 14:37:20 +02:00
$config->paths->siteModules . 'AdminTheme/' . $this->className() . '/styles/',
2022-03-08 15:55:41 +01:00
);
foreach($dirs as $customDir) {
if(is_dir($customDir)) {
foreach(glob($customDir . '*.css') as $file) {
$name = str_replace('main-', '', basename($file, '.css')); // Remove "main-" from default theme names
if($name == 'main' || $name == 'classic' || $name == 'blue') continue;
$formatName = ucwords(str_replace('-', ' ', $name));
$field->addOption($name, $formatName);
}
}
}
$field->attr('value', isset($data['colors']) ? $data['colors'] : '');
$field->optionColumns = 1;
$inputfields->add($field);
// User templates
// Processwire 2.5.14+ supports multiple user templates
// Revisit when droppping support for 2.5.3
2024-04-04 14:37:20 +02:00
$template_ids = $config->userTemplateIDs;
if(empty($template_ids)) {
$template_ids = array($templates->get('user')->id);
}
2022-03-08 15:55:41 +01:00
2024-04-04 14:37:20 +02:00
/** @var InputfieldFieldset $fieldset */
$fieldset = $modules->get("InputfieldFieldset");
2022-03-08 15:55:41 +01:00
$fieldset->label = $this->_('User Images');
$fieldset->description = $this->_('To use this feature your user template(s) needs to have an image field. If your user template(s) do not have an image field, the avatar will default to an icon. To add an image field to the default user template to go Setup > Templates > Filters (Show System Templates). The "user" template will now show in the list. If you have created an additional/alternate user template, you can enable this feature by adding an image field to that template.');
$fieldset->icon = "fa-image";
2024-04-04 14:37:20 +02:00
foreach($template_ids as $id){
2022-03-08 15:55:41 +01:00
2024-04-04 14:37:20 +02:00
$template = $templates->get($id);
2022-03-08 15:55:41 +01:00
// User Avatar fields
2024-04-04 14:37:20 +02:00
/** @var InputfieldSelect $field */
$field = $modules->get("InputfieldSelect");
2022-03-08 15:55:41 +01:00
$field->attr('name', "avatar_field_$template->name");
$field->label = sprintf($this->_('Image field for the %s template'), $template->name);
$imageField = false;
foreach($template->fields as $f) {
if(($f->type == "FieldtypeImage") || ($f->type == "FieldtypeCropImage")){
if(isset($data["avatar_field_$template->name"]) && $data["avatar_field_$template->name"] == $f->name) {
$field->addOption($f->name, $f->name, array("selected"=>"selected"));
2024-04-04 14:37:20 +02:00
$imageField = $f;
2022-03-08 15:55:41 +01:00
} else {
$field->addOption($f->name, $f->name, array());
$imageField = true;
}
}
}
if(!$imageField) {
// no image fields found
$field->addOption('', $this->_('No image fields assigned to this template'));
2024-04-04 14:37:20 +02:00
} else if($imageField instanceof Field) {
2022-03-08 15:55:41 +01:00
// make the image field part of the profile fields the user may edit
2024-04-04 14:37:20 +02:00
$profileConfig = $modules->getModuleConfigData('ProcessProfile');
if(!in_array($imageField->name, $profileConfig['profileFields'])) {
$profileConfig['profileFields'][] = $imageField->name;
$modules->saveModuleConfigData('ProcessProfile', $profileConfig);
$this->message(sprintf($this->_('Added field "%s" to fields editable by user in their profile.'), $imageField->name));
2022-03-08 15:55:41 +01:00
}
}
$fieldset->add($field);
}
$inputfields->add($fieldset);
// Display Name
2024-04-04 14:37:20 +02:00
/** @var InputfieldFieldset $fieldset */
$fieldset = $modules->get("InputfieldFieldset");
2022-03-08 15:55:41 +01:00
$fieldset->label = $this->_('User Display Names');
$fieldset->icon = "fa-user";
$fieldset->description = $this->_("Comma separated list of fields to use as the display name in the admin. (example: first_name, last_name)");
$fieldset->notes = $this->_('These can only be text fields. Other field types will be ignored.');
2024-04-04 14:37:20 +02:00
foreach($template_ids as $id){
$template = $templates->get($id);
/** @var InputfieldText $field */
$field = $modules->get("InputfieldText");
2022-03-08 15:55:41 +01:00
$field->attr("name+id", "userFields_$template->name");
$field->label = sprintf($this->_('Display name for the %s template'), $template->name);
isset($data["userFields_$template->name"]) ? $user_info = $data["userFields_$template->name"] : $user_info = "name";
$field->value = $user_info;
$fieldset->add($field);
}
$inputfields->add($fieldset);
// Icons
2024-04-04 14:37:20 +02:00
/** @var InputfieldFieldset $fieldset */
$fieldset = $modules->get("InputfieldFieldset");
2022-03-08 15:55:41 +01:00
$fieldset->label = $this->_('Icons');
$fieldset->description = $this->_('Specify icons for navigation items');
$fieldset->icon = "fa-cog";
$fieldset->collapsed = true;
// notices
2024-04-04 14:37:20 +02:00
/** @var InputfieldIcon $field */
$field = $modules->get("InputfieldIcon");
2022-03-08 15:55:41 +01:00
$field->attr('name', "notices");
$field->label = $this->_("Top Navigation: Notices");
$field->columnWidth = 50;
$field->attr('value', array_key_exists('notices', self::$defaultIcons) ? self::$defaultIcons['notices'] : "fa-bell");
if (isset($data['notices'])) $field->attr('value', $data['notices']);
$fieldset->add($field);
// view homepage icon
2024-04-04 14:37:20 +02:00
/** @var InputfieldIcon $field */
$field = $modules->get("InputfieldIcon");
2022-03-08 15:55:41 +01:00
$field->attr('name', "home");
$field->label = $this->_("Top Navigation: View Home Page");
$field->columnWidth = 50;
$field->attr('value', array_key_exists('home', self::$defaultIcons) ? self::$defaultIcons['home'] : "fa-home");
if (isset($data['home'])) $field->attr('value', $data['home']);
$fieldset->add($field);
// signout
2024-04-04 14:37:20 +02:00
/** @var InputfieldIcon $field */
$field = $modules->get("InputfieldIcon");
2022-03-08 15:55:41 +01:00
$field->attr('name', "signout");
$field->label = $this->_("Sign out");
$field->columnWidth = 50;
$field->attr('value', array_key_exists('signout', self::$defaultIcons) ? self::$defaultIcons['signout'] : "fa-power-off");
if (isset($data['signout'])) $field->attr('value', $data['signout']);
$fieldset->add($field);
2024-04-04 14:37:20 +02:00
foreach($this->wire()->pages->find("parent=2, sort=sort") as $p){
2022-03-08 15:55:41 +01:00
if(!$p->viewable()) continue;
2024-04-04 14:37:20 +02:00
/** @var InputfieldIcon $field */
$field = $modules->get("InputfieldIcon");
2022-03-08 15:55:41 +01:00
$field->attr('name', $p->name);
2024-04-04 14:37:20 +02:00
$field->label = __($p->title, '/wire/templates-admin/default.php');
2022-03-08 15:55:41 +01:00
$field->columnWidth = 50;
$field->attr('value', array_key_exists($p->name, self::$defaultIcons) ? self::$defaultIcons[$p->name] : "fa-file-text-o");
if (isset($data[$p->name])) $field->attr('value', $data[$p->name]);
$fieldset->add($field);
}
$inputfields->add($fieldset);
return $inputfields;
}
2024-04-04 14:37:20 +02:00
}