Jump to content

Settings Factory


Macrura

Recommended Posts

@gornycreative thanks - the use case sounds interesting and obviously useful for dynamically generating options from other places than static choices; I'll play around with it soon and try and post back, have some projects that will probably need more elaborate settings pages soon...

Link to comment
Share on other sites

If you want to try the example I built (it looks for css/less files in assets/fonts and templates/ and then parses font families and returns a select options box with unique path/font family pairs) let me know and I'll tidy up an example and attach it.

On the backend it gives me this:

image.thumb.png.9fa2bb0eb849834f4e2892d7f5fc34ac.png

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

  • 5 months later...
50 minutes ago, Krlos said:

Hi @Macrura,

I just found your amazing module, how can I enable multilanguage support for fields?

Thanks.

 

Hi Krlos - thanks - I believe the module does support multilanguage, and we had added support for that a few years ago. I know there is probably no example of how to set a multilanguage field in the samples, but AFAIK it should work if you get the JSON or PHP setup to tell it the various language parameters.

  • Like 1
Link to comment
Share on other sites

  • 2 months later...
8 minutes ago, fruid said:

has something changed in this module? Because I cannot seem to find the place where you enter the path to the json or php file with the settings array. I'm on ProcessWire 3.0.207

@fruid First create a new admin page (under admin, with admin template) and then select ProcessSettingsFactory as the process.

After that you'll see the Inputfields Definition File Path field show.

Link to comment
Share on other sites

13 hours ago, fruid said:

I tried that, FYI I see 

PHP Warning: Undefined array key "footer_imprint__1021" in .../modules/SettingsFactory/ProcessSettingsFactory.module:151

Yes i see that the lines that handle the languages (148-154) is not checking if the array key is set yet. Will have to add that check to prevent the warning.

  • Like 2
Link to comment
Share on other sites

I know I'm sort of preaching to the choir here, but it's a shame you cannot add images in SF. I think what many devs, me included ,want to use this module for is for global settings which includes things like logo(s). It just makes so much more sense to have these things defined in a separate page rather than by adding fields to the home template but maybe I'm just being too neurotic. 

Please forgive me if this is a dumb question, but since I have to create a page under the admin page tree to get SF to work, why can't I add images to this very site's /assets/files/ folder? But I guess the answer does something like because the fields I create on the required php or json file don't really exist in the system and are create at runtime?

  • Like 1
Link to comment
Share on other sites

  • 1 month later...
  • 5 months later...

@froot sorry I didn't see your posts.

On 9/29/2023 at 4:26 AM, froot said:

Please forgive me if this is a dumb question, but since I have to create a page under the admin page tree to get SF to work, why can't I add images to this very site's /assets/files/ folder? But I guess the answer does something like because the fields I create on the required php or json file don't really exist in the system and are create at runtime?

If i understand correctly the admin pages use the admin template which is not a configurable template.

You could create a settings page under the admin using the ProcessPageEdit process and then using a hook you can get that admin page to use a page in the tree, like "/settings/"; this was an old trick we used to do all the time and suggested by @Jonathan Lahijani.

In terms of the general workflow for the settings factory, i just don't attempt to use images on those settings pages, but what I do is use a centralized media library to store site assets such as a logo. The logo is also tagged as such, and is additionally easily findable by the site managers and they can replace it on their own if they need to; this allows me to use all of the features of the regular page editor and images field and not have to hack it for use in Settings Factory. In SF you could create a page select that would allow selection of that media item.

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

I'm trying to achieve the following:

I already have a selectoptions field with a specific page array.
I want to add custom links to that array that I would define as JSON inside another field "menulinks" on this very settings factory page. 

How can I access the fields value while I'm on the settings page? I understand I would need to save the page first before the value is accessible inside the options field? So how to access the value? It must be stored somewhere…

// Assume $fields is your instance of the Fields API in ProcessWire

// Fetch the 'menu_allocation' field
$menuField = $fields->get('menu_allocation');

// Get the options for the 'menu_allocation' field
$menuOptions = $menuField->type->getOptions($menuField);

// Create an empty array to store the page arrays for each option
$pageArrays = array();


// Loop through each menu option
foreach ($menuOptions as $menuOption) {
  // Convert $menuOption to a string
  $menuOptionString = (string)$menuOption->title;

  // Create a selector to find pages with 'menu_allocation' set to the current option
  $selector = "menu_allocation=$menuOptionString, sort=sort";

  // Find pages that match the selector
  $treePages = $pages->find($selector);


  // Convert the pages to an array
  $pageArray = array();
  foreach ($treePages as $page) {
    $pageArray[$page->id] = $page->title;
  }

  // Add the page array to the main array
  $pageArrays[$menuOptionString] = $pageArray;
}

$inputfields = array(
        array(
        'name' => 'menulinks',
        'label' => 'menulinks',
        'type' => 'textarea',
        'value' => '',
        'columnWidth' => 30,
      ),
);

// json_decode the "menulinks" value to an array
// merge the resulted array with the pageArrays

// Loop through each page array and create 'asmselect' field
foreach ($pageArrays as $menuOption => $pageArray) {
  $inputfields[] = array(
      'name' => 'page_select_' . $menuOption, // Unique name based on $menuOption
      'label' => 'Select a page for ' . $menuOption,
      'type' => 'asmselect',
      'description' => 'Select a page from the page tree for ' . $menuOption,
      'columnWidth' => 100,
      'useLanguages' => false,
      'options' => $pageArray, // Use the page array as options for the 'asmselect'
  );
}

return $inputfields;

 

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