Jump to content

Settings Factory


Macrura

Recommended Posts

@Zeka - as far as i know this module shouldn't prevent you from using languages, since you create the inputfields, and the module does not limit what you put in the config settings for any/each inputfield. Did  you test it already and find it not working (?), if so i can look and see if the issue is with the module, otherwise it should work the same as if you were creating module config settings..

Link to comment
Share on other sites

  • 1 month later...

Hi @adrian - thanks for testing this - hoping to submit to modules directory soon. In terms of the process page, i think it is better to not install any, because it may cause more confusion, since the name of the process page is important in the setup.. LMK if you have any ideas about that, or do you think it should install a starter settings page, but as an option?

Link to comment
Share on other sites

I don't think it needs to be automatic, but perhaps the instructions could be expanded. Currently all they say is:

"Create your processes then enter a path to the json or php definition of the fields in the path field."

and that didn't initially make sense to me. I think spell it out:

1. Create a page under Admin (at the top level or under Setup if you prefer)

2. Save the page and then choose the ProcessSettingsFactory process from the dropdown.

3. Enter the path to youre settings file. Not sure using a placeholder is good the way you did - I actually thought it was already filled out with: settings/site-settings.php

I also think you should say included "samples", not examples, because of the folder they are stored in.

Hope that helps.

  • Like 4
  • Thanks 1
Link to comment
Share on other sites

@Macrura

I have several hooks to before/after TemplateFile render method and typically I can exclude PW backend like

$templateFile = $event->object;

        if ($templateFile->page->template == 'admin') {
            return;
        }

or

if ($this->wire('page')->template->name == 'admin') {
	return;
}

But these checks fail for rendering settings pages and hooks are executed also for those template files in the admin panel and I get "PHP Notice: Trying to get property of non-object" as $this->wire('page') = null and there is no $event->object->page->template. 

I'm not sure that it is directly relative to SettingsFactory, so I would ask you to check this behavior.

 

 

Link to comment
Share on other sites

i'm not following 100%; the module assumes you will want the settings everywhere (front/back).

I don't see $this->wire('page') anywhere in the module, can you provide more details?

By the way, the flowchart for the (non-process) module is like this:

(1) find all admin pages using ProcessSettingsFactory
(2) process each settings page and store the settings

(these 2 procedures run in the buildFactory() method which runs on init(); and this module is autoload).

This procedure might be able to be more optimized, but does ensure that any changes you make to your files (like adding inputfields) are reflected. Maybe checking the last mod date; or maybe a settings lock field on the process that prevents the file from being further processed and wirecache the array from the file;

 

Link to comment
Share on other sites

@Macrura

For example, I have this hook in module

public function init()
{
  $this->addHookAfter('TemplateFile::render', $this, 'hookAfterTemplateRender');
}

public function hookAfterTemplateRender($event)
{
  if ($this->wire('page')->template->name == 'admin') {
  return;
  }

  // some logic which I don't want in admin pages
}

You use WireRenderFIle which is the shortcut of TemplateFile class. In that way, my hook executes also for calls of WireRenderFile method in the module and I get mentioned notices as $thiss->wire('page') is null.

So the issue is that I can't find the way how to check and prevent the execution of hook for calls of wireRenderFile. Hope it explains what I mean. 

Link to comment
Share on other sites

@Zeka, maybe you can use the filename, prependFilename or appendFilename properties of the TemplateFile to limit where your hook applies. E.g.

$wire->addHookAfter('TemplateFile::render', function(HookEvent $event) {
    $template_file = $event->object;
    $proceed = false;
    foreach($template_file->appendFilename as $filename) {
        if(substr($filename, -9) === '_main.php') $proceed = true;
    }
    if(!$proceed) return;
    // Your code...
});

I'm curious - what's your reason for hooking after TemplateFile::render? If you are targeting non-admin template files inside your /site/ why wouldn't you include whatever logic you need inside the template files rather than via a hook?

  • Like 1
Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...

@Macrura - Great looking module!  Couple of questions for you:

Can you perform any validations when using this module?  Example: Say you have a settings field for integers.  Is there a way to verify that the integer is greater than 10?

Can each settings page be restricted by some kind of role or permission?  Ex. Site editors could access/edit a "Theme settings" page, but couldn't access/edit the "API Settings" page.

Link to comment
Share on other sites

33 minutes ago, gmclelland said:

