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
×
×
  • Create New...