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