Can you perform any validations when using this module?  Example: Say you have a settings field for integers.  Is there a way to verify that the integer is greater than 10?

yes, since you create the inputfields, they support all built in attributes, so you'd just need to set those attributes in your PHP or JSON array.

33 minutes ago, gmclelland said:

Can each settings page be restricted by some kind of role or permission?  Ex. Site editors could access/edit a "Theme settings" page, but couldn't access/edit the "API Settings" page. 

Yes, each settings page is full access controllable.

  • Thanks 1
Link to comment
Share on other sites

21 hours ago, benbyf said:

there a video or tutorial with screens for this module? I feel like I'd love to use it but cant visualise how it works in my head.

ok yeah, I'll see if i can improve the readme and i'll post a walkthrough here with some screenshots shortly...

In the meantime a lot of the info in this post is still relevant:

 

  • Like 1
Link to comment
Share on other sites

The process of setting up a settings page is very simple; You need to start with a JSON or PHP fields definition file; There are samples of these in the module. Once you have your file in valid JSON, or PHP that returns an array of inputfields, you would create a page somewhere under your Admin branch.

You can name this whatever you want, but bear in mind that the name of the process page is how you will access your settings. Once you create the page (using Admin template), and set the process as "ProcessSettingsFactory", you should see a blank text field; In this field you enter the path to your definition file, which should be located somewhere in templates.

At this point you can now access your settings page and see if it works (you should see your fields). You can populate the fields, and save, and your data will save in the module config.

You can now access your settings on the front end by doing this:

$factory = $modules->get("SettingsFactory");
$newsSettings = $factory->getSettings('news-settings');// where news-settings is the name of the process page holding the settings you want to get,

You can view the contents of what is returned Tracy (e.g. bd($newsSettings);)

So far this has been rock solid on some very big sites, both in terms of users accessing and modifying settings, as well as dealing with permissions to the settings, and outputting the settings in the front end; Haven't noticed any performance issues, and some sites have 5-6 different settings panels.

Link to comment
Share on other sites

  • 3 weeks later...

Hi @Macrura,

I was just testing out this module and it seems to work great!  Thank you for making this module.

Is there any way to access control individual settings factory pages?  I see there is an "settings-factory" permission included with the module.  I don't know if it is feasible, but maybe a permission could somehow be created for each settings factory page?

For example, you might want a client to be to make changes to a "Theme settings" page, but you don't want them to mess with the "API settings" page.

Also, I'm curious if and how you use this module for SEO?  or do you use something like the MarkupSEO module?  Would you create a settings page for each type of template to override the general seo settings page as needed?

Link to comment
Share on other sites

Thanks Adrian, I'm currently using MarkupSEO.  I haven't tried your fork yet, but probably will switch at some point since MarkupSEO doesn't seem to be maintained anymore.

Although it may be possible that Settings Factory can do the job as well?

Link to comment
Share on other sites

43 minutes ago, gmclelland said:

Is there any way to access control individual settings factory pages? 

yes you just need to make the permission the same name as the process page, and then use that permission to restrict; if you need examples i can explain it more, but essentially this is like the core permissions setup used by stuff like lister pro, where the permission for a process matches the process page name.

I haven't looked at MarkupSEO for a while, instead i use my (yet unreleased) MarkupSiteMetaAdvanced module, which has like a gazillion seo settings, but much more since it covers basically everything related to meta data, including schema, all social media, DCMI, analytics, copyrights, location, as well as the ability to setup custom key value pairs or define a path to a json inputfields definition file (sort of like mini settings factory);

preview:

1666680198_Modules__ProcessWire__jonathandawe_com.thumb.jpg.e2320609f9907c14f675156a1a420971.jpg

  • Like 3
  • Thanks 1
Link to comment
Share on other sites

When you use a CKeditor field in Settings Factory.  Is there anyway to specify text formatters or markup options like "Link abstraction"?

I also noticed an error when I clicked the Ckeditor image button on a CKeditor field on my Settings Factory page.

image.jpg.ad0e1d2deb87a4000d0c1caf82b2cf45.jpg

error.thumb.jpg.01aacdc39baad82ea6ff7fc9556804a8.jpg

Is there also a way to simplify the CKeditor's buttons?

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By sms77io
      Hi all,
      we made a small module for sending SMS via Sms77.io. It supports sending to one and multiple users.
      You can download it from GitHub and follow the instructions on how to install it - it is quite easy. An API key is required for sending, get yours for free @ Sms77 and receive 0,50 €.
      Hope this helps somebody and we are open for improvement suggestions!
       
      Best regards
      André
    • By opalepatrick
      I see old posts saying that repeaters are not the way to go in Custom Process Modules. If that is the case, when using forms (as I am trying to do) how would one tackle things like repeat contact fields where there can be multiple requirements for contact details with different parameters? (Like point of contact, director, etc) or even telephone numbers that have different uses?
      Just for background I am creating a process module that allows me to create types of financial applications in the admin area (no need to publish any of this, pure admin) that require a lot of personal or company information.
      Maybe I am thinking about this incorrectly?
    • By jploch
      Hey folks,
      for a module (a pagebuilder based on PageTable) I need to save some settings as JSON. The values are saved for each page table item (a pw page). It's working well, but I am looking for ways to improve the structure I have. As I'm not that experienced with JSON, maybe someone more experienced can take a look and tell me if my approach is good practice. 

      My goal is to make all the items accessible by page id, without looping over them (using objects instead of arrays):
      // access from template with pw page var $jsonObject->items->{$page}->cssClass; Her is an example of my JSON structure:
      { "items": { "3252": { "id": "3252", "cssClass": "pgrid-main", "breakpoints": { "base": { "css": { "grid-column-end": "auto", "grid-row-end": "auto", "grid-column-start": "auto", "grid-row-start": "auto", "align-self": "auto", "z-index": "auto", "padding-left": "60px", "padding-right": "60px", "padding-top": "60px", "padding-bottom": "60px", "background-color": "rgb(255, 255, 255)", "color": "rgb(0, 0, 0)" }, "size": "@media (min-width: 576px)", "name": "base" } } }, "3686": { "id": "3686", "cssClass": "test_global", "breakpoints": { "base": { "css": { "grid-column-end": "-1", "grid-row-end": "span 1", "grid-column-start": "1", "grid-row-start": "auto", "align-self": "auto", "z-index": "auto", "padding-left": "0px", "padding-right": "0px", "padding-top": "0px", "padding-bottom": "0px", "background-color": "rgba(0, 0, 0, 0)", "color": "rgb(0, 0, 0)" }, "size": "@media (min-width: 576px)", "name": "base" } } }, "3687": { "id": "3687", "cssClass": "block_editor-3687", "breakpoints": { "base": { "css": { "grid-column-end": "span 2", "grid-row-end": "span 1", "grid-column-start": "auto", "grid-row-start": "auto", "align-self": "auto", "z-index": "auto", "padding-left": "0px", "padding-right": "0px", "padding-top": "0px", "padding-bottom": "0px", "background-color": "rgba(0, 0, 0, 0)", "color": "rgb(0, 0, 0)" }, "size": "@media (min-width: 576px)", "name": "base" } } }, "3696": { "id": "3696", "cssClass": "block_editor-3696", "breakpoints": { "base": { "css": { "grid-column-end": "span 2", "grid-row-end": "span 1", "grid-column-start": "auto", "grid-row-start": "auto", "align-self": "auto", "z-index": "auto", "padding-left": "0px", "padding-right": "0px", "padding-top": "0px", "padding-bottom": "0px", "background-color": "rgba(0, 0, 0, 0)", "color": "rgb(0, 0, 0)" }, "size": "@media (min-width: 576px)", "name": "base" } } } }, "breakpointActive": "base", "breakpointActiveSize": "@media (min-width: 576px)" }  
    • By hellerdruck
      Hi all
      I need to export all the texts from a website to a translation company (as json or csv or txt...). How can this be done? Of course manually, but this website is huge and it would take me years...
      Also, as a second step, importing the translation ...
      Any ideas anyone? Tutorials? Plugins?
      Thanks for your help.
    • By jonatan
      So... I thought (for some stupid reason I can't even recall now no wait now I remember.. I wanted to hide the "Trash" for "editor" role users) that it'd be super duper smart to "Enable access control" for the field "process" on the admin template.... Really really stupid.... Now all I get is:

       
       
       
      – when I go to mywebsitedomain.com/admin
      but.... my website domain.com and all its subpages works perfectly fine! So it's ONLY the /admin (processwire) which throws a 503 at me. 
      🥵🤯☠️💩😭😱
      S.O.S.
×
×
  • Create New...