Jump to content

Robin S

Members
  • Posts

    4,928
  • Joined

  • Days Won

    321

Everything posted by Robin S

  1. You have the whole API available to you for module development. The examples above are not specific to modules, but are methods of the Wire class. https://processwire.com/api/ref/wire/message/ https://processwire.com/api/ref/wire/error/ My go-to pages for module-specific info are: https://processwire.com/api/ref/module/ https://processwire.com/blog/posts/new-module-configuration-options/
  2. Sounds like a job for the API Delete fields by name: <?php $field_names = ['field1', 'field2', 'etc']; foreach($field_names as $field_name) { $field = $fields->get($field_name); $fields->delete($field); echo "Deleted field '{$field->name}'<br>"; } Or maybe delete all unused fields: <?php foreach($fields as $field) { if( count($field->getFieldgroups()) === 0 ) { $fields->delete($field); echo "Deleted field '{$field->name}'<br>"; } } Or you could make a form displaying checkboxes for each unused field and select which to delete, similar to what @diogo does here for templates.
  3. Glad you got it working. The sub-selector docs are here but I'm sure you found them by now.
  4. Thanks for the info. Seems that this affects all new map applications and existing applications (like mine) are grandfathered.
  5. If you mean the message in your browser console I think it's just a warning rather than an error. I'm using the Map Marker module without an API key and it's working fine.
  6. Maybe $pages->getById() is the way to go. $my_pages = $pages->getById([1086,1021,1053,1018]);
  7. Here is another way you can get your repeater items, by first finding the pages those repeaters are on. Not tested. <?php // sanitized input $types = $sanitizer->selectorValue($input->get->type); $patterns = $sanitizer->selectorValue($input->get->pattern); $designers = $sanitizer->selectorValue($input->get->designer); $colours = $sanitizer->selectorValue($input->get->colour); // selector $selector = "template=template_with_repeater_field, collections_detail_images.count>0, sort=title"; if ($types != "all") $selector .= ", collections_detail_type=$types"; if ($patterns != "all") $selector .= ", collections_detail_pattern=$patterns"; if ($designers != "all") $selector .= ", collections_detail_designer=$designers"; // here we make sure we only find pages that have the right colour in one of their repeater items if ($colours != "all") $selector .= ", collections_detail_images=[collections_detail_image_colour.collections_colours_group=$colours]"; $results = $pages->find($selector); include './collections-filters.inc'; // not sure what this does ?> <?php if(count($results)): ?> <div class="container-fluid"> <div class="row"> <div class="fabric-list-container collections-results all"> <?php foreach($results as $result) { $fabrics = $result->collections_detail_images; $fabrics->sort("collections_detail_image_colour"); if($colours != "all") { $fabrics->filter("collections_detail_image_colour.collections_colours_group=$colours"); } foreach($fabrics as $fabric) { include './fabrics-list.inc'; } } ?> </div> </div> </div> <?php endif; ?> Another thought: seeing as you want to do all this stuff with your repeater items outside the context of them being fields in another page maybe repeaters are not the ideal mechanism for your data. Could these repeater items instead be normal pages, related to their 'get-for' pages either via a parent-child relationship or via a Page field in the collections_detail_images pages? You can make the collections_detail_images pages easy to add by including them in the "Add New" menus.
  8. Maybe I'm not understanding you right, but can't you search for pages that contain the repeater fields and then get the repeater items for those pages? I think (based on the code you showed in this thread) that the fields you are filtering and sorting on are fields in the get-for page rather than fields that are necessarily inside the repeater items so it seems like what you want to be finding are the get-for pages. Another general idea that might be useful: if you look at the page structure around repeaters in the Admin section of the tree you see that the repeaters parent name is "for-page-1234" where 1234 is the id of the page the repeater is on. So if you want to search for repeater items directly with a $pages->find() you could first construct an array of parent page names to use in the selector. Something like: <?php $get_for_ids = $pages->find("foo=bar")->each("id"); $parent_names = array_map( function($item) {return "for-page-$item";}, $get_for_ids ); $parent_names = implode('|', $parent_names); $repeater_items = $pages->find("template=repeater_my_repeater, parent.name=$parent_names");
  9. See the screenshots below for a demo of how the Inputfield Selectize module can be used with getForPage()... Page with repeater field Page field using Inputfield Selectize Page field options (note: I'm recycling an existing 'headline' field as the attribute in the repeater) Edit: I'm a big fan of the new Inputfield Selectize, but if you want to use one of the other Page inputfields then have a read of this post - you'll see how the code could be adapted to use getForPage().
  10. I don't have much experience with the PW3 front-end editing features, but this seems to work: <?php $heading_field = $page->headline ? 'headline' : 'title'; $content .= "<h1>$page->edit($heading_field)</h1>";
  11. I think your question relates more to how PW sorts PageArrays created via find() rather than Hanna Code specifically. I guess you are doing something like this in your PHP: $my_pages = $pages->find("id=1086|1021|1053|1018"); I was surprised to discover, as you did, that the resulting PageArray does not sort the pages in the order the IDs were given. This is what I came up with as a workaround: $my_ids = [1086,1021,1053,1018]; $my_pages = new PageArray(); foreach($my_ids as $id) { $my_pages->push($pages($id)); } I'd be keen to hear if there is a better way to get pages into a PageArray while maintaining a given order of page IDs.
  12. Ah, I see. If these values are being stored only for the purposes of displaying in the Page inputfield you could combine them into a single field in the repeater. Or potentially avoid the need for this hook by using the Inputfield Selectize module:
  13. This isn't a direct answer to your issue, but do you actually need this hook? It looks like you want each repeater item to store some values from the page the repeater field is on (the "for-page"), but this seems like unnecessary duplication. Can't you just get the values from the for-page once and output it wherever needed? If you want the value from inside a loop that is outputting repeater items you can use getForPage(), but chances are you already have the for-page in another variable (e.g. $page). So in your template: <?php $type = $page->collections_detail_category->name; // similarly for other values foreach($page->collections_detail_images as $collections_detail_image) { // do what you want with $type, and any other repeater item fields }
  14. Not sure this is the right place to report this, but I noticed that the "Related Forum Threads" links in the documentation for the Images fieldtype are broken.
  15. I think you want <img src="<?php echo $config->urls->templates ?>images/b1.jpeg"> or with short syntax <img src="<?= $config->urls->templates ?>images/b1.jpeg"> And to be honest, I usually hard code the paths to my template images. <img src="/site/templates/images/b1.jpeg">
  16. That would be a nice feature. I'm a strong believer in the benefits of minimising mouse usage. In the meantime... I'm not sure if this is a Windows or a Firefox thing, but if I click the select box and then start typing the highlight moves accordingly. So it's almost like an autocomplete. One catch is that you can't see the highlight on disabled items (i.e. those fields that are already added to the template) but you can type a letter or two and then use the arrow keys to complete the selection.
  17. This seems to me to be pretty comprehensive: https://processwire.com/api/ref/module/ Also useful: https://processwire.com/blog/posts/new-module-configuration-options/ And there's good stuff in the Helloworld.module I'm learning development myself and so I understand how it can be challenging to tackle something more advanced like module development. But I think you also need to bear in mind that many of the things that need to be understood in order to build a module are not PW-specific but are actually require knowledge of PHP and object-oriented programming. We can't expect the PW docs to give us all of this on a plate.
  18. mod_security blocks processing based on regex rules: exactly what rules are implemented is up to the host or the person configuring the module. Perhaps your page contains a string that matches some overly-broad regex rule. The intention behind mod_security is good but my experience has been that running the module results in many false-positives and the resulting problems are difficult to debug. On many hosts you can't even tell when mod_security has been triggered. My shared hosting enables it by default on every new account but I always disable it to avoid headaches.
  19. If your host is running mod_security that might be the culprit. I've struck odd issues like this before that were resolved by disabling mod_security.
  20. Great job on the new forum @Pete. Is there an account setting I can apply so replies in a Q&A thread are sorted by date by default? I find it hard to follow the conversation when they are sorted by rating and don't want to have to change the sort order manually for every thread.
  21. A like is not enough! This is just awesome and opens up so many possibilities for page inputfield UI. :)
  22. If you don't want to upgrade to ProCache v3 there are some htaccess settings shared by WillyC here.
  23. It works okay for me with PW 3.0.21. Not sure why it's not working for you but as an alternative you could use: $users->get($page->settings->created_users_id)->name $users->get($page->settings->modified_users_id)->name
  24. Echoing a comment above... In the image field 'list' view the size difference between landscape-format and portrait-format images can be extreme. In the screenshot below the two images have the same aspect ratio but the portrait-format is rendered much larger. Wouldn't it be better to define the thumbnail container as a square with the thumbnail centered and fitted to the container? Then each image row is an equal height.
  25. I solved this - it was due to a module of mine in which I use the admin image thumbnails. I just needed to adjust the module code to account for the new default thumbnail height of 260px.
×
×
  • Create New...