Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by bmacnaughton

  1. I am using the translation function (either $this->_() or __()) within a module that responds to AJAX API calls - there isn't really a page that is being served. When I supply a string with an apostrophe, e.g., __('Book \'em danno') It is formatted as Book 'em danno Is there some way to prevent output formatting when retrieving strings using the translation functions?
  2. Thank you for the precise and concise answer! It works quite nicely - even defaulting when a language doesn't have a value filled in.
  3. I would like to be able to fetch the labels for fields in a language different than the current logged in user. For field values that's easy // p is page, l is language, and f is field $p->getLanguageValue($l, $f); I'm looking for something like $fields->getLanguageValue('en', 'length'); The only solution I know of is to save the current user language, iterate through the languages by setting the user language and fetching the value, and then restore the user language.
  4. Thanks. I was trying to find out if a field was multiple language as opposed to there being language alternate fields. But I appreciate the link.
  5. Is there a way to tell if a field is a multi-language field? I am currently checking to see if the last 8 characters are 'Language' but that seems like a fragile solution.
  6. Thank you @Zeka. Perfect answer, with code reference! I am getting more familiar with the code slowly.
  7. When I delete a page name, e.g, /cart/, using the admin interface it goes into trash and gets the name /trash/2573.1.11_cart/ . I see that, with the Pages::trashed hook that the previous page name (previousPage) can be accessed. Where can I more information about what happens when a page is put into trash and what the name means?
  8. I have a hook that creates a page for a subset of the pages on our site. It uses the saved page's name as part of the created page's name. The problem I am having is that my hook, attached to Pages::saved(), is being called even when the page save failed because of missing fields. Is there a way I can tell that the page save failed due to missing fields? Never mind - it does succeed; it just issues warnings about required fields.
  9. What's odd is that PW doesn't take all the data from the array passed to $form->process(). You can argue the CSRF protection is a different function, but that's just internal implementation. And it's easy enough to stuff things into $input->post, so it's not like it prevents forging.
  10. You can stuff the values into $input->post or you can set the HTTP headers, so you can work around it.
  11. I tried the same thing - it was the last way I could think of. I'm not sure why it didn't work but will try again.
  12. Thank you @Robin S. I am going to give this a try - I solved this particular problem by forcing the new entries under the page they are contained by but that is a suboptimal solution.
  13. Thanks Abdus. I have a little different problem - I am looking for the specific page instance that has the field being edited. There are multiple pages based on the template that contains that field. I need to know which specific page instance is the "logical parent", not the set of pages that contain that field, i.e., are instances of the template that includes that PageTable field. To try to make it more concrete: PageA, PageB, and PageC all have the PageTable field Variations. When in the Admin interface PageA is being edited and the user wants to add a variation then they click "Add New" under Variations. At that point an iFrame overlay pops up to enter data for the new PageTable page in Variations. When that PageTable page is saved I need to know that it is associated with PageA. If the PageTable pages were in their default location (children of PageA) then I could just look at parent. But the PageTable pages are all kept in a single directory for grouping purposes. Make sense?
  14. When a PageTable field in a specific template is being edited I need to know the Page that contains the PageTable so I can fill in hidden fields in the PageTable. I can capture the page being edited via: // $this->addHookBefore('ProcessPageEdit::execute', ... public function pageEditExecuteBefore(HookEvent $e) { $p = $e->object->getPage(); if ($p->template !== 'rtw-product') return; // $p is the page being edited } I can intercept PageTable entry being saved: // $this->addHookBefore('Pages::save' public function savePageBefore (HookEvent $e) { $p = $this->wire('page')->id; $page = $e->arguments('page'); $obj = $e->object; $name = $page->name; // page name of PageTable page $template = $page->template->name; // template of PageTable page $parent = $page->parent->name; // parent directory for PageTable items What I am trying to find is the page in which the PageTable field is located. I've also tried having pageEditExecuteBefore() saving $p in $this->context and then accessing that in savePageBefore() but it's a different instance of the class because $this->context is null when it gets to savePageBefore(). I could save the page ID in session, but that seems error prone. Does anyone know how to achieve this?
  15. Thank you. I really appreciate the link and the code being on github. I learn a lot by reading code and yours is very helpful. I've solved the problem for one template but your solution is more general so when the inevitable additional template comes along, I'll most likely move to your module. Thanks for putting it together and pointing me at it.
  16. Do any experts have experience with the level of stability and/or support for turning on $config->advanced? I ask because of the warning at the bottom of the System tab "Please note that all of these system settings are intended for ProcessWire system development (not site development). Use them at your own risk." It provides two facilities that are invaluable to me (maybe because I don't know how to do them any other way). 1) Disable Settings Tab on a per template basis 2) Page Class Name - this makes it tweak a page while relying on the underlying Page class for the majority of functions. Are others using this setting in production? Have you used it over an extended time and seen that it is not changed often or at all?
  17. I'm working in version 3 and can't remove the settings tab using your example. Maybe something new has changed? But $config->advanced = true; works perfectly and is a better solution as it's already per-template.
  18. Woohoo! Thanks. $config->advanced = true; does the trick!
  19. I found this in the meantime - thanks for this post as well. I got the this working by turning on $config->advanced = true; in config.php which allows hiding the settings tab on a per-template basis! Nice. It seems that the code in the thread turns off the general ProcessWire menus as well: Before and after shots attached. I'm working on 2) now.
  20. Soma, Thank you so much for this. It's a fantastic example which I'm using as of yesterday. I particularly appreciate you posting clean code as I find reading code the best way for me to learn how things work. Do you possibly have any examples of a hook in which I could manipulate more of the admin interface? I'd like to do a couple things: 1. Remove the "settings tab" in the iframe that pops up when editing a PageTable entry. Maybe it's possible to do so with roles and permissions or a technique similar to removing the button. 2. Change the function of the "Add New" button completely - don't create/load the iframe and just create a new PageTable entry programmatically. If there are hooks to point me at I can figure them out. I've spent time with Captain Hook and but am a bit overwhelmed with the sheer number as well as the fact that I don't know much about how the admin interface is constructed.
  21. Is it possible to rename the page after it's been added to the Page Table? In the admin interface there is an "Add New" button for Page Table fields. I am trying to set the name of the page being created based on content that is entered into the page in the "Add New" overlay dialog. Is that possible without editing ProcessWire source code? It seems like the name has already been entered into the PageTable before the new page is created and that might be why hooking 'setupPageName' is not effective.
  22. OK, I was too quick to assume it would work. The hook is invoked with a page name like 20170422-011158. As shown in the following code I try to insert 'temp-' in front of the timestamp-based name. $name = 'temp-' . $event->return; $event->return = $name; But the $event->return value is not being used. What am I doing wrong? Is there some special about Page Tables that this doesn't work for?
  23. OK, I've got this one solved. Hook 'Pages::setupPageName'. Working on the next one.
  24. I have a Page Table field that, for new entries, I want to construct the name for. When I click the Add New button the page being added has already been given a random name like: 20170422-003744. I wish to 1) change that name so it's obvious it is a temporary name and 2) when either Publish or Save + Keep Unpublished is clicked, set the name of the page based on the content entered. What hooks can I use to accomplish 1 and 2? thanks.
  • Create New...