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!

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

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 dragan
      I just noticed that PW will output frontend-editing markup, even if I output JSON.
      Is there a way I can disable that, from inside my template?
      I use classic switch/case statements and URL-segments to output different content, HTML + JSON, in the same template. I know that my JS modules will not see all that extra markup, and guest users neither.
      [{"title":"Joe Doe","firstName":"<span id=pw-edit-1 class='pw-edit pw-edit-InputfieldText' data-name=firstName data-page=1161 style='position:relative'><span class=pw-edit-orig>Joe<\/span><span class=pw-edit-copy id=pw-editor-firstName-1161 style='display:none;-webkit-user-select:text;user-select:text;' contenteditable>Joe<\/span><\/span>","lastName":"<span id=pw-edit-2 class='pw-edit pw-edit-InputfieldText' data-name=lastName data-page=1161 style='position:relative'><span class=pw-edit-orig>Doe<\/span><span class=pw-edit-copy id=pw-editor-lastName-1161 style='display:none;-webkit-user-select:text;user-select:text;' contenteditable>Doe<\/span><\/span>","teamEmail":"<span id=pw-edit-3 class='pw-edit pw-edit-InputfieldEmail' data-name=teamEmail data-page=1161 style='position:relative'><span class=pw-edit-orig>akbari@inspire.ethz.ch<\/span><span class=pw-edit-copy id=pw-editor-teamEmail-1161 style='display:none;-webkit-user-select:text;user-select:text;' contenteditable>joe.doe@foo.ch<\/span><\/span>","office":"<span id=pw-edit-4 class='pw-edit pw-edit-InputfieldText' data-name=office data-page=1161 style='position:relative'><span class=pw-edit-orig>PFA E 91<\/span><span class=pw-edit-copy id=pw-editor-office-1161 style='display:none;-webkit-user-select:text;user-select:text;' contenteditable>PFA E 91<\/span><\/span>","phone":"<span id=pw-edit-5 class='pw-edit pw-edit-InputfieldText' data-name=phone data-page=1161 style='position:relative'><span class=pw-edit-orig>+41 44 123 45 67<\/span><span class=pw-edit-copy id=pw-editor-phone-1161 style='display:none;-webkit-user-select:text;user-select:text;' contenteditable>+41 44 123 45 67<\/span><\/span>"}] But when working on a PW site, it would be cool to somehow not see this.
      Is there a setting for this? Do I have to add something to my selector?
    • By dragan
      I'm puzzled by something I thought would be rather easy:
      I want to send a request to a PW page. It's POST, and I define a header, and send data as JSON.
      I need to send data in the following format:
      $ POST https://mysite.com/foo/bar/ {"headers": {"Authorization": "Bearer API_KEY", "Content-Type": "application/json"}, "body": {"fields": {"Name": "<get name>", "Department": "<get team>", "Home Address": "<get address>", "Phone #": "<get phone>", "Personal Email Address": "<get email>", "Birthday": "<get birthday>", "Date Added": "<call>currentDate</call>" }}} This is supposed to be sent via a Chatbot engine (Dexter).
      In the PW page that should handle this, $_POST is always empty, as is $_REQUEST. Same for PW's $input or if ($config->ajax) {}.
      I get the header, but no data.
      So I dug deeper, and tried this:
      @ini_set("allow_url_fopen", true);
      @ini_set("always_populate_raw_post_data", true);
      $data = json_decode(file_get_contents('php://input'), true);
      $d    = print_r($data, true); // I store this, along with the header infos and timestamp in a PW page-field (instead of using file_put_content)
      I checked page permissions, I made sure I use pagename/, i.e. with trailing slash only, to avoid stripping the header away due to redirects (which somebody in an older forum thread once highly suggested).
      I tried to send the same stuff that the chatbot does via CURL. Nothing. PW error logs don't report anything (site is still in dev-mode).
      PW 3.0.81 - everything else runs just fine.
      Any ideas what I should change? Any more PHP/Apache settings maybe?
      Help is highly appreciated.
       
    • By benbyf
      HELLO! I always struggle adding additional functionality, buttons and other settings to the CKeditor and I guess other people might have the same issue at times.
      For those who are CKeditor aces would you share your settings in this post to help others with what I guess should be a simple task to extend the default settings.
       

      Extra color select and text formating
      toolbar
      Format, Styles Bold, Italic, Underline, -, RemoveFormat TextColor, BGColor JustifyLeft , JustifyCenter, JustifyRight, JustifyBlock NumberedList, BulletedList, -, Blockquote PWLink, Unlink, Anchor PWImage, Table, HorizontalRule, SpecialChar PasteText, PasteFromWord Scayt, -, Sourcedialog extra allowed content
      small[*] section font[style] span[style]{!color} code[*] custom config options
      colorButton_colors: ec4626,ffde43,00aaeb,004a87,7b9320,ffffff extra plugins
      colorButton  
    • By EyeDentify
      Hello There fellow PW gurus.

      I am trying to make a field show as open only if the field is filled out with at string.
      for example: "my_styles.css" and stay hidden if the field is empty.

      The field in question is of type "text" if that helps.

      And i put in the "show this field only if"
      css_filename!=''

      because the field name is "css_filename"

      But no mather what the field is closed because i have choosen it as "closed" as default.

      What am i doing wrong?

      i am running PW 3.0.83 Dev.
       


    • By prestoav
      Hi all,
      PW: 3.0.42
      I'm trying to have responsive images in the body field. First I need to stop the image tag generated by CKEditor adding the width attribute to the image tag on insertion. I found the 'Skip width attributes on image tags?' in the settings of ProcessPageEditImage and that suggests it does exactly what I'm after.
      Sadly, even when this checkbox is checked and a new image is inserted the width attribute is still added.
      Am I missing something?
      TIA.