Jump to content
Macrura

Settings Factory

Recommended Posts

@gmclelland

you definitely won't be able to ckeditor images, because there is no Page to store the images under;

unless there is some way that you can use a hook, and then use the PHP option for your field defs and then in that file define your hook etc,

In terms of Ck editor, i think you'd need to study the inputfield itself and see how the options are supplied to the inputfield, and then just mimic that; So far i have not had the necessity to use ckeditor field, or images for the Settings Factory, and i don't think it will be able to support images unless someone comes up with an idea for how to solve that problem...

Share this post


Link to post
Share on other sites

Thanks Macrura.  I just tested and it looks like you can do this:

// in site-settings.php
// note the toolbar line and inlineMode line

[
        'name' => 'ckeditor_test',
        'label' => 'CK Editor Test',
        'type' => 'InputfieldCKEditor',
        'width' => '100',
        'description' => 'Some Formatted Test',
        'collapsed' => 0,
        'value' => '',
        'toolbar' => "Bold, Italic",
		'inlineMode' => 1,
    ],

Doing that will only show the Bold and Italic buttons in the CKeditor toolbar.  It will also use inline mode.  I'm not sure about the other stuff yet.  I found those settings in wire/modules/Inputfield/InputfieldCKEditor/InputfieldCKEditor.module

Hope that helps someone.

  • Like 2

Share this post


Link to post
Share on other sites

@Macrura

https://github.com/outflux3/SettingsFactory/blob/master/SettingsFactory.module#L69

I don't think that looping through all admin pages is the optimal way to find all settings pages. In that way, on every page load, all admin pages get loaded and it produces a lot of unnecessary PDO queries. 

For example in one of my project, I have a lot of repeater/matrix pages and I get this stats without/with the SettingFactory module:

Pages loaded (38 / 239)
PDO queries (38 / 224)

 

  • Like 2

Share this post


Link to post
Share on other sites

right, ok thanks for the report – i have an easy fix for this, will post update soon.

  • Like 1

Share this post


Link to post
Share on other sites

@Zeka

I think the 2 things that need to happen are

(1) change the selector and not have to iterate, that was not efficient, but the process does not appear to be queryable; if the process was able to be part of the selector that would solve this issue completely, but for some reason it doesn't work which is why it ends up being an in-memory find;

if we add a field to the module that sets the parent of the settings pages under admin, that would reduce the pages loaded, tested this and it did reduce that by a lot.

$adminPages = $this->wire('pages')->find("template=admin,parent=2153");
$settingsPages = $adminPages->find("process=ProcessSettingsFactory");
$adminPages->uncacheAll();

(2) not sure if the uncacheAll() call here is correct, but it also seems to further reduce the pages loaded. 

If you want to hack the module and see if these changes work in your setup (make sure to change the parent=id to the id of the parent of the settings process pages), I'll carry on testing and researching here; If anyone out there knows why the process is not queryable by the selector engine, that would be good to know, would help on another module also..

Share this post


Link to post
Share on other sites

Hi.

Test this

		$module_id = wire('modules')->getModuleInfo('ProcessSettingsFactory')['id'];
		$adminPages = $this->wire('pages')->find("template=admin, process=$module_id");

 

  • Like 3

Share this post


Link to post
Share on other sites

Hi,

After updating to PW 3.0.109 i get the following error:

Error: Call to a member function attr() on null in .../site/assets/cache/FileCompiler/site/modules/SettingsFactory/ProcessSettingsFactory.module on line 137

Can't figure out, what's going wrong :s

Share this post


Link to post
Share on other sites

Hi Peejay,

What happens when you go to /processwire/module/ and click on the "clear compiled files" button?

I just upgraded my local install and I'm not seeing this problem.

Share this post


Link to post
Share on other sites

Hi gmclelland, 

Thx for your fast reply 🙂.

I tried your module with only inputfields (like your example kitchen-sink) and then there is no problem.

But when I use your "wiretabs" example then I get the error.

Share this post


Link to post
Share on other sites

All credit goes to Macrura, it is his module.  Can you post the code you are using?

Share this post


Link to post
Share on other sites
$inputfields = new InputfieldWrapper();

//---------------------------------------------------
$general = [
    [
        'name' => 'site_name',
        'label' => __('Site Name'),
        'type' => 'InputfieldText',
        'required' => true,
        'value' => '',
        'useLanguages' => true
    ],
    [
        'name' => 'email_address',
        'label' => __('E-mail'),
        'type' => 'InputfieldEmail',
        'required' => true,
        'value' => '',
        'columnWidth' => 33
    ],
    [
        'name' => 'telephone',
        'label' => __('Telephone'),
        'type' => 'InputfieldText',
        'required' => true,
        'value' => '',
        'columnWidth' => 34
    ],
    [
        'name' => 'facebook',
        'label' => __('Facebook'),
        'type' => 'InputfieldText',
        'value' => '',
        'columnWidth' => 33
    ]
];

$tab = new InputfieldWrapper();
$tab->attr('title', 'General');
$tab->attr('class', 'WireTab');
$tab->add($general);
$inputfields->append($tab);

return $inputfields;

 

Share this post


Link to post
Share on other sites

I think you actually need to have more than 1 tab if you're going to use wiretabs (?) you said you tried it with the wiretabs-example.php ?

