Jump to content
Macrura

Settings Factory

Recommended Posts

Hi @Macrura

Do you have plans to support ML in your module?

I meen support of 

'useLanguages' => true,

in field config.

Eugene. 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

@Macrura

Yes, I have tested it and only values for default language are saved. 

As far as I can see the issue is in the processForm method.

Share this post


Link to post
Share on other sites

I'm not experienced with the multilanguage stuff; I'd have to research to see if there is a way to support it...

Share this post


Link to post
Share on other sites

@Macrura
Just made pull request with some modifications to support ML and useLanguages. 
It's quite dirty, but works for me. Maybe you will find it useful.

  • Like 2

Share this post


Link to post
Share on other sites

Hey @Macrura,

I was surprised that the Process module didn't automatically create its own page, so I was a little lost for a minute or two, but otherwise looks great and looking forward to using it - thanks for the hard work!

  • Like 1

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
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

Share this post


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

 

 

Share this post


Link to post
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;

 

Share this post


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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Hadn't predicted that need, but i can look into it...

  • Like 1

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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

Share this post


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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites
5 minutes ago, gmclelland said:

Would you create a settings page for each type of template to override the general seo settings page as needed?

My fork of MarkupSEO has this ability.

  • Like 2

Share this post


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

Share this post


Link to post
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

Share this post


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

 

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 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.
    • By Ivan Gretsky
      Most of us know and use site/config-dev.php file. If present, it is used instead of site/config.php, so it is easy to set database connection and debug mode for local development, not touching the production config. It is also very useful when working with git. You can simply ignore it in the .gitignore file, so local settings won’t end up in the repo.
      But sometimes you need to add code to site/ready.php or site/init.php just for the dev environment. For example, to add ryan’s super cool on demand images mirrorer. I can’t live without it when working with big sites, which have more assets then I want to download to my desktop.
      It would be great if there was something like site/ready-dev.php for this. Not out-of-the-box, but it’s pretty easy to achieve. Unlike site/config-dev.php, site/ready.php is not hardcoded. It’s name is set with a special config setting:
      // wire/config.php $config->statusFiles = array( 'boot' => '', 'initBefore' => '', 'init' => 'init.php', 'readyBefore' => '', 'ready' => 'ready.php', 'readySite' => '', 'readyAdmin' => '', 'render' => '', 'download' => '', 'finished' => 'finished.php', 'failed' => '', ); As you can see, we can not only define, which files are loaded on init, ready and finished runtime states, but probably even add more if we need to.
      So we override this setting in site/config-dev.php like this:
      // site/config-dev.php // Change ready.php to ready-dev.php $temp = $config->statusFiles; $temp['ready'] = 'ready-dev.php'; $config->statusFiles = $temp; For some reason we can’t just do
      $config->statusFiles['ready'] = 'ready-dev.php'; and have to override the whole array. Maybe you PHP gurus can explain this in the comments.
      Now we can create the site/ready-dev.php file and place all the dev-only code there. Important thing is to include the main site/ready.php.
      // site/ready-dev.php include 'ready.php'; // DEV HOOK TO MIRROR ASSETS ON DEMAND $wire->addHookAfter('Pagefile::url, Pagefile::filename', function($event) { $config = $event->wire('config'); $file = $event->return; if($event->method == 'url') { // convert url to disk path $file = $config->paths->root . substr($file, strlen($config->urls->root)); } if(!file_exists($file)) { // download file from source if it doesn't exist here $src = 'https://mysite.com/site/assets/files/'; $url = str_replace($config->paths->files, $src, $file); $http = new WireHttp(); try { $http->download($url, $file); } catch (\Exception $e) { bd($file, "Missing file"); } } }); Do not forget to replace "mysite.com" if you’re copypasting this))
      Now, add the newly created file to the `.gitignore` and we’re done.
       
      # .gitignore # Ignore dev files site/config-dev.php site/ready-dev.php Thanks for reading!
       
    • By MoritzLost
      Sorry for the convoluted title. I have a problem with Process modules that define a custom page using the page key through getModuleInfo (as demonstrated in this excellent tutorial by @bernhard). Those pages are created automatically when the module is installed. The problem is that the title of the page only gets set in the current language. That's not a problem if the current language (language of the superuser who is installing the module) is the default language; if it isn't, the Process page is missing a title in the default language. This has the very awkward effect that a user using the backend in the default language (or any other language) will see an empty entry in the setup menu:

      This screenshot comes from my Cache Control module which includes a Process page. Now I realize the description sounds obscure, but for us it's a common setup: We a multiple bilingual sites where the default language is German and the second language is English. While the clients use the CMS in German, as a developer I prefer the English interface, so whenever I install a Process module I get this problem.
      As a module author, is there a way to handle this situation? I guess it would be possible to use post-installation hooks or create the pages manually, but I very much prefer the declarative approach. The page title is already translatable (through the __ function), but of course at the time of installation there is no translation, and as far as I'm aware it's not possible to ship translations with a module so they are used automatically. Could this situation be handled better in the core? I would prefer if the module installation process would always set the title of the Process page in the default language, instead of the language of the current user.
    • By MoritzLost
      Process Cache Control
      This module provides a simple solution to clearing all your cache layers at once, and an extensible interface to perform various cache-related actions.
      The simple motivation behind this module was that I was tired of manually clearing caches in several places after deploying a change on a live site. The basic purpose of this module is a simple Clear all caches link in the Setup menu which clears out all caches, no matter where they hide. You can customize what exactly the module does through it's configuration menu:
      Expire or delete all cache entries in the database, or selectively clear caches by namespace ($cache API) Clear the the template render cache. Clear out specific folders inside your site's cache directory (/site/assets/cache) Clear the ProCache page render cache (if your site is using ProCache) Refresh version strings for static assets to bust client-side browser caches (this requires some setup, see the full documentation for details). This is the basic function of the module. However, you can also add different cache management action through the API and execute them through the module's interface. For this advanced usage, the module provides:
      An interface to see all available cache actions and execute them. A system log and logging output on the module page to see verify what the module is doing. A CacheControlTools class with utility functions to clear out different caches. An API to add cache actions, execute them programmatically and even modify the default action. Permission management, allowing you granular control over which user roles can execute which actions. The complete documentation can be found in the module's README.
      Plans for improvements
      If there is some interest in this, I plan to expand this to a more general cache management solution. I particular, I would like to add additional cache actions. Some ideas that came to mind:
      Warming up the template render cache for publicly accessible pages. Removing all active user sessions. Let me know if you have more suggestions!
      Links
      https://github.com/MoritzLost/ProcessCacheControl ProcessCacheControl in the Module directory CHANGELOG in the repository Screenshots


×
×
  • Create New...