Jump to content

General site settings module


pmarki

Recommended Posts

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
  • Like 11
Link to comment
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.

  • Like 1
Link to comment
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:

  • Like 1
Link to comment
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 thought it's just as easy like that :)

  • Like 2
Link to comment
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.

  • Like 1
Link to comment
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.

Link to comment
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?

Link to comment
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. 

Link to comment
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__) {

 

  • Like 3
Link to comment
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

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

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...

 

  • Like 1
Link to comment
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
Link to comment
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...

  • Like 1
Link to comment
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
×
×
  • Create New...