Jump to content

Robin S

Members
  • Content Count

    3,501
  • Joined

  • Last visited

  • Days Won

    201

Everything posted by Robin S

  1. You're nearly answering your own question there. The key is the position number in the field (zero-indexed like all arrays). Using this field as an example... The key is the position:
  2. You're right - it doesn't work because the selected pages are lost after save. I remember now that there was an issue with how InputfieldPage and FieldtypePage interpret "page.some_field" when it is used to refer to another Page Reference field: https://github.com/processwire/processwire-issues/issues/479 The thing is that PW has to make some consistent evaluation of what "page" is in this circumstance and it can't really know whether you want page to refer to the edited page or the repeater page. I don't have much time right now but I might come back and explore this more later.
  3. No, but I posted a hook for using the hidden JS max filesize validation for File fields: I'm not sure if this validation is used for Image fields. Another hook that could be used to check the filesize after an image is uploaded: $wire->addHookBefore('InputfieldImage::fileAdded', function(HookEvent $event) { /* @var Pageimage $image */ $image = $event->arguments(0); $max_filesize = 150000; if($image->filesize > $max_filesize) { throw new WireException("Image $image->basename is $image->filesize bytes which exceeds the maximum of $max_filesize bytes."); } });
  4. The dependent selects feature has only ever worked with the selector string option as far as I know.
  5. I had a play around and this hook seems to do the job: Edit: the hook doesn't work because the selected pages are lost on page save. Maybe related to the discussion in this issue. $wire->addHookBefore('InputfieldPage::render', function(HookEvent $event) { /* @var InputfieldPage $inputfield */ $inputfield = $event->object; $page = $inputfield->hasPage; $field = $inputfield->hasField; // Return early if inputfield is not in a Repeater page if(!$page instanceof RepeaterPage) return; $selector = $inputfield->findPagesSelector; // Return early if no selector or selector doesn't include a dependency if(!$selector || strpos($selector, '=page.') === false) return; // Get suffix added to inputfields in this Repeater page $suffix = str_replace($field->name, '', $inputfield->name); // Add the suffix to dependency inputfield names $selector = preg_replace('/(=page.[_a-zA-Z0-9]+)/', "$1{$suffix}", $selector); // Replace the original findPagesSelector $inputfield->findPagesSelector = $selector; }); Demo... Page tree: Selector string for Subcategory field: Page Edit:
  6. LOVE the new module! I'm adding this to every site for sure. 🙂 In terms of alternatives, besides the SystemNotifications module mentioned in the post there is also Page Edit Soft Lock, but UserActivity is more powerful. A question: is it possible to use this module via the API to find all users currently logged in by role? Something like (pseudo-code): $logged_in_editors = $userActivity->findLoggedIn("role=editor"); I think that could be useful. Thanks @ryan!
  7. @DV-JF, I thought that this module was too "minor" to belong in the modules directory, but I get that it makes it easier to find, install and update so I've added it now. It should get validated and appear in the directory soon.
  8. There is already a feature similar to this - it's the "Name format for children" setting on the template of the parent page. https://processwire.com/docs/modules/guides/process-template/ ID is not one of the supported options, but if you want the page to be named with the ID you can install @kixe's module which extends the functionality of this feature. http://modules.processwire.com/modules/process-setup-page-name/ Or you can enter something like a date format ("Y/m/d H:i:s") in the core "Name format for children" setting, which allows you to skip the Page Add step. And then set the page name and title to the ID with a hook in /site/ready.php: $pages->addHookAfter('added', function(HookEvent $event) { $page = $event->arguments(0); if($page->template == 'your_child_page_template') { $page->setAndSave([ 'name' => $page->id, 'title' => $page->id, ]); } });
  9. The thing to remember is that this setting is called the "Formatted value", i.e. the value when output formatting is on. When output formatting is off the value of an image field is always a WireArray. And in your code, you specifically turn output formatting off before you work with the field (as you must). If you treat the image field value as an array I think it will work as expected. Something like: $page->of(false); $page->photo->removeAll(); $page->photo->add('https://example.com/img.jpg'); $page->save(); $image = $page->photo->last(); $image->textfield = 'Some text'; $page->save();
  10. See the docs to understand the difference between $pages->get() and $pages->find(): https://processwire.com/api/ref/pages/get/ https://processwire.com/api/ref/pages/find/ You want $pages->find(). And you only want to execute it once and use $results for both the results list and the pagination. $results = $pages->find("template=product, limit=10"); // Results list foreach($results as $result) { // Output each individual result // ... } // Pagination echo $results->renderPager(array( 'nextItemLabel' => 'Volgende', 'previousItemLabel' => 'Vorige', 'currentItemClass' => 'active' ));
  11. @Kiwi Chris, I think you want to make use of Inputfield::hasPage in this case. $wire->addHookAfter('InputfieldPage::getSelectablePages', function(HookEvent $event) { /* @var InputfieldPage $inputfield */ $inputfield = $event->object; $field = $inputfield->hasField; $edited_page = $event->arguments('page'); $page_containing_inputfield = $inputfield->hasPage; // a Repeater page in your case if($field->name === 'pageBatch') { // Use $page_containing_inputfield as needed here // ... } });
  12. This was fixed in 3.0.144: https://github.com/processwire/processwire-issues/issues/1027
  13. What we're discussing is a feature request rather than a bug to report, and there already is the feature request I linked to in my earlier post. I've added a comment linking to this thread but like all such things Ryan will just get to it when he gets to it. This is feature request 13 of 269 and counting. 😉
  14. If I use Tracy to do a test dump in FieldtypePage::wakeupValue (which is where the stored IDs are loaded into a PageArray) then it seems that this method executes regardless of the visibility of the field in Page Edit. And it's not Page Edit that's the main problem anyway. If you have a field then presumably you want to work with that field, but whenever you do... $page->my_pr_field ...then all the pages are loaded to memory. So for instance if you want to add a page via the API... $page->my_pr_field->add($p) ...then you are automatically loading all the pages to memory. @bernhard's suggestion and @teppo's module are good workarounds but I think it's important to get a core solution to this. PW has an "everything is a page" philosophy, so pages can be any unit of data, not necessarily a viewable page of content. And Page Reference fields are the fundamental way to make connections between pages in PW. So when you have thousands of pages that need to have connections to thousands of other pages then you have to start looking beyond the core fieldtypes which is a limitation for PW. Sometimes you can do what @wbmnfktr suggested and reverse the connection, putting the PR field in the other template to reduce the number of pages stored per field. But this isn't always possible. In terms of concrete examples, imagine you were using PW to build some kind of Spotify-like database that tracks users' listening habits. There could be thousands of users who listen to thousands of songs, so either way you cut it you want to store thousands of pages in a PR field.
  15. I can't reproduce that here. If you insert an image without the caption checkbox checked then the plugin inserts an image with the class applied and doesn't insert a wrapping figure element. <p><img alt="" class="align_right" src="/site/assets/files/1/colin-watts-1141600-unsplash.300x0-is.jpg" width="300" />Lorem ipsum dolor sit amet, adipiscing elit. Nullam dignissim convallis est. Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui.</p> If you insert an image with the caption checkbox checked then the plugin inserts a figure + img + figcaption with the class applied to the figure element. <figure class="align_right"><img alt="" src="/site/assets/files/1/colin-watts-1141600-unsplash.300x0-is.jpg" width="300" /> <figcaption>Your caption text here</figcaption> </figure> <p>Lorem ipsum dolor sit amet, adipiscing elit. Nullam dignissim convallis est. Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui.</p> Something to be aware of is that if you change the alignment classes for Page Edit Image from their defaults you need to allow those classes in the Extra Allowed Content setting for the CKEditor field. img figure(is-pulled-left,is-pulled-right) It would be better if the class names configured in Page Edit Image were automatically allowed - there's an open issue about this: https://github.com/processwire/processwire-issues/issues/800
  16. @AndZyk, a Page Reference field doesn't scale well because all pages are loaded into memory and there is no ability to limit the loaded pages or paginate the inputfield in admin. Back in 2016 Ryan said it was likely that pagination would be added to several core fieldtypes but it hasn't happened yet: https://processwire.com/blog/posts/fieldtype-pagination/ The Page Reference fieldtype/inputfield is the one that would benefit the most from this. I have an open request for this that you could add your voice to: https://github.com/processwire/processwire-requests/issues/13
  17. See the module config for Page Edit Image (which is the Process module used by the PWImage plugin):
  18. Yes. If you want the hook to apply to a specific Lister Pro instance instead of a bookmark you could do this: $wire->addHookBefore('ProcessPageLister::execute', function(HookEvent $event) { /* @var ProcessPageLister $lister */ $lister = $event->object; // If executing a specific Lister Pro instance if($event->wire('page')->name === 'your-lister-page-name') { // Find the templates that contain the meta_title field $tpls = new TemplatesArray(); foreach($event->wire('templates') as $template) { if($template->flags) continue; // Skip system templates (e.g. repeater templates) if($template->fieldgroup->has('meta_title')) $tpls->add($template); } // Set the defaultSelector for the Lister $lister->defaultSelector = "template=$tpls, meta_title=''"; } });
  19. @cst989, here is one way you could do it. First create a new Lister bookmark with the columns and sorting set the way you want. It doesn't matter what you set in the filters because we are going to override that in a hook. Take note of the bookmark ID in the URL when you view the bookmark in Lister. Now add the following hook to /site/ready.php, updating the bookmark ID to suit: $wire->addHookBefore('ProcessPageLister::execute', function(HookEvent $event) { /* @var ProcessPageLister $lister */ $lister = $event->object; $bookmark = $event->wire('input')->get('bookmark'); // If executing your specific bookmark if($bookmark === '_1574293851') { // Find the templates that contain the meta_title field $tpls = new TemplatesArray(); foreach($event->wire('templates') as $template) { if($template->flags) continue; // Skip system templates (e.g. repeater templates) if($template->fieldgroup->has('meta_title')) $tpls->add($template); } // Set the defaultSelector for the Lister $lister->defaultSelector = "template=$tpls, meta_title=''"; } });
  20. Also, take a look at the WireHttp docs, particularly WireHttp::getJSON() - this method can make your code more streamlined. 🙂
  21. JSON is just a string so you can save it to $session as a string: Or you could decode the JSON to an associative array and then save that array to session. The core wireDecodeJson() function is a handy shortcut to force the JSON to decode as associative arrays rather than objects.
  22. Have you looked at the $session documentation? If so is there a specific problem you're having?
  23. It's unlikely the browsers themselves are making the difference here. Probably you are logged into the PW admin in Chrome but not in the other browsers. So your problem is due to some access restriction on page/template "b".
  24. It works for me, so double-check your code. Another way you can find related templates is to apply a tag to them in the admin (Advanced tab). Then you can find the templates that have that tag and find pages using those templates. // Find templates with tag "foo" $tpls = $templates->find("tags=foo"); // Find pages using those templates $items = $pages->find("template=$tpls");
  25. Try: // Set filename manually $filename = $config->paths->templates . 'lvl04-post.php'; // Or get filename from one of the templates that uses it // $filename = $templates->get('lvl04-post')->filename; // Find templates that use this template file $tpls = $templates->find("filename=$filename"); // Find pages using those templates $posts = $pages->find("template=$tpls, limit=5");
×
×
  • Create New...