Jump to content

Robin S

Members
  • Posts

    5,034
  • Joined

  • Days Won

    340

Everything posted by Robin S

  1. It's possible, but not as simple as it should be because it seems that the option() method of Datepicker (and Timepicker) is not working for the stepMinute option. Instead it seems you have to destroy and re-init the datepicker if you change stepMinute. In some custom admin JS, for a field named "date"... // For a Datetime field named "date" with time enabled $('#Inputfield_date').on('focus', function() { // Get the existing options for the Datetimepicker var options = $(this).datetimepicker('option', 'all'); // If the picker has the default stepMinute setting... if(options.stepMinute === 1) { // Set custom stepMinute setting options.stepMinute = 15; // Destroy picker $(this).datetimepicker('destroy'); // Re-initialise picker $(this).datetimepicker(options); } });
  2. Here's an example... The page structure: Some pet species have breed child pages and some do not. The selector string for selectable pages for the breed field is "parent=page.species". In ready.php: $wire->addHookAfter('ProcessPageEdit::buildForm', function(HookEvent $event) { /* @var InputfieldForm $form */ $form = $event->return; $breed_field = $form->getChildByName('breed'); if(!$breed_field) return; $species_with_breeds = $event->wire('pages')->find('parent=/selects/pets/, children.count>0'); $breed_field->showIf = 'species=' . $species_with_breeds->implode('|', 'id'); });
  3. See how PW determines $config->ajax here. So you may need to set the X-Requested-With header:
  4. Do you mean you tried to upload a WebP image to an Images field? If so that's not supported - the blog post explains that WebP is an output format only:
  5. It doesn't look like there is a way to keep HTML comments intact when using the core Markup Regions feature. Even if there was a way to set the "exact" option you mentioned (which there isn't currently because the Markup Regions methods aren't hookable), comments are also removed here. You could make a feature request at GitHub for an option to keep HTML comments.
  6. There is a honeypot option. There's a JS-based approach that goes back a long time... ...and a more recent addition... https://github.com/processwire/processwire/commit/8405c586f03a2a0a6271b5edd5ba9361f768da6a
  7. @Zeka, you can hook before any Process execute method that the user has access to and replace the output. You can see an example here where I replace ProcessLogin::executeLogout (because that is something that all users have access to). I like the sound of @elabx's suggestion of adding a new execute method and accessing the URL segment for it, but with some quick testing I couldn't get that to work. But that's probably just me.
  8. Ah right, unfortunately AdminThemeUikit::renderBreadcrumbs() returns early unless some protected class properties are set, and there is no setter method provided. It's a shame that AdminThemeUikit wasn't designed with flexibility for customisation in mind, because it means that users like yourself have to create a totally separate theme that duplicates almost the entirety of the AdminThemeUikit code just to achieve a few minor changes. It would have been nice if something like Markup Regions could have been employed in the theme template files. But it looks like there's no better way for now, so I've merged your PR.
  9. Some thoughts... What about any auto-prepended _init.php and/or auto-appended _main.php - any code in there that would impact performance? Bear in mind that the PW debug mode and Tracy Debugger have their own memory usage, DB queries, etc. The Tracy overhead in particular could vary a lot depending on what panels are in use. To get a fair comparison across the EE and PW sites on the server you should disable PW debug mode and Tracy and use some consistent performance measurement technique/tool on both sites.
  10. Thanks @flydev, but that solution feels less than ideal - I think there is a better way. If you want to implement the AdminThemeUikit breadcrumbs in your custom theme (which you would have to in order for the Breadcrumb Dropdowns module to work) then you can just call AdminThemeUikit::renderBreadcrumbs() because it is a public method. So in your custom theme template files where you want to output the breadcrumbs you can do something like this: echo $modules->get('AdminThemeUikit')->renderBreadcrumbs();
  11. In theory yes, but in practice you will hit PHP memory and timeout limits at some point. Just try it and see how you get on.
  12. Probably one of the $sweepstake_children doesn't have any images. Probably best not to rename the images within the page because that results in the loss of potentially useful filename data and would break any links to the images within CKEditor fields. Instead you could copy the files to a temporary directory, renaming them in the process, then create the zip and download from there. Here is some code you can adapt for your purpose: // Create temp directory $td = $files->tempDir('to-zip'); $td_path = (string) $td; $files_to_zip = array(); foreach($page->children() as $child) { $image = $child->images->first(); // Continue if no image exists if(!$image) continue; // Set path including new filename as needed $new_path = $td_path . "{$child->id}.{$image->ext}"; // Copy image to new path $success = $files->copy($image->filename, $new_path); // Add new path to array if($success) $files_to_zip[] = $new_path; } // Set destination path for zip file $zip_path = $td_path . time() . '.zip'; // Create zip file $success = $files->zip($zip_path, $files_to_zip); // Send download if($success) $files->send($zip_path); // Optionally remove temp directory now rather than waiting for it to automatically expire $td->remove();
  13. Not so long as you keep it outside of the /wire/ folder.
  14. 1. If you put your PHP file in the site root it won't be affected by the htaccess restrictions. You could also put it any other place besides those places with restricted access. 2. See the "Files" tab in the template settings: "Disable automatic prepend of file..." / "Disable automatic append of file..."
  15. When output formatting is off the value of a Images field is a Pageimages object (WireArray). So you have to do: $page->pageBanner->first()->focus(10,10);
  16. See Ryan's post here:
  17. You might find this module useful for that: https://modules.processwire.com/modules/restrict-repeater-matrix/
  18. You could create a Page Reference field that has the Repeater items as selectable pages. Hook for selectable items in /site/ready.php: $wire->addHookAfter('InputfieldPage::getSelectablePages', function(HookEvent $event) { $page = $event->arguments(0); if($event->object->hasField == 'select_repeater_item') { $event->return = $page->repeater; } }); Then create a matrix type that has this Page Reference field. But if the repeater items are to be output among the matrix items then I'm not sure why the repeater exists as a separate field. Wouldn't it be better to just have a matrix field alone and replace the repeater with a matrix type?
  19. Looks good. You could maybe simplify the first hook by using a str_replace(): $wire->addHookAfter('InputfieldPageTable::render', function (HookEvent $event) { $markup = $event->return; $markup = str_replace("&context=PageTable", "&context=PageTable&field_parent={$event->object->hasPage}", $markup); $event->return = $markup; });
  20. Yes, it is about how you build the selector. When you are dealing with input coming from a search form you usually build up the selector in a string variable $selector, adding pieces to $selector for each populated GET variable. But before you try that start with something simpler. Rather than building up a selector string dynamically, experiment with writing out different selector strings and supplying the selector to $pages->find() to see if you get back the pages you expect. The selectors documentation is here: https://processwire.com/docs/selectors/ Each "clause" you add to the selector works with AND logic by default: field_1=foo, field_2=bar This matches pages where field_1=foo AND field_2=bar. For OR logic with different fields and values, check the documentation for OR-groups. (field_1=foo), (field_2=bar) This matches pages where field_1=foo OR field_2=bar. Regarding OR conditions for multiple values in a single field, or multiple fields with a single value, see the following sections: https://processwire.com/docs/selectors/#or-selectors1 https://processwire.com/docs/selectors/#or-selectors2 When you have sorted out what kind of selector you need to match the pages you want you can move on to building up the selector dynamically according to your GET variables.
  21. Like you say, the PageTable page only belongs to the PageTable field when you save it. So you can get the container page as you save the page but not before then. Maybe this post helps: If your PageTable pages are set to be children of the container page it would be easier, but often for PageTable fields that's not the case. It's much easier to get the container page for Repeater fields, so I'd say a Repeater Matrix field is a better choice over a PageTable field for these kinds of things. If you are stuck with the PageTable field and there's no other solution then you could try something like hooking ProcessPageAdd and injecting some JS that checks for an iframe parent and gets the edited page ID from the parent URL, then saves it to a cookie or PHP session via AJAX, then you look for that page ID in the cookie/session in another hook before ProcessPageEdit. But that's hardly a straightforward solution.
  22. I've never needed to use ProcessPageClone but I would have expected the created/modified time to be set to the time the new page is cloned from the old page. Maybe there are use cases for cloning the created/modified times, so perhaps the issue could be a feature request for the option to determine what happens to created/modified times on the cloned page?
  23. Hi @stuartsa, welcome to the PW forums. ? Publishing a new page that is created via the API is not an extra action because pages are published by default. Or more accurately, they are "not unpublished" by default, because being unpublished is an extra status that you may add to a page but is not present by default. When a page is created in the admin via ProcessPageAdd it gets the unpublished status added because the expectation is that the user probably wants to populate some fields in a following step before the page becomes accessible on the front-end, and also because new pages can be added by roles with more restricted permissions than superuser. But when you add pages via the API then you are an unrestricted superuser and so it is up to you to populate the page fields and set page statuses as you see fit. Yes.
  24. Try: $result = new PageArray(); foreach($pages->getById([1049,1053,1055,1059,1152]) as $p) { $result->add($p->repeater_field->findRandom(3)); } $result->shuffle(); // Now do something with $result - foreach, etc.
  25. The status flags are bitwise so if you use a flag value directly to find published pages it would need to be like this: projects_awards.owner.status<2048 But for PageFinder selectors you can use a string for status: projects_awards.owner.status!=unpublished You would also want to exclude unpublished repeater pages because otherwise you can get unfilled "ready" repeater pages in your result. So your selector would be: template=repeater_projects_awards, projects_awards.owner.status!=unpublished, status!=unpublished, include=all
×
×
  • Create New...