Jump to content

Settings Factory


Macrura

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

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

Link to comment
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 4
Link to comment
Share on other sites

  • 2 weeks later...

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

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

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

 

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

Link to comment
Share on other sites

  • 1 year later...

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
Link to comment
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 4
Link to comment
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 3
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...