Jump to content

Robin S

  • Content Count

  • Joined

  • Last visited

  • Days Won


Everything posted by Robin S

  1. 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().
  2. 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 = ''; } });
  3. 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:
  4. 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.
  5. 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";
  6. @gmclelland, thanks for the report, should be fixed in v0.1.1.
  7. 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.
  8. 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.
  9. 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?
  10. You could update to the latest dev. Support for empty data attributes was added in this commit.
  11. 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();
  12. 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.
  13. 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.
  14. 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?
  15. 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.
  16. There is some code and some links to explore in this post:
  17. 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; });
  18. When you do this you load all the children of the of the root parent into memory as a PageArray, and then you get just one of those pages. It's more efficient to directly get the single page you need: $page->rootParent()->child('template=menu_submenus, include=hidden');
  19. I suspect the image is corrupt in some way, or maybe contains some metadata, colour profile, etc, that can't be handled. Try opening this image in Photoshop or similar and then save it as a new JPG, making sure to use the standard sRGB colour profile.
  20. When you add an image via the API rather than via the inputfield you have to do all the work yourself that the inputfield would otherwise do for you. A recent answer to a similar question, which contains a link to some code that might be useful to you:
  21. v0.1.4 released. This version adds support for some new features added in Repeater Matrix v0.0.5 - you can disable the settings for matrix types (so items cannot change their matrix type), and when the limit for a type is reached it becomes unavailable for selection in the type dropdown of other matrix items. The module now requires Repeater Matrix >= v0.0.5. If you are using Repeater Matrix v0.0.4 or older then there is no need to upgrade Restrict Repeater Matrix as the new features in v0.1.4 are only applicable to Repeater Matrix v0.0.5.
  22. There's no special setting for the number of page links between the ellipses, but how many appear there is determined by the numPageLinks setting, which as I understand it should control how many extra page numbers appear in addition to the first and last page numbers. So you'd expect that a numPageLinks setting of 3 would achieve what you want, but it seems buggy: Why is the current page the last number and not the middle number? Why are there only two numbers here instead of three? Likewise here - why aren't there three numbers in addition to the first and last numbers? Why does the second page look like this... ...but the second to last page look like this... ? If you want to have a go at fixing it the relevant code is in PagerNav::getPager().
  23. To test the explode() method you would dump its return value (an array):
  24. No, I don't think the module sets page titles. I was expecting something similar using the core "Name format for children" feature, but if you want to automatically set a title you have to use a hook. It's discussed in the topic below:
  • Create New...