Jump to content

Robin S

Members
  • Posts

    4,365
  • Joined

  • Last visited

  • Days Won

    265

Robin S last won the day on May 1

Robin S had the most liked content!

Profile Information

  • Gender
    Male
  • Location
    New Zealand

Recent Profile Visitors

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

Robin S's Achievements

Hero Member

Hero Member (6/6)

8.3k

Reputation

17

Community Answers

  1. Then you'll want to get the PageArray of selectable pages as shown in the earlier hook: $selectable_pages = $page->getInputfield('your_page_reference_field')->getSelectablePages($page); Then you can use ->eq() to get any item in the PageArray by its index/position, and use a switch statement to do different things accordingly. // Get all the selectable pages that apply when "your_page_reference_field" is used on $page $selectable_pages = $page->getInputfield('your_page_reference_field')->getSelectablePages($page); // Compare the value of $page->your_page_reference_field against the pages in various positions of $selectable_pages switch($page->your_page_reference_field) { case $selectable_pages->eq(0): // The first selectable page is selected require ('assets/bookingstatus/bookingstatus_step1.inc.php'); break; case $selectable_pages->eq(1): // The second selectable page is selected require ('assets/bookingstatus/bookingstatus_step2.inc.php'); break; case $selectable_pages->eq(2): // The third selectable page is selected require ('assets/bookingstatus/bookingstatus_step3.inc.php'); break; default: // Some other page is selected so handle that scenario... }
  2. First have a look at the docs for eq(): https://processwire.com/api/ref/wire-array/eq/ This method works on a WireArray/PageArray and returns the item at the given position. So the object you call the method on needs to be a WireArray/PageArray but you are calling it on a Page object (probably your booking_status field is a "single" Page Reference field so its value when populated will be a Page). It's not clear to me what you're trying to do in that part of your code, but if you want your if() test to mean "if the booking_status field is not empty" then you would do something like this: if($bookingstatus->booking_status->id) { //... } Or if you want to check if the value of the booking_status field value equals some page then you would do something like this: // Get $some_page however you like $some_page = $pages->get('/path/to/page/'); // Check if the booking_status field value equals $some_page if($bookingstatus->booking_status === $some_page) { //... }
  3. It doesn't make sense to put the parent path in a check against the page template, but you can check the parent path separately: if($page->template != 'booking') return; if($page->parent->path !== '/nya-bokningar/') return; // The rest of your hook code...
  4. If you want to pre-set the third option within the selectable pages: $wire->addHookAfter('Pages::added', function(HookEvent $event) { $page = $event->arguments(0); // Only for the booking template if($page->template != 'booking') return; // Get all the selectable pages for the field $selectable_pages = $page->getInputfield('booking_searchactivator_option')->getSelectablePages($page); // Get the third selectable page (the numbering is zero-based) $third_selectable_page = $selectable_pages->eq(2); // Set the third selectable page as the field value $page->setAndSave('booking_searchactivator_option', $third_selectable_page); });
  5. Wow, what an awesome list of improvements! @ryan, I have a question about the lazy-loading of fields. Do you think this change means that the previous recommendation to reuse fields, as in the "Making efficient use of fields in ProcessWire" blog post, is now no longer needed? Say I am using text fields in lots of different templates for different purposes, and if I create and name fields so they describe the use in each template I will have 50 text fields, or if named them generically and reused them I would have maybe 5 text fields. Is their any reason now to prefer the 5 fields option over the 50 fields option, given that in any one template I'll only have 5 text fields or less and so presumably only ~5 or less fields get fully loaded at a time?
  6. In the template code for your website footer you can add something like this: <?php if($page->editable()): ?> <a target="_blank" href="<?= $page->editURL ?>">Edit this page</a> <?php endif; ?> This will give logged-in users who have permission to edit the page a link to open the page in Page Edit, and you can work out its location, template, etc, from there. Or if you have Tracy Debugger installed you can run the following in the Console panel while viewing the page on the frontend and the edit link will appear in the console output: <a target="_blank" href="<?= $page->editURL ?>">Edit this page</a>
  7. If you are currently using "Page List Select" as the inputfield type you'll want to change to different inputfield type because that inputfield doesn't support limiting selectable pages by anything other than parent. This is explained in the field settings:
  8. Try instead: template=faq-category, parent=page.parent.parent, sort=sort
  9. @DrQuincy, when using $this->halt() I think it has to be return $this->halt() or else you still get the subsequent template output. Template file: Output: Template file: Output:
  10. I think person 2 sees page B in 2 seconds. I did a kind of test... I have two pages and two templates: page "Yellow" uses template "colour" and page "A Basic Page" uses template "basic_page". There's nothing special about the template file for basic_page but in the template file for colour I have: sleep(30); If I load page Yellow in one tab and then immediately load A Basic Page in another tab then I have to wait 30 seconds to view either page. But if I load page Yellow in one tab and then immediately load A Basic Page in an incognito window (which will have a different session) then the page loads immediately.
  11. You can do a find() but with a limit of 1. This will be just as efficient as findOne(), the only thing is that it will return a PageArray so use first() to get the item as a Page. $results = $pages->find("template=template-news, sort=created, limit=1, start=1"); if($results->count) { $title = $results->first()->title; }
  12. Yes, it will break. I gave the link to the blog post introducing "owner" selectors in the code, but here it is again: https://processwire.com/blog/posts/processwire-3.0.95-core-updates/ So this selector... template=colour, select_colour.owner.template=animal, select_colour.owner.id!=$page->id ...is saying... Match pages where: the page template is "colour" and the page is selected in a field named "select_colour" and the page containing the select_colour field is using the template "animal" and the page containing the select_colour field is not the page represented by the $page variable (i.e. the page that is currently open in Page Edit)
  13. This would be easier to explain in your context if you had included all the relevant field and template names in your post. So here is an example that you can adapt to your scenario... I have a Page Reference field named "select_colour" and generally the selectable pages are those that have the template "colour". I add this field to the template "animal", so that on animal pages I have a field to choose the colour of the animal. But in the select_colour field I only want to show colours that have not been selected on any other animal page. So in the settings for field select_colour I only use the "Custom PHP code" option for "Selectable pages" and add the following code to /site/ready.php: $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { $page = $event->arguments(0); // Define selectable pages for the select_colour field if($event->object->hasField == 'select_colour') { /** @var Pages $pages */ $pages = $event->wire()->pages; // Find colours that are already selected on another animal page using "owner" selector // https://processwire.com/blog/posts/processwire-3.0.95-core-updates/ $already_selected_on_another_page = $pages->find("template=colour, select_colour.owner.template=animal, select_colour.owner.id!=$page->id"); // Return colour pages that aren't already selected on another page $event->return = $event->pages->find("template=colour, id!=$already_selected_on_another_page"); } }); Another possible approach is to loop over all the colour pages and remove those that are referenced on another page, but this is less specific because it will remove colours that have been referenced in any field, not just the select_colour field. $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { $page = $event->arguments(0); // Define selectable pages for the select_colour field if($event->object->hasField == 'select_colour') { /** @var Pages $pages */ $pages = $event->wire()->pages; // All colours $colours = $pages->find("template=colour"); foreach($colours as $colour) { // Remove colour if any other pages are referencing it if($colour->numReferences) $colours->remove($colour); } // Return the filtered colours $event->return = $colours; } });
  14. Might be mod_security false positive.
×
×
  • Create New...