pmarki

module
General site settings module

46 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
10 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 thought it's just as easy like that :)

2 people like 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 Robin S
      First a note about my other modules...
      I have three existing modules that are similar in that they allow restrictions to be placed on repeating inputfields: Limit Repeater, Limit PageTable, Limit Table
      Restrict Repeater Matrix takes a different approach to the module configuration from those other modules. The module settings for Restrict Repeater Matrix are applied in the field settings rather in a module config screen. I think this new approach is better, but it means that it isn't practical to create different settings for different roles via the admin interface. Instead the module has a hookable method, allowing roles to be targeted and other advanced usages to be achieved via a hook. The result is that the module is more flexible.
      I intend to transition my other modules to the same approach over the coming weeks, but because this will result in breaking changes I will be releasing the updated modules under new names ("Restrict Repeater", etc) to avoid users upgrading via the Upgrades module without full awareness of the changes. The old modules will be marked as deprecated.
       
      Restrict Repeater Matrix
      A module for ProcessWire CMS/CMF. Allows restrictions and limits to be placed on Repeater Matrix fields.
      For any matrix type in a Repeater Matrix field you have the option to:
      Prevent drag-sorting of items Prevent cloning of items Prevent toggling of the published state of items Prevent trashing of items Limit the number of items that may be added to the inputfield Please note that restrictions and limits are applied with CSS/JS so should not be considered tamper-proof.
      Usage
      Install the Restrict Repeater Matrix module.
      For each matrix type created in the Repeater Matrix field settings, a "Restrictions" fieldset is added at the bottom of the matrix type settings:

      For newly added matrix types, the settings must be saved first in order for the Restrictions fieldset to appear. Set restrictions for each matrix type as needed. A limit of zero means that no items of that matrix type may be added to the inputfield.
      Setting restrictions via a hook
      Besides setting restrictions in the field settings, you can also apply or modify restrictions by hooking RestrictRepeaterMatrix::checkRestrictions. This allows for more focused restrictions, for example, applying restrictions depending on the template of the page being edited or depending on the role of the user.
      The checkRestrictions() method receives the following arguments:
      $field This Repeater Matrix field $inputfield This Repeater Matrix inputfield $matrix_types An array of matrix types for this field. Each key is the matrix type name and the value is the matrix type integer. $page The page that is open in ProcessPageEdit The method returns a multi-dimensional array of matrix types and restrictions for each of those types. An example of a returned array:

      Example hooks
      Prevent the matrix type "images_block" from being added to "my_matrix_field" in a page with the "basic-page" template:
      $wire->addHookAfter('RestrictRepeaterMatrix::checkRestrictions', function(HookEvent $event) { $field = $event->arguments('field'); $page = $event->arguments('page'); $type_restrictions = $event->return; if($field->name === 'my_matrix_field' && $page->template->name === 'basic-page') { $type_restrictions['images_block']['limit'] = 0; } $event->return = $type_restrictions; });  
      Prevent non-superusers from trashing any Repeater Matrix items in "my_matrix_field":
      $wire->addHookAfter('RestrictRepeaterMatrix::checkRestrictions', function(HookEvent $event) { $field = $event->arguments('field'); $type_restrictions = $event->return; if($field->name === 'my_matrix_field' && !$this->user->isSuperuser()) { foreach($type_restrictions as $key => $value) { $type_restrictions[$key]['notrash'] = true; } } $event->return = $type_restrictions; });  
      https://github.com/Toutouwai/RestrictRepeaterMatrix
    • By bernhard
      Hi,
      just stumbled over a little module that i built for my last project. it helped me to test performance of my rockdatatables module to generate 3000 random json datasets and i want to share it with you. maybe it saves some time for someone.
      https://gitlab.com/baumrock/RockDummyData/
      easy example:
      $rdd = $modules->get('RockDummyData'); for($i=0; $i<15; $i++) { // this has to be inside the for-loop to always get a new dummy $dummy = $rdd->getDummy(); echo date("d.m.Y H:i:s", $dummy->timestamp) . "<br>"; } more advanced:
      $json = new stdClass(); $json->data = array(); $rdd = $modules->get('RockDummyData'); for($i=0; $i<3000; $i++) { // this has to be inside the for-loop to always get a new dummy $dummy = $rdd->getDummy(); $obj = new stdClass(); $obj->name = $dummy->forename . ' ' . $dummy->surname; $obj->position = $dummy->job; $obj->office = $dummy->city; $obj->color = $dummy->color; $obj->start_date = new stdClass(); $obj->start_date->display = date('d.m.Y',$dummy->timestamp); $obj->start_date->sort = $dummy->timestamp; $obj->salary = rand(0,10000); $json->data[] = $obj; } echo json_encode($json); you have to store your random datasets on your own into the /data folder. there are several services for creating all kinds of random data on the web - if you know one service that allows sharing those datasets let me know and i can include common needed data into the module
    • By AndySh
      Hello!
      I need your assistance please. I purchased the module FormBuilder. Unfortunately, the module discontinued delivering customer submissions to e-mail box specified in the module settings. Direct mailing to the e-mail box works OK. The module settings stays the same and are correct, like "Send e-mail to administrator(s) is checked. The last version of FormBuilder 3.0 has been installed. Please advise how to resolve the issue becase I cannot get orders from customers anymore (((
    • By kixe
      As described in this post (https://processwire.com/talk/topic/8551-custom-urls-for-pages/?p=82742) the option 'Name Format Children' under the tab 'Family' in template settings doesn't work properly and also not as expected. I had a look inside the code and made some changes which are working properly, which offers much more options, more consistency and less code too.

      The result is the following. You have 3 Options for generating name and title, which could be combined in endless variations.
      Name is always derived from title, same like creating pages manually.
      type date: if function detects # character anywhere in the string, conversion will be: deletion of # and string will be used as format parameter for PHP date() function type field: if string is a fieldname of the parent page the value of this field will be used type string: if string doesn't fit to the 2 preceeding it will be taken as it is All parts (separated by comma) will be composed in the order of setting. You can use unlimited numbers of parts

      I made a pull request on github: https://github.com/ryancramerdesign/ProcessWire/pull/831

      Example screenshots

      Setting ...


      will result in


       
    • By kongondo
      FieldtypeRuntimeMarkup and InputfieldRuntimeMarkup
       
      Modules Directory: http://modules.processwire.com/modules/fieldtype-runtime-markup/
      GitHub: https://github.com/kongondo/FieldtypeRuntimeMarkup
       
      This module allows for custom markup to be dynamically (PHP) generated and output within a page's edit screen (in Admin).
       
      The value for the fieldtype is generated at runtime. No data is saved in the database. The accompanying InputfieldRuntimeMarkup is only used to render/display the markup in the page edit screen.
       
      The field's value is accessible from the ProcessWire API in the frontend like any other field, i.e. it has access to $page and $pages.
       
      The module was commissioned/sponsored by @Valan. Although there's certainly other ways to achieve what this module does, it offers a dynamic and flexible alternative to generating your own markup in a page's edit screen whilst also allowing access to that markup in the frontend. Thanks Valan!
       
      Warning/Consideration
      Although access to ProcessWire's Fields' admin pages is only available to Superusers, this Fieldtype will evaluate and run the custom PHP Code entered and saved in the field's settings (Details tab). Utmost care should therefore be taken in making sure your code does not perform any CRUD operations!! (unless of course that's intentional) The value for this fieldtype is generated at runtime and thus no data is stored in the database. This means that you cannot directly query a RuntimeMarkup field from $pages->find(). Usage and API
       
      Backend
      Enter your custom PHP snippet in the Details tab of your field (it is RECOMMENDED though that you use wireRenderFile() instead. See example below). Your code can be as simple or as complicated as you want as long as in the end you return a value that is not an array or an object or anything other than a string/integer.
       
      FieldtypeRuntimeMarkup has access to $page (the current page being edited/viewed) and $pages. 
       
      A very simple example.
      return 'Hello'; Simple example.
      return $page->title; Simple example with markup.
      return '<h2>' . $page->title . '</h2>'; Another simple example with markup.
      $out = '<h1>hello '; $out .= $page->title; $out .= '</h1>'; return $out; A more advanced example.
      $p = $pages->get('/about-us/')->child('sort=random'); return '<p>' . $p->title . '</p>'; An even more complex example.
      $str =''; if($page->name == 'about-us') { $p = $page->children->last(); $str = "<h2><a href='{$p->url}'>{$p->title}</a></h2>"; } else { $str = "<h2><a href='{$page->url}'>{$page->title}</a></h2>"; } return $str; Rather than type your code directly in the Details tab of the field, it is highly recommended that you placed all your code in an external file and call that file using the core wireRenderFile() method. Taking this approach means you will be able to edit your code in your favourite text editor. It also means you will be able to type more text without having to scroll. Editing the file is also easier than editing the field. To use this approach, simply do:
      return wireRenderFile('name-of-file');// file will be in /site/templates/ If using ProcessWire 3.x, you will need to use namespace as follows:
      return ProcessWire\wireRenderFile('name-of-file'); How to access the value of RuntimeMarkup in the frontend (our field is called 'runtime_markup')
       
      Access the field on the current page (just like any other field)
      echo $page->runtime_markup; Access the field on another page
      echo $pages->get('/about-us/')->runtime_markup; Screenshots
       
      Backend
       

       

       
      Frontend