pmarki

module
General site settings module

31 posts in this topic

This module provides a solution for keeping various site settings in one place (titles, slogans, api keys, emails, addresses, etc.).

Features

- Admin can create unlimited number of settings
- Settings can be grouped
- Admin can set setting label, notes, property name, field width and type
- Settings can be of type text, checkbox, radios, select, email, url, integer

How to use

In module configuration create as many settings as needed. Customize their label, type, width and provide a name you want to use in a template files (property name). After that admin can set those  settings on "General Settings" page in "Setup" section.
Every time you wish to output eg. site name you can use $settings->site_name or wire('settings')->site_name or $settings->option2 to get value of 'Check it' as seen on the first screenshot. (Checked checkbox returns 1).
You can change global name ($settings) to something else in module configuration.

To get basic markup with all settings and their values use $settings->render(), usefull to check returning values (esp. select/radios - their values are sanitized as page names).

Current limitation:
-no way to change order of settings,
-new settings can only be added at the bottom.

Multilanguage

To make fields multilanguage aware create a field with a same property name with '_languageName' appended. Example: Your site has two languages: default and french, create site_title and site_title_french fields. Put in a template $settings->site_title. If a user has set french language, this module output site_title_french, otherwise site_title. Please notice that render() function is not language aware.

https://github.com/pmarki/ProcessGeneralSettings

Screenshot_20160920_110011.pngScreenshot_20160830_180429.png

Edited by pmarki
new features added
8 people like this

Share this post


Link to post
Share on other sites

I'm using my MultiValueTextformatter module for such things, added to the Home page. Works fine, though it's for the developer only, not for the client because he could easily mess things up. If I use an InputfieldTextaraeaLanguage then it's multilanguage too - btw, is your module multilang capable?

I have another idea in mind for such a module that would heavily depend on JavaScript (namely Vue.js). It would be responsible for the UI, all settings would be saved as one JSON.

1 person likes this

Share this post


Link to post
Share on other sites
4 hours ago, tpr said:

I'm using my MultiValueTextformatter module for such things, added to the Home page. Works fine, though it's for the developer only, not for the client because he could easily mess things up. If I use an InputfieldTextaraeaLanguage then it's multilanguage too - btw, is your module multilang capable?

I have another idea in mind for such a module that would heavily depend on JavaScript (namely Vue.js). It would be responsible for the UI, all settings would be saved as one JSON.

Yes, I used to use MultiValueTextformatter for this and had the same worries. Just modified it a little to have 'some kind of multilanguage support', not as convenient as built in pw, but better than nothing :rolleyes:

1 person likes this

Share this post


Link to post
Share on other sites

Multilanguage can complicate things a lot and most non-techie people doesn't even recognize that. At one of my workplaces they asked me to place 3 language flags to the header - they though it's just as easy like that :)

1 person likes this

Share this post


Link to post
Share on other sites

I have reorganize module settings, it uses JSON and ASM Select for fields, now it's possible to reorder settings, add, delete and so on. The only drawback is that it's not compatible with previous version. If you want to update, you will lose all entered  settings.

1 person likes this

Share this post


Link to post
Share on other sites

Nice! I haven't used it yet just had a quick look.

How about removing the "pencil" icon from the asm items and open the edit modal on click? I think this is the "natural" way of setting asmList item options in PW so people should be aware of that.

Share this post


Link to post
Share on other sites
27 minutes ago, tpr said:

asmList item options

Where are those options? Have I missed them so far? The only similar behavior is the action of the "drop down headers" of Repeater items (but those have the arrow like "greater-than sign") like this:

repeater-example.png

We can only drag-and-drop or delete standard asmSelect list items, at least that's what I have thought so far. Am I missing something?

Share this post


Link to post
Share on other sites

Eg when editing a template you can click on a field (asmList item) and set a few things there (overrides). Is that new to you? :) 

Share this post


Link to post
Share on other sites

Luckily, I have not had to update templates recently :P Jokes aside, yeah, now I see what you meant, but as a side note let me add that even those asmSelects have "text with links on them" and I thought you were referring to simply clicking on the bounding box itself and not on an additional element of it like the <a> in this case. The pencil icon might not be used in the ProcessWire admin in this context, but some sort of indicator is used, and generally I like these indicators, so that even newcomers can figure out the intended behavior. 

Share this post


Link to post
Share on other sites

Well if they get used to the pencil icon then when wil they learn the default PW workings? :)

There's an issue in the module: its SettingsJS.js is added not only in the module's page but every (admin) page and asmList items get the "pencil" icons. Of course clicking on them do nothing, apart from this error:

SettingsJS.js:50 Uncaught TypeError: Cannot read property 'undefined' of null

Setting line 42 to this fixes it:

if ($this->wire('user')->isLoggedin() && $this->input->get('name') == __CLASS__) {

 

3 people like this

Share this post


Link to post
Share on other sites
2 hours ago, tpr said:

How about removing the "pencil" icon from the asm items and open the edit modal on click?

I think I'll leave it as is. It's a good indicator for newcomers and obvious for advanced.

 

38 minutes ago, tpr said:

Setting line 42 to this fixes it:

Thanks, fixed

Share this post


Link to post
Share on other sites

Have you updated the module in the module directory? Update says the latest is v110.

Share this post


Link to post
Share on other sites
20 minutes ago, pmarki said:

Done, but honestly I thought it's done automatically.

It is done automatically, once a day I think (?)...However, you can always do it manually if you can't wait :-) 

Share this post


Link to post
Share on other sites
9 hours ago, monchu said:

Hi pmarki, can I use this module for pw 3.xx version?

Yes, it works with pw3. Just updated module info and added textarea field.

2 people like this

Share this post


Link to post
Share on other sites

If only I knew how to do this...

Adding file fields isn't easy, beacuse you have to store a file somewhere. So far I haven't find a way to achieve this :(

But any advice would be appreciated :)

Share this post


Link to post
Share on other sites

I'm sorry, but I'm facing exactly the same problem. I'm no expert at all, but I guess the module has to create a new file/image field, a new template with that field assigned and finally a new page based on that template. Then this page could be used to store the image. Somehow. Maybe. :rolleyes:

Share this post


Link to post
Share on other sites

i would think that a general site settings module should just store settings, and not any files or images - if you need those just add a custom field to your settings template (?)

alternately ftp upload the image to a specific folder and then reference that file's path in the setting...

 

1 person likes this

Share this post


Link to post
Share on other sites
14 hours ago, Macrura said:

alternately ftp upload the image to a specific folder and then reference that file's path in the setting...

There's certainly nothing wrong with that approach and for sure it's quite common, but I think it is somewhat limited:

  • the customer/editor has to leave his known environment (ProcessWire backend in this case) and has to use FTP/SSH whatever
  • the referenced image is not available for image manipulations, for example: automatic creation a favicons in different solutions

Share this post


Link to post
Share on other sites

it depends - a lot of times if you are talking about a logo, that is a really specific image that might be precisely sized and optimized for display, may have light/dark versions, smaller icon version for mobile, maybe a version with a tagline, as well as possibly retina versions;

it could be something you don't want the client to have access to change.

On the other hand if you did want the client to have access to it and be able to change it, you might need a multi-image field with tags, so that you could upload all of the versions of the logo and tag them (light, dark, retina, icon or whatever). This is why i would recommend using the system's native image fields for images...

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By cosmicsafari
      Hi All,
      Fairly new to ProcessWire so apologies if this is a daft question, but I am having a go creating my first module. I have set it up and enabled it as per the docs.
      However I have created another class within the same module directory, which was going to be used in the main module file but I can't get it to work for the life of me and I believe its due to me not fully understanding the namespace side of things.
      Example:
      MyModule.module.php
      <?php namespace ProcessWire; class MyModule extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Test Module', 'version' => 1, 'summary' => 'Test module', 'href' => '', 'singular' => true, 'autoload' => true, 'icon' => 'exchange', ); } public function newMethod( $testMessage ) { $foo = new Foo($testMessage); $foo->getFoo(); } } Foo.php
      <?php namespace ProcessWire; class Foo { protected $foo; public function __construct($foo) { $this->foo = $foo; } public function getFoo() { return $this->foo; } } Now as I understand it both these files should exist under the ProcessWire namespace, so in theory I should be able to use Foo within MyModule without any use statements as they both exist at the same level within the ProcessWire namespace?
      However when I try something like so:
      $myModule = $modules->getModule('MyModule'); $myModule->myMethod('Foo'); I would have thought this should return 'Foo', however I keep running into errors like:
      Any help would be appreciated.
    • By Max Allan Niklasson
      Hi, I think this is my first topic, even though I've been working with PW a few years. But now, I'm trying to restructure my way of coding, cause many templates (like activities for birding societies) are re appearing in multiple different websites. Since this, I've been working on redo this into a module, but as far as I have read I cannot store the templates (related to specific module) in the module's folder. It has to be in the templates folder?
       
    • By kongondo
      Menu Builder
       
      Modules Directory
      Project Page
      Read Me (How to install, use, etc..)

      If you want a navigation that mirrors your ProcessWire page tree, the system allows you to easily create recursive menus using either vanilla PHP or Soma's great MarkupSimpleNavigation. In some cases, however, you may wish to create menus that:
      1. Do not mirror you site's page tree (hirarchies and ancestry); and
      2. You can add custom links (external to your site) to.

      That is primarily where Menu Builder comes in. It is also helpful if you:
      3. Prefer creating menus via drag and drop
      4. Have a need for menus (or other listings) that will be changing regularly or that you want to allow your admin users to edit.

      The issue of custom menus is not new here in the forums. The difference is that this module allows you to easily create such menus via drag and drop in the Admin. Actually, you can even use it to just create some list if you wanted to. In the backend, the module uses the jQueryUI plugin nestedSortable by Manuele J Sarfatti for the drag and drop and is inspired in part by the WP Custom Menu feature.
       
      Please read the Read Me completely before using this module. 
      For Complex or highly-customised menus, it is recommended to use the getMenuItems() method as detailed in this post.
       
      Features
      Ability to create menus that do not mirror your ProcessWire Page Tree hierarchy/structure Menus can contain both ProcessWire pages and custom links Create menu hierarchies and nesting via drag and drop Easily add CSS IDs and Classes to each menu item on creating the menu items (both custom and from ProcessWire pages) or post creation. Optionally set custom links to open in a new tab Change menu item titles built from ProcessWire pages (without affecting the original page). E.g. if you have a page titled 'About Us' but you want the menu item title to be 'About' Readily view the structure and settings for each menu item Menus stored as pages (note: just the menu, not the items!) Menu items stored as JSON in a field in the menu pages (empty values not stored) Add menu items from ProcessWire pages using page fields (option to choose between PageAutocomplete and AsmSelect [default]) or a Selector (e.g. template=basic-page, limit=20, sort=title). For page fields, you can specify a selector to return only those specified pages for selection in the page field (i.e. asm and autocomplete) For superusers, optionally allow markup in your menu titles, e.g. <span>About</span> Menu settings for nestedSortable - e.g. maxLevels (limit nesting levels) Advanced features (e.g. add pages via selector, menu settings) currently permissible to superadmins only (may change to be permission-based) Delete single or all menu items without deleting the menu itself Lock down menus for editing Highly configurable MarkupMenuBuilder - e.g. can pass menu id, title, name or array to render(); Passing an array means you can conditionally manipulate it before rendering, e.g. make certain menu branches visible only to certain users [the code is up to you!]  Optionally grab menu items only (as a Menu object WireArray or a normal array) and use your own code to create custom highly complex menus to meet any need. More... In the backend, ProcessMenuBuilder does the menu creation. For the frontend, menus are displayed using MarkupMenuBuilder.

      Credits

      In this module's infancy (way back!), I wanted to know more about ProcessWire modules as well as improve my PHP skills. As they say, what better way to learn than to actually create something? So, I developed this module (instead of writing PW tutorials as promised, tsk, tsk, naughty, naughty!) in my own summer of code . Props to Wanze, Soma, Pete, Antti and Ryan whose modules I studied (read copied ) to help in my module development and to Teppo for his wonderful write-up on the "Anatomy of fields in ProcessWire" that vastly improved my knowledge and understanding of how PW works. Diogo and marcus for idea about using pages (rather than a custom db table), onjegolders for his helpful UI comments, Martijn Geerts, OrganizedFellow, dazzyweb and Mike Anthony for 'pushing me' to complete this module and netcarver for help with the code.
       
      Screens

    • By kongondo
      Introducing Variations, an Input- and Fieldtype for product variations and their attributes.
      Product variations is a topic that has been coming up now and then, especially in the recent past.  This module seeks to fill this gap. Though it's in its early stages of development, it is already functional and can be used as is. I decided to make an early announcement (modules development forum) in order to get early feedback from potential users. 
      The module is an alternative take on how variations can be built for a product. Imagine the ubiquitous T-Shirt. The product could vary by ...Size, Colour, Material, etc...These variations could in turn have internal variations, i.e. attributes....so, Size [Small, Large], Colour [Red, Blue]...etc; you get the drift.
      The usual approaches to building variations have been either to use Multiple pages, Repeaters, Page Table, Table or Matrix (limited to 1x1 variations). In this module, we do it a bit differently.
      First, the variations occur not at the Field level (meaning all product pages would have the same variations and attributes for each template) but at the page level. Secondly, there are no multiple pages for each variation and/or attributes; a product is a single page. The variations and their attributes are defined by site editors at the page level. Once a variations configuration has been defined, it is applied to the page and all possible combinations are generated (i.e. the Red,Small,Cotton; Red,Large,Cotton, etc) in the Inputfield. There is no limit to the number of variations and attributes that can be defined, although you will be amazed at how quickly the combinations grow! Prices are entered for each combination when editing the page. Combinations without prices are not saved to the database. Please note that prices cannot themselves vary at the page-level. Meaning, you cannot have ONE variation configuration that has different price inputs per product in the same FieldtypeVariations field.
      The module ships with an API for outputting variation combinations in the frontend. Search, database and in-memory work as normal in the frontend. In the backend, DataTables provides a nice paginated, filterable table. Prices can be entered on any pages (of the table) without loss of data (meaning you can enter prices on page 1, scroll to page 10, enter more prices, filter or search the products table, enter more prices and finally save; no data will be lost).
      I still have a couple of ideas and plans pending but would love to hear from you, thanks.
      Below is a short video demo of the module in its current state. Things may/will change, both UI and features. Btw, the Fieldtype, although primarily targeted at commerce applications, is by no means limited to this. Other uses requiring combinations of whatever number of variables are very much within the remit of the module.
      Planned/Hoped for features
      Import/Export product variations and attributes (Excel, etc) Full integration with Padloper (I will have to  discuss with @apeisa) SKU fields for each product variation Add/Remove extra subfields, e.g. multi-currency prices (currently there is only 1 input for each product variations' price) Product variation images? Etc... Please not this module is not related to this other planned module (but it may eventually).
      Sneak Peek Demo
       
       
    • By bernhard
      hi everybody,
      this is a preview of a module that i'm working on for quite a long time. I needed it for an intranet office management application that i'm still working on. It makes it very easy to create very customized Datatables using the awesome jquery datatables plugin (www.datatables.net)
       
      EARLY ALPHA release!
      It's very likely that there will lots of changes to this module that may cause breaking your implementations.
       
      Module source
      https://gitlab.com/baumrock/RockDataTables2/tree/master
      Screencast:

       
      Remarks:
      The module is intended to be used on the backend. Loading styles is at the moment only done via adding files to the $config->styles/scripts arrays. Also the communicaton to javascript is done via the $config->js() method that is built into the admin and would have to be implemented manually on frontend use. But it would not be difficult of course
       
      Installation:
      Nothing special here, just download + install
       
      Example setup of the most minimal Table:
      you always need 2 files to create a table:
      php file to define the columns and related data (page selector) js file to control the client-side actions like rendering, sorting, etc PHP
      // init datatables module $dt2 = $modules->get('RockDataTables2'); // setup columns // name $col = new dtCol(); $col->name = 'name'; $col->title = 'Name'; $col->data = function($page) { return $page->title; }; $dt2->cols->add($col); // setup table $dt2->id = 'dt_kundenliste'; // give your table an id $dt2->js('/site/modules/ProcessRockProjects/dt_kundenliste.js'); // tell it where to find the related javascript // ################################## // ajax request -> return data // non-ajax -> render table // ################################## if($config->ajax) { // here you can setup your page selector // this will for sure change in the future to support filtering etc echo $dt2->getJSON($pages->find('template=rockcontact, sort=random, limit=10000')); die(); } else return $dt2->render(); JS
      $(document).ready(function() { // setup variables var opt = ProcessWire.config.dt_kundenliste; // options from backend var colDefs = []; // column definitions // custom column definitions here (see https://datatables.net/reference/option/columnDefs for all options) // load default column definitions colDefs = colDefs.concat(dtGetDefaultDefs(opt)); // initialise table $('#dt_kundenliste').DataTable({ ajax: './kundenliste/', columnDefs: colDefs, }); }); that's it - as easy as that!

       
      Customization example:
      in the screencast you see an example that i'm using in a process module. i put the table inside an InputfieldMarkup just to have the same look&feel all around the admin. you see that you could also use this module to create tables quickly and easily using @kongondo s runtime markup module.
      complete PHP code:
      $this->headline('Kundenliste'); $form = $modules->get('InputfieldForm'); // init datatables module $dt2 = $modules->get('RockDataTables2'); // setup columns // name $col = new dtCol(); $col->name = 'name'; $col->title = 'Name'; $col->data = function($page) { return $page->title; }; $dt2->cols->add($col); // type $col = new dtCol(); $col->name = 'type'; $col->data = function($page) { return $page->rockcontact_type->title; }; $dt2->cols->add($col); // modified $col = new dtCol(); $col->name = 'modified'; $col->data = function($page) { $obj = new stdClass(); $obj->timestamp = $page->modified; $obj->display = date('d.m.Y', $page->modified); return $obj; }; $dt2->cols->add($col); // setup table $dt2->id = 'dt_kundenliste'; $dt2->js('/site/modules/ProcessRockProjects/dt_kundenliste.js'); $f = $modules->get('InputfieldMarkup'); $f->value = $dt2->render(); $form->add($f); // ################################## // ajax request -> return data // non-ajax -> render form + table // ################################## if($config->ajax) { echo $dt2->getJSON($pages->find('template=rockcontact, sort=random, limit=10000')); die(); } else $out .= $form->render(); return $out; what is interesting here is this part:
      // modified $col = new dtCol(); $col->name = 'modified'; $col->data = function($page) { $obj = new stdClass(); $obj->timestamp = $page->modified; $obj->display = date('d.m.Y', $page->modified); return $obj; }; $dt2->cols->add($col); datatables support orthogonal data (https://datatables.net/extensions/buttons/examples/html5/outputFormat-orthogonal.html). a date column is a good example, because you need to DISPLAY a formatted date (like 10.02.2017) but you need to be able to SORT this column by a different value (timestamp). its very easy to accomplish this by providing both values in your json. Btw: You could also just transfer the timestamp and do the formatting on the client-side via javascript. Next Example will show ho this would work. Both cases can be necessary, it's just an example here.
      back to topic: now we have both data available and need to tell the table wich data to use for which action. it's easy, just add the definition to the array:
      // modified date colDefs.push({ targets: opt.colnames.indexOf('modified'), render: { _: 'display', sort: 'timestamp', }, }); this tells the datatable to use the display-value for displaying (and filtering) and the timestamp-value for sorting. see https://datatables.net/reference/option/columns.render
      you can also easily modify a simple non-orthogonal data via a render function:
      // name colDefs.push({ targets: opt.colnames.indexOf('name'), render: function ( data, type, full, meta ) { return '<span class="blurry" title="'+data+'">'+data+'</span>'; }, }); this adds the span with "blurry" class to every cell of type "name". i did this to blur all the client data in my screencast
      the complete javascript:
      $(document).ready(function() { // setup variables var opt = ProcessWire.config.dt_kundenliste; // options from backend var colDefs = []; // column definitions // custom column definitions here // see https://datatables.net/reference/option/columnDefs for all options // name colDefs.push({ targets: opt.colnames.indexOf('name'), render: function ( data, type, full, meta ) { return '<span class="blurry" title="'+data+'">'+data+'</span>'; }, }); // typ colDefs.push({ targets: opt.colnames.indexOf('type'), render: function ( data, type, full, meta ) { return '<a href="#" style="white-space: nowrap;">'+data+'</a>'; }, }); // modified date colDefs.push({ targets: opt.colnames.indexOf('modified'), render: { _: 'display', sort: 'timestamp', }, }); // load default column definitions colDefs = colDefs.concat(dtGetDefaultDefs(opt)); // initialise table $('#dt_kundenliste').DataTable({ ajax: './kundenliste/', columnDefs: colDefs, scrollY: "400px", scrollCollapse: true, scrollX: "100%", pageLength: 10, }); }); you can also have scrollbars just by adding options to your datatable. also fixed columns are possible. just see the docs on datatables.net

      Why i created this module:
      of course i know @Soma s module but i needed a lot more features and the newer datatables version. also i like to define all the columns as objects and have everything on one place. lister & markupadmindatatable: nice for basic tables but lacks of features to modify the appearance of the cell values (like rendering icons, background colors and so on) datatables provides a great frontend API for filtering, showing/hiding columns, getting data, modifying it... it also plays well together with frontend charts like google chart api in this case:
       
      todo / roadmap:
      all kinds of column filters (like seen in the example above that shows an older and bloated version of this module) support for ajax filters and pagination (currently all filtering and sorting is done on the client side. i tried it with up to 50.000 rows and got reasonable results. initial loading took around 10sec. but of course this heavily depends on the complexity of your table and your data.