Jump to content

Robin S

  • Content Count

  • Joined

  • Last visited

  • Days Won


Everything posted by Robin S

  1. The notes on the Settings tab of Page Edit are a good summary of what the statuses mean: Hidden and unpublished pages are both excluded from selectors (unless you override this) - the difference is that a hidden page is viewable if the URL is known, whereas an unpublished page cannot be viewed unless the user is logged in and has edit access for the page.
  2. A RepeaterPageArray is a type of WireArray so it should work as is. And it's working for me so double-check your code (e.g. invisible characters from forum copy/paste).
  3. This is when you gotta do some debugging. Some things to try... Set $config->debug to true to make sure you are seeing error messages. Install Tracy Debugger - the debug bar is great at catching error/warning messages that debug mode sometimes misses. Dump $items with Tracy Debugger to see if there's actually any pages in there: bd($items); Not sure if the line of code you showed is just a demo or your real code, but 111 is not going to be the ID of a front-end page because these start at 1000. Welcome to the forums BTW 🙂
  4. Hi @Soma, Could you please add this very useful module to the PW modules directory? Thanks!
  5. Using the brand new "multiple methods" hook feature in PW 3.0.137 you could save the average stars value to a decimal (or float) field every time a comment is approved/disapproved/updated/deleted. Then you can find or sort pages by the field more efficiently. The hook below assumes a comments field named "comments" and a decimal field named "decimal": $wire->addHookAfter('FieldtypeComments::commentApproved, FieldtypeComments::commentUnapproved, FieldtypeComments::commentDeleted, FieldtypeComments::updateComment', function(HookEvent $event) { /* @var Page $page */ $page = $event->arguments(0); /* @var Field $field */ $field = $event->arguments(1); if($field->name !== 'comments') return; if($page->template->hasField('decimal')) { // Save the average star rating for comments with approved or featured status $page->setAndSave('decimal', $page->comments->find("status=1|2")->stars(true)); } }); P.S. You'd do a one-off API operation to save the average stars value for all your existing comments to get things set up initially.
  6. Here's a slightly different approach. Assumes an image field named "images" and a CKEditor field named "body". foreach($page->images as $image) { // Get the image URL excluding the file extension (to account for image variations) $match_url = substr($image->url, 0, -strlen($image->ext)); // Skip the image if the match URL occurs at the start of a src attribute in $page->body if(strpos($page->body, "src=\"$match_url") !== false) continue; // Output the image or whatever echo "<img src='{$image->width(300)->url}' alt='$image->description'>"; }
  7. It's working as expected for me. You're not including the quote marks around the value by any chance are you? If -10:+10 is actually the value you want you can leave the setting empty because that is the default.
  8. As stated in the module readme, FieldtypeYaml uses a namespaced version of Spyc. And the examples for Spyc show how to dump an array to YAML: https://github.com/mustangostang/spyc/blob/master/examples/yaml-dump.php So to reproduce that example using the namespaced Spyc bundled with FieldtypeYaml: // Init the module so Spyc gets loaded $modules->get('FieldtypeYaml'); // Some array data $array[] = 'Sequence item'; $array['The Key'] = 'Mapped value'; $array[] = array('A sequence','of a sequence'); $array[] = array('first' => 'A sequence','second' => 'of mapped values'); $array['Mapped'] = array('A sequence','which is mapped'); $array['A Note'] = 'What if your text is too long?'; $array['Another Note'] = 'If that is the case, the dumper will probably fold your text by using a block. Kinda like this.'; $array['The trick?'] = 'The trick is that we overrode the default indent, 2, to 4 and the default wordwrap, 40, to 60.'; $array['Old Dog'] = "And if you want\n to preserve line breaks, \ngo ahead!"; $array['key:withcolon'] = "Should support this to"; // Dump to YAML with some (optional) custom indent and wordwrap settings $yaml = \owzim\FieldtypeYaml\Vendor\Spyc::YAMLDump($array,4,60); // See the result in a Tracy dump bdb($yaml, 'yaml'); You can convert a WireArray to a plain array with getArray().
  9. There are a couple of different questions here. Check if saved page has errors: $wire->addHookAfter('Pages::saveReady', function(HookEvent $event) { /* @var Page $page */ $page = $event->arguments(0); // Find out if the page being saved has any errors $has_errors = $page->hasStatus(Page::statusFlagged); // Do something accordingly... }); You can set custom error messages as follows. This is for a text inputfield - adjust to suit the type of inputfield in question: $wire->addHookAfter('InputfieldText::processInput', function(HookEvent $event) { /* @var InputfieldText $inputfield */ $inputfield = $event->object; $field = $inputfield->hasField; // Return early if the field name doesn't match if(!$field || $field->name != 'text_1') return; // If some condition is or isn't met if($inputfield->value && $inputfield->value !== 'foo') { // Show an error for the inputfield $inputfield->error('The value of this field must be empty or foo'); // Maybe clear the inputfield value $inputfield->value = ''; } });
  10. I think it's a bug and I've opened an issue here: https://github.com/processwire/processwire-issues/issues/956 Regarding different CKEditor configs per Repeater Matrix type, Ryan has suggested some code in a recent topic in the ProFields forum:
  11. Not sure why this means URL segments can't be a solution. You hook Pages::added and put the title through $sanitizer->pageName and save it to a hidden field (full_page_name). Then in the parent page template you check the URL segment against full_page_name and render any matching page (and throw a 404 if none found). For URLs to the pages you hook Page::path as per Ryan's case study and concatenate full_page_name to the parent URL.
  12. If you are looping over the whole PageArray then the sort position is the key (zero indexed). foreach($items as $key => $item) { echo "$item->title - sort position is $key"; } If you want to get individual pages from the PageArray and know their sort position you can first loop over the PageArray and save the sort position to a custom property on each page. foreach($items as $key => $item) { $item->sort_position = $key; } $one = $items->get("foo=bar"); echo "$one->title - sort position is $one->sort_position";
  13. @gmclelland, thanks for the report, should be fixed in v0.1.1.
  14. Okay, I see where you are going wrong. You need to enable pagination for the template that is listing the results, not for the template of pages you are getting in your find() selector.
  15. Are you 100% sure you have "Allow Page Numbers" checked in the template settings? Your links should be like "/page2/". A link like "?page=2" and the same results on every pagination is usually a sign that page numbers have not been enabled for the template.
  16. Thanks for taking on this module @teppo. A couple of minor styling observations with the Uikit theme... The spacing around the buttons is a little inconsistent. And to my eye the triangle that indicates the active button feels like it's off-centre, because the icon feels like it is separate to the word rather than them both making up a single visual unit. So for the Uikit theme I'd be inclined to centre the active marker on the word alone rather on icon + word. For pages where some buttons are not available... When "Edit" is not available the button text changes (the full stop looks out of place here), but when "New" is not available the button text is gone but the icon remains. Not sure but maybe unavailable buttons should not render at all?
  17. You could update to the latest dev. Support for empty data attributes was added in this commit.
  18. of() is a method of Page objects, but you're trying to use it on an PageArray of Repeater pages. Try: // Get the page you want to work with $home = $pages->get("template=home"); // Turn output formatting off for the page $home->of(false); // Change the Repeater field value $home->submissions->removeAll(); // Save the page $home->save();
  19. From past experience working with lat/lng coordinates, I suggest using a decimal field for these. Float fields only have a precision of 6 figures which is often not sufficient for a lat/lng value.
  20. Does the module need to read data back from the external database and display it in an interface for editing, or is PW only used for creating new data and inserting it into the database? Because if it's the latter you could still use Page Edit as the interface for data creation. You'd use a saveReady hook to get, prep and insert the data from the page into the external database, then clear out the page ready for new data. Maybe you'd add an extra submit button to Page Edit ("Send to database") so that the normal save buttons can be used to temporarily save data locally and only the "Send" button finally inserts and clears the data when the user is ready.
  21. A client hired a security consultant to do a site analysis and they advised that the X-Content-Type-Options HTTP header should be set to "nosniff". The MDN docs for this header say: "Site security testers usually expect this header to be set." https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options This was easily resolved by adding the following to .htaccess Header set X-Content-Type-Options "nosniff" Do you think it would be good to add this to the default PW .htaccess file?
  22. Why not use pages and proper Fieldtype fields to store the data? Seems like it would be much easier, and anything out-of-the-ordinary that you want to show within your Process module you could show within Page Edit by hooking the render of a markup inputfield, or by using one of the runtime field modules from kongondo, bernhard, kixe, or me.
  23. There is some code and some links to explore in this post:
  24. Try: $wire->addHookAfter('Field::getInputfield', function(HookEvent $event) { $page = $event->arguments(0); $inputfield = $event->return; // Only for non-superusers if($event->wire('user')->isSuperuser()) return; // Only for a particular Repeater page ID if($page->id !== 1553) return; // Set collapsed to Inputfield::collapsedNoLocked or Inputfield::collapsedHidden as suits $inputfield->collapsed = Inputfield::collapsedNoLocked; });
  • Create New...