Jump to content

Robin S

  • Content Count

  • Joined

  • Last visited

  • Days Won


Robin S last won the day on September 2

Robin S had the most liked content!

Community Reputation

6,024 Excellent

About Robin S

  • Rank
    Hero Member

Profile Information

  • Gender
  • Location
    New Zealand

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. @CrazyEnimal, please insert your code inside a code block in forum posts. You can use SQL in ProcessWire when it suits you. That's what the $database API variable is for. Here is one way you could get a listing of manufacturers with the number of occurrences within a selection of cars. // Get the IDs of the cars $car_ids = $pages->findIDs("parent=$parent, template=page_car, dealer=$dealer_id"); // Get table for manufacturer Page Reference field $table = $fields->get('manufacturer')->getTable(); // Get manufacturers that are selected in the car pages $query = $database->query("SELECT data FROM $table WHERE pages_id IN (" . implode(',', $car_ids) . ")"); $manufacturer_ids = $query->fetchAll(\PDO::FETCH_COLUMN); // Count how many times each manufacturer occurs in the results $manufacturer_occurrences = array_count_values($manufacturer_ids); // Sort the results in order of occurrences, highest to lowest arsort($manufacturer_occurrences); // Get the manufacturer pages $manufacturers = $pages->getById(array_keys($manufacturer_occurrences)); // Output a list of manufacturer titles and the number of occurrences foreach($manufacturers as $manufacturer) { echo "<p>{$manufacturer->title} ({$manufacturer_occurrences[$manufacturers->id]})</p>"; }
  2. Assuming the categories are assigned to locations by a Page Reference field named "categories": $locations = $pages->find("template=location"); foreach($locations as $location) { foreach($location->categories as $category) { echo "<marker title='$location->title' category='$category->title'/>"; } }
  3. In PW you cannot have multiple sibling pages with exactly the same name. That's why the pages are automatically renamed - otherwise you would see an error message.
  4. Maybe it's a matter of rethinking this in light of what the real objective is. I'm guessing that when the notify_user checkbox is checked and the page is saved, something happens - some sort of action that notifies a user. You're saying that you want to force the notify_user checkbox to be in a checked state if the categories field is changed, presumably to force the action to happen. So why not just do the action if the categories field has changed? $pages->addHookAfter('saveReady', function(HookEvent $event) { $page = $event->arguments(0); // If the notify_user checkbox is checked or the categories field value has changed... if($page->notify_user || $page->isChanged('categories')) { // Do the notify user action... } });
  5. Since this thread was started a hasPage property has been added to Inputfield instances in PW. So you can do this: $wire->addHookBefore('Inputfield::render', function(HookEvent $event) { /* @var Inputfield $inputfield */ $inputfield = $event->object; $page = $inputfield->hasPage; if($page) { // Use $page bd($page->name, 'page name'); } });
  6. The new FormBuilder features look very nice, thanks! Lots of questions spring to mind... 1. When using Form A within a Form B, is it possible to override any of the field settings of Form A in the context of Form B? Say, if I was using Form A inside several other forms but I needed one of the fields to be required only within Form B. 2. Is it possible to have show-if and required-if dependencies on fields within Form A that depend on the values of fields within Form B? 3. In a paginated form, are the form values submitted to the server each time Next / Back is clicked? So is each page validated independently and the user cannot move forward until the current page validates, or is all the validation done on the final submit? 4. If each page is submitted/validated independently, can a site admin see partial form submissions in Entries that are abandoned before the final submit button is clicked? 5. Or if the form is only submitted/validated after all pages are completed, how are field errors displayed if they occur on multiple different pages in the form? 6. Is it planned to have an overview navigation of the pagination using the page headings, so a user can jump directly to any previous page in form and can see how far they have progressed through the total form? 7. Do the different pages "know" about the values entered into other pages in the form, so show-if and required-if can depend on values in other pages? Probably I just need to wait until the new version is released. 🙂
  7. This means that there is no property "page" on $event->argument(0). The first and only argument to InputfieldPage::getSelectablePages() is: @param Page $page The Page being edited This is the page that's open in Page Edit, regardless of whether the Page Reference field is inside a Repeater or not. So probably you don't need to use getForPage() in your situation.
  8. FormBuilder has just such a setting: Although strangely if I change this setting it doesn't stick and always returns to "Auto-detect" - might be a bug. For controlling the WireMail mailer used by other modules perhaps the recently released Mail Router module could be a solution. Although the module that is sending the mail can't be detected directly, for some circumstances you could perhaps use a prefix in the subject line (e.g. "Form submission: ...") that could determine which WireMail mailer is used.
  9. I forgot to mention that you must enable URL segments on the uppy template. I've updated my previous post to include this step. Although I'm not sure why you would get a 403 because of that - rather you should get a 404.
  10. Here's a basic example of how you could save files to a PW page via a front-end page using tus-php and Uppy. 1. Install tus-php via Composer. 2. Create a PW template that will provide the tus-php server endpoint - in this example the template is named "uppy". In the template Files tab, disable any automatically appended template file. In the template URLs tab, allow URL segments. If using Tracy Debugger, disable the debug bar in the front-end for this template because we don't want any output from Tracy being included in the response. The contents of the uppy.php template file: <?php namespace ProcessWire; // Create PW temp directory $td = $files->tempDir('uppy'); $td_path = (string) $td; // Create TusPhp server $server = new \TusPhp\Tus\Server(); // Set path to endpoint - no trailing slash here $server->setApiPath('/uppy'); // Set upload directory $server->setUploadDir($td_path); // Listener function for when an upload is completed $server->event()->addListener('tus-server.upload.complete', function(\TusPhp\Events\TusEvent $event) { // Get path of uploaded file $file_path = $event->getFile()->getFilePath(); // Add uploaded file to "files" field on Home page $p = wire('pages')->get(1); $p->of(false); $p->files->add($file_path); $p->save('files'); }); // Send response $response = $server->serve(); $response->send(); // Exit from current PHP process // Could probably use PW halt here as an alternative // return $this->halt(); exit(0); 3. Create a page using the template - in this example the page is at url http://1testing.oo/uppy/ 4. Add the Uppy assets, JS and markup to the template of the front-end page that you will upload files from. Markup Regions are used in this example. <pw-region id="scripts"> <script src="https://transloadit.edgly.net/releases/uppy/v1.4.0/uppy.min.js"></script> <script> const uppy = Uppy.Core({debug: true, autoProceed: false}) .use(Uppy.Dashboard, {target: '#uppy-box', inline: true}) .use(Uppy.Tus, {endpoint: 'http://1testing.oo/uppy/', limit:10}); </script> </pw-region><!--#scripts--> <pw-region id="stylesheets"> <link href="https://transloadit.edgly.net/releases/uppy/v1.4.0/uppy.min.css" rel="stylesheet"> </pw-region><!--#stylesheets--> <div id="body"> <div id="uppy-box"></div> </div><!--#body--> 5. Upload files via the front-end and see that they are added to the "files" field on the Home page.
  11. I always use the "Server directory" option because I'm using the profiles locally and so there's no point in an extra zipping/unzipping stage. So could be a bug with the ZIP export option.
  12. This part is optional - it's exists in case you want your server endpoint to be something pretty like http://yourdomain.com/files/ But if it's causing you a problem you can leave out the tus-php .htaccess and set your endpoint to http://yourdomain.com/server.php or whatever with no rewrite needed.
  13. You can simplify that a bit to this... $classname = $event->arguments[0]; if($classname !== $this->className) return; // Only continue if settings of this module are being saved.
  14. Ryan's ProcessExportProfile module includes ready.php in the exported files. Based on your other comment, I think there may have been an error during the export process because I frequently install profiles exported by this module without any problems.
  15. This is why I think we need a field aliases feature. I have a working module that allows the use of field aliases anywhere in template files and in /site/ready.php and /site/init.php, but issues with the File Compiler need to be fixed before the module can be released.
  • Create New...