Jump to content

MarkE

Starter
  • Content Count

    94
  • Joined

  • Last visited

Community Reputation

17 Good

About MarkE

  • Rank
    Full Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. The hook is on Pages::added. I tried it on Pages::saved as well. I also tried saving the page (in the first hook, not the second ). All the other fields were present and correct, it was just the images that were missing as they were not saved at the time the hook ran, The bar dumps indicated that the path to the files had been set, but that there were no files in that directory. Immediately afterwards (by inspection, and as picked up by my LazyCron), the files appeared.
  2. UPDATE: I think I have found the problem (and a sort of solution). The problem seems to be that the file system has not saved the image files when the hook is run. I suspect that it makes no difference what hook is used as they will all execute before the files have been saved. So my sort-of-solution is to take the code out of the hook and instead execute it from a LazyCron (everyMinute). That's timely enough for what I need. After executing, the source page is removed so that it does not execute again. If anybody has any better ideas, I'd be interested to know.
  3. Hmm. I can see that the array I have is actually the array defining the FieldtypeImage rather than an array of a FieldtypeImage object! EDIT Some more clues: The copying is within an addHookAfter('Pages::added',...) hook. It seems that the path for the images is set, but that the actual images are not saved to the files directory until a later stage. So maybe I need to move the whole code to another hook? However, I only want the code to execute when the new page (with the images) is added (it is created by FormBuilder).
  4. Yes - no luck with that. I've now found the docs on Pageimages (e.g. https://processwire.com/api/ref/pageimages/add/) which implies I can add a filename string or an existing Pageimage type. My field ('images') is FieldtypeImage which seems (on debugging) to be an array, but not of images, rather something like this: [gif jpg jpeg png, 1, InputfieldImage, 0, 1, 6, Array, 1, 0, 0, sitemap, Site, 0, 0, grid, on, 0, 90, 0, 0] I'm struggling to find what property of FieldtypeImage I should use to add to another FieldtypeImage.
  5. I have a function which copies (selected) fields from one page to another. This was working fine until I added a field of type FieldtypeImage. I can't get this to copy across. The original code (before adding the image type) was foreach ($foundPage->fields as $field) { if (!in_array($field->name, $unwantedFields)) { $foundPage->$field = $p->$field; } } where $foundPage is a matching page for $p (same template) and $unwantedFields is an array of field names not to be copied. When the image field was added to the template, no errors were reported, but the image field would not copy over. The field $p->images seemed to be empty. So I tried this code: foreach ($foundPage->fields as $field) { $fieldName = $field->name; $updateField = $p->getFields()->get("name=$fieldName"); if (!in_array($field->name, $unwantedFields)) { $foundPage->$field = $updateField; } } That did populate the $updateField with the image field and showed it as a type FieldtypeImage, but I got the message "Item added to ProcessWire\Pageimages is not an allowed type" Given that the images field is an array (and actually I would prefer to merge rather than replace the contents), I tried adding in something like: if ($field->type == 'FieldtypeImage') { foreach ($updateField as $image) { $foundPage->$field->add($image); } } but that did nothing (nor threw any errors). Obviously there's something I don't quite understand about FieldtypeImage and/or WireArray. I read https://processwire.com/docs/fields/images/, but that didn't seem to cover it. Any ideas what I am doing wrong? Thanks.
  6. I've been using this field type for a while and very good it is too, but now I am scratching my head: I have a runtime_markup field ('runtime_markup_expiryDate') with PHP as follows return ($page->parent->name == 'memberships' and $page->latestSubscription()->id) ? date('d/m/Y', $page->latestSubscription()->subsEndDate) : 'Non-subscriber'; This works well in the back-end, but gives the wrong result in the API. If I retrieve the field in the API, it just gives 01/01/1970. However, if I remove the formatting in the PHP, thus: return ($page->parent->name == 'memberships' and $page->latestSubscription()->id) ? $page->latestSubscription()->subsEndDate : 'Non-subscriber'; it works correctly in the API (gives the right date, e.g. 30/09/2019) but obviously just gives the integer in the back end (e.g. 1569798000). The curious thing is that, in this case I can't work out where the formatting is applied in the API (which might be related to the cause of the problem) What is going on? Any suggestions for a fix or work-round? Thanks.
  7. Many thanks. Slightly adapted that. This works: '<span style="display:none">' . $membership->modified . '</span>' . datetime('d/m/Y', $membership->modified) with the MarkupAdminDataTable method setEncodeEntities(false) BTW, I also tried '<span class="datetime">' . datetime('d/m/Y', $membership->modified) . '</span>', which is what seems to be used in ListerPro (and works), but that didn't work in my module for some reason. Shame, because I would prefer not to have the concatenated formatted date after the unix integer as part of the sort key (although it shouldn't be a problem with the chosen format).
  8. Brill, thanks. Looks like mmddyyyy is hard-coded into the jquery tablesorter in wire. I hacked that to ddmmyyyy and it works fine (until the next update ) Anyone any ideas how I put that over-ride into my site?
  9. Not sure how well documented MarkupAdminDataTable is, but I've managed to work out quite a bit and have found it very useful for custom admin pages. One thing that has me stumped, however, is sorting dates. Obviously if the date is just rendered as a unix integer, it sorts fine but is not very meaningful. If I apply a datetime format, it sorts it as as string, which again is fine for 'Y/m/d' but no good for a more user-friendly format like 'd/m/Y' or 'relative'. I've tried applying class="datetime" to the items (which I spotted you can do by supplying an array of [item, class]) but that seems not to help. Any ideas or pointers to more documentation?
  10. For iPad users, when editing in the back end in a modal, after saving, the display seems to stay at the bottom of the modal, so the close icon is not evident. In this case (and more generally, too, I think) it would be helpful to have a cancel/close/continue button (ideally text would depend on state) at the bottom of the modal, next to the publish/save button. I'm sure there must be a simple way of adding this, but I can't see how.
  11. Ta @adrian. I'll look into that where there are privacy issues - my first concern was to make things easier to use, but I need to think about privacy also.
  12. That's 5 Here's my code (slightly generalized) //Restrict page-list view in back-end wire()->addHookAfter('Page::listable', function(HookEvent $event) { $page = $event->object; $allowedViews = [ 'membership-secretary' => ['home', 'template_1', 'template_2'], 'treasurer' => ['home', 'template_3', 'template_4'], // etc. 'site-content-editor' => ['home', 'basic-page'] ]; $event->return = false; foreach ($allowedViews as $role => $templates) { if ($this->wire()->user->hasRole($role) and in_array($page->template->name, $templates)) $event->return = true; } if ($this->wire()->user->hasRole('webmaster')) $event->return = true; });
  13. Thanks a lot. I’ll give that a go.
  14. Yes I have, thanks - but that limits users to just one branch. In my case, I need them to access more than one branch. I tried the "role-based" approach, thinking I could set up a role for each of the relevant branches and then assign those, but I couldn't get it working. In any case it wouldn't really meet my requirement which is to just display pages of the relevant templates - restricting page-view for the templates does this, but with the consequences I described.
  15. The access mechanisms for PW seem pretty powerful, but a bit complicated. I'm struggling to do something that i thought would be quite simple but I keep tripping up. The pages in my site include a large number which are not rendered - essentially a database - but they are outside the "admin" section. I have a number of roles to which I need to provide access to selected groups of these pages in the back end. It is easy enough to limit the "edit" access by template. Because it would be confusing for the users to see a tree with a load of pages not relevant to their roles, I would also like for them not to see the pages to which they don't have edit access. So I removed their "view" access to these templates. However, they can still see them in the back end, because of inherited rights from the "guest" role. Now, I needed the "guest" role to be able to view many of the pages because that is the role used by webhooks and batch runs invoked by LazyCron. So I thought perhaps I could set up separate roles for them and add those roles to their guest role in the API when they run - that way I could reduce the default "guest" access to just renderable pages and give enhanced access to other roles as needed. However, this does not seem to work. The role is shown as being added, but doesn't actually seem to provide the additional access rights to the "guest" user. What is wrong with my approach and is there a better way of doing this?
×
×
  • Create New...