Share this post


Link to post
Share on other sites

When I use 1 or more tabs I have the same error.  Indeed, I also tried the wiretabs-example.php

Share this post


Link to post
Share on other sites

Hmm... It works for me without error.

Spoiler

<?php

/**
 * since you can only return 1 array to the module, you have to wrap 
 * the tabs in an inputfield wrapper
 */
$inputfields = new InputfieldWrapper();

//---------------------------------------------------
$general = [
    [
        'name' => 'site_name',
        'label' => __('Site Name'),
        'type' => 'InputfieldText',
        'required' => true,
        'value' => ''
    ],
    [
        'name' => 'email_address',
        'label' => __('E-mail'),
        'type' => 'InputfieldEmail',
        'required' => true,
        'value' => ''
    ],
    [
        'name' => 'telephone',
        'label' => __('Telephone'),
        'type' => 'InputfieldText',
        'required' => true,
        'value' => ''
    ],
    [
        'name' => 'fax',
        'label' => __('Fax'),
        'type' => 'InputfieldText',
        'value' => ''
    ],
];

$tab = new InputfieldWrapper();
$tab->attr('title', 'General');
$tab->attr('class', 'WireTab');
$tab->add($general);
$inputfields->append($tab);

//---------------------------------------------------
// $location = [
//     [
//         'name' => 'address',
//         'label' => __('Address'),
//         'type' => 'InputfieldText',
//         'required' => true,
//         'value' => ''
//     ],
//     [
//         'name' => 'postal_code',
//         'label' => __('Postal code'),
//         'type' => 'InputfieldText',
//         'required' => true,
//         'value' => '',
//         'columnWidth' => 33
//     ],
//     [
//         'name' => 'city',
//         'label' => __('City'),
//         'type' => 'InputfieldText',
//         'required' => true,
//         'value' => '',
//         'columnWidth' => 67
//     ],
// ];

// $tab = new InputfieldWrapper();
// $tab->attr('title', 'Location');
// $tab->attr('class', 'WireTab');
// $tab->add($location);
// $inputfields->append($tab);

//---------------------------------------------------


return $inputfields;

 

Did you maybe forget the opening <?php tag?

Share this post


Link to post
Share on other sites

I just upgraded core and the settings do still work; What PHP version are you running? Do you have TracyDebugger installed? Would be good to see what bd($f) is around line 136

Share this post


Link to post
Share on other sites

Never mind, It's not an issue in the module.

Last weekend I updated my MAMP. 😑

On my online server the module works! 

Thanks for your help! 🙂 

Share this post


Link to post
Share on other sites

Hi @Macrura,

just tried your module and have some suggestions:

This is the screen after installation:

zyZozpU.png

What do you think of adding this section in the instructions field? https://github.com/outflux3/SettingsFactory#instructions (or at least the link)

You could even add a direct link to create a new page under ADMIN (.../page/add/?parent_id=2) or under SETUP (.../page/add/?parent_id=22).

Maybe you also want to add this screenshot for anybody wanting to get a quick impression of how this module looks in action (using the kitchen-sink example file): 

SfEMSHJ.png

Looks like I should start using your modules for my projects! 🙂 Thx!

How do you handle file uploads? Eg site logo, favicon, image placeholder, invoice template etc? Maybe we get a possibility soon: https://processwire.com/talk/topic/22815-new-post-weekly-update-for-27-dec-2019/?do=findComment&comment=195465 

 

  • Like 3

Share this post


Link to post
Share on other sites

Thx @adrian true. That would be a good option. Though not ideal imho. But the best option we have so far. Thx

Share this post


Link to post
Share on other sites
2 hours ago, bernhard said:

That would be a good option. Though not ideal imho. But the best option we have so far. Thx

I will soon implement the file upload to custom folder feature into ImageReference. Then you can upload an image from within the inputfield to a designated folder and then pick it afterwards. This should make it an even better option for SettingsFactory.

  • Like 3

Share this post


Link to post
Share on other sites

@bernhard, many thanks for trying out the module, and for your suggestions and feedback!

I will see about implementing the suggestions, especially linking to the Github and Forum topics for anyone who installs it, so that it is easier to grasp how to use it.

I'm also hoping to test out the ImageReference field within this and then post example screenshots showing an even more kitchen sink setup, with images etc.

Not directly related to your post, but responding more to the general consensus on where and how to create settings pages: I found this module to be most useful in the past couple of years for things like:

- Site Schema for a person or business (the fields basically follow the schema.org items; See screenshots below)
- Settings for various custom implementations - e.g. api keys, urls, enable/disable features, etc.
-- on one site we use this to enable the site manager to choose which comment system to use (Disqus, Facebook etc), and then put in various settings if using Disqus (user id etc)
- Theme settings, like you might find on a WordPress theme, stuff like colors, what type of global footer to use, logo selections (using page refs), site title, slogan.

It is also a good way to have settings for any custom code you are doing without having to write a module...

324647347_Local_Business__schema___ProcessWire__inbalancetaichi_com.thumb.jpg.1eaa4646b7c945e59f2f8570faa8b62f.jpg1348105684_Local_Business__schema___ProcessWire__inbalancetaichi_com.thumb.jpg.018a696581d92c4a4399215d55238052.jpg

  • Like 2

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