Jump to content

Kiwi Chris

Members
  • Posts

    266
  • Joined

  • Last visited

  • Days Won

    4

Everything posted by Kiwi Chris

  1. I've checked what $event->argument(0) is returning, and it actually is the page the repeater is used on, even though that page doesn't directly have the field 'bom' as that is only used in the repeater itself, so even though the repeater item is technically a page in its own right, my hook is picking up the page the repeater is on anyway. My filter seems to be working as expected now. I think the issue arose because previously I was using a pagetable instead of a repeater, but the client didn't like the presentation, and found a repeater more intuitive. The client only needs a few items, sometimes only one, so a repeater makes sense. With the pagetable, I did need to refer to the parent, and with the repeater items technically being pages, I assumed I needed to do the equivalent, but it turns out that with repeaters the page they're used on is the page returned by the hook.
  2. I'm trying to apply a custom filter on a page field within a repeater via ready.php like so: $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if ($event->object->hasField == 'bom') { $parent = $event->arguments(0)->page->getForPage(); } // Filter criteria ... } The problem is I get "Call to a member function getForPage() on null" on the line: $parent = $event->arguments(0)->page->getForPage(); Any idea what I'm doing wrong?
  3. I have a role that has page edit, view, and clone permissions on a specific template. If a page using the template is locked by a user in a role with lock/unlock permissions on the template , the only button alongside it in the page tree is view, for users who don't have lock/unlock permissions. If however, I also give the role page-lock permission on the template, they then get additional buttons, edit, copy, and unlock. I don't actually want to give this role unlock permissions, but I do want the copy (clone) button to display alongside the page in the page tree. Elsewhere, I've discussed how I've worked out how to create a hook to unlock the copy, but I want to keep the original page so a user without lock permissions can't unlock from the page tree it to make changes. Question: What method should I hook into to intercept any attempt to change the lock status?
  4. /* * Example of how to clone a locked page, remove the lock on the copy, and clear the value of a field in the copy. * Reset stockCode Field when copying a page using a specific template, also remove locked status. * This code is included in the /site/ready.php file. */ $wire->addHookAfter('Pages::cloned', function($event) { /* * Important: The event arguments include both the copied page and the newly created page. * Don't use $event->arguments('page') as this returns the page that is being cloned rather than the cloned copy. * Instead use $event->arguments(1) which correctly refers to the new copy. */ $currentPage = $event->arguments(1); if ($currentPage->template == 'bom') { $currentPage->stockCode = ''; $currentPage->status = $currentPage->status & ~Page::statusLocked; //probably better to use removeStatus(Page::statusLocked) $currentPage->save(array('quiet' => true)); } }); Here's my documented example of how I got this to work.
  5. I want to be able to allow users with page clone rights the ability to clone locked pages with specified templates to a new unlocked copy, but without letting them edit the locked page. It looks as though I have the right permissions set to allow them to copy a page, but I need to add a hook in the /site/ready.php to unlock a page after it's copied. What method should I hook into? Edit: Figured it out. AddHookAfter Pages::Cloned. I had to be careful to pick the right argument though so that I was modifying the cloned copy and not the page that the copy was made from.
  6. From what I understand, you want to list comments from each product page on the product brand page? Comments documentation is here: https://processwire.com/docs/modules/guides/comments/ If you look at the section in the docs titled OPTIONAL : Generating your own output it has this example code: foreach($page->comments as $comment) { if($comment->status < 1) continue; // skip unapproved or spam comments $cite = htmlentities($comment->cite); // make sure output is entity encoded $text = htmlentities($comment->text); $date = date('m/d/y g:ia', $comment->created); // format the date echo "<p><strong>Posted by $cite on $date</strong><br />$text</p>"; } Of course you can always replace the $page variable in that example with your own variable that returns a page, so you could do something like: $brandProducts = $page->children(); $foreach($brandProducts as $product){ foreach($product->comments as $comment) { if($comment->status < 1) continue; // skip unapproved or spam comments $cite = htmlentities($comment->cite); // make sure output is entity encoded $text = htmlentities($comment->text); $date = date('m/d/y g:ia', $comment->created); // format the date echo "<p><strong>Posted by $cite on $date</strong><br />$text</p>"; } } If your products aren't children of a brand, but simply have a brand field set using a page reference field for example, you'd need to use a selector instead to populate $brandProducts eg $brandProducts = $pages->find("brand={$page->brand}");
  7. I've found this module really useful, and thought I'd share an interesting use case I've come up with for it. I had a client who wanted both the functionality of pageTable, and PageTableExtended, ie they wanted a tabular summary like PageTable provides, but with the option to expand or collapse to display rendered detail from a template like PageTableExtended allows. It turns out, I was able to provide the desired functionality using PageTableExtended, and built in UI-kit classes in the template file I provided to PageTableExtended. <!-- This is the summary section, like displayed by PageTable --> <table class="AdminDataTable AdminDataList uk-table uk-table-divider uk-table-justify uk-table-small"> <thead> <tr> <th>BOM</th> <th>Cases to produce</th> <th>+/- or exact</th> <th>Notes</th> </tr> </thead> <tr> <td><?= $bom->title ?></td> <td><?= $page->cases ?></td> <td><?= $page->exact ?></td> <td><?= $page->notes ?></td> </tr> </table> <!-- Toggle to display detail section --> <a herf="#" class="toggleRenderedLayout"> <i class="toggle-icon fa fa-angle-right"></i> </a> <span class="renderedLayoutTitle">BOM Details</span> <!-- Detail section, hidden by default, using built in ui-kit css. --> <div class="renderedLayout hiddenOnStart"> <div uk-grid uk-margin-small-top> <div class="uk-width-1-3 uk-margin-small-top"><strong>Wine Variety </strong><?= $bom->wineVariety->title ?></div> <div class="uk-width-1-3 uk-margin-small-top"><strong>Brand </strong><?= $bom->brand->title ?></div> <div class="uk-width-1-3 uk-margin-small-top"><strong>Market </strong><?= $bom->market->title ?></div> <div class="uk-width-1-1 uk-margin-small-top"><strong>Orientation </strong><?= $bom->orienation->title ?></div> ... </div> </div> Screenshot, showing the tabular summary, with the detail section expanded.
  8. In the RTE, when inserting a link, there are several input fields that can be used to select a page, including a text input field that will auto-complete with pages on the site. When inserting an image, there is only an option to navigate the page tree. (equivalent to the second input option 'Select Page...' on the Insert Link screen from the RTE. When inserting an image from another page buried somewhere in the page tree, if you know the name of the page, it would often be quicker to use an auto-complete text field than 'Select Page...' option. It would be nice if the image insertion dialog offered the same functionality as the link insertion dialog so that when selecting a page it's possible to choose either to navigate the page tree, or have a text auto-complete field.
  9. Conditionally 2, provided the collapsible option is available. One of the things I like about Processwire is that it plays nice with mobile screens. Some other CMSs are clearly designed for desktops or large tablets only, but Processwire will work even on a smartphone. I can't say how often I'd actually use it on a phone, but it would be nice to have the option. I actually can think of a case where having the backend mobile friendly would be handy. I was at a market last year, and someone didn't have any cash, but did have a credit card. Of course the front end of my site is mobile friendly anyway, but it could be handy to have the backend mobile friendly too.
  10. If for any reason, you can't get terminal access, you can add the php code to any template that already exists in the /site/templates directory and then view any page based on the template to trigger it. You won't require the first require line in that case, and don't forget to remove the password reset code again afterwards.
  11. Beat me to it. It's one of the nice things about Processwire that the admin is simply a UI on top of the API, and anything you can do via admin, you can also do easily via a script.
  12. I'm trying this option, but I can't seem to get it to work. I've tried: public function ready() { $this->addHookAfter('Page::render', $this, 'updatePageViews'); $page = $this->page; } public function updatePageViews($event) { /** @var Page $page */ $page = $event->object; // don't add this to the admin pages if ($page->template == 'admin') return; if ($page->hasField('pageViews') and $this->user->isGuest) { //Update the number of page views for current page, but only visitor views not admin. $page->of(false); $page->pageViews ++; $this->pages->saveField($page, 'pageViews'); $page->of(true); } } and this way: public function ready() { $page = $this->page; if ($page->hasField('pageViews') and $this->user->isGuest) { //Update the number of page views for current page, but only visitor views not admin. $page->of(false); $page->pageViews ++; $this->pages->saveField($page, 'pageViews'); $page->of(true); } } But neither of them seem to do anything with template caching enabled. Any idea what I'm doing wrong? Edit: I found the problem isGuest needs brackets, ie isGuest()
  13. Update: In addition to the modules previously mentioned, the site now uses Padloper to add shopping cart functionality, and PaymentStripe and PaymentInvoice modules. I've also made some modifications to the MapMarker module so that I can use KML files from a separate files field as map overlays. This is really handy, as I can use Google Earth to define paths and areas that I can overlay on the map, which I can export and display with Processwire. In the process, of implementation with the payment modules, I discovered an issue with module dependencies and the modules cache in the database, which I've discussed and resolved here: https://processwire.com/talk/topic/19606-class-not-found-error/?tab=comments#comment-170031
  14. This was coming from an old CMS. I used Source: index.mvc?ArticleID={id} Destination: [[wid={id}]]
  15. It's great to see a government agency using Processwire. Here across the Tasman, I think Silverstripe has been mandated as the government CMS of choice which is sort of ok in some respects, but it's a lot more complex than it needs to be for many projects.
  16. Some people think that anyone who works in any form of IT is made of money, but sadly it's not always the case. I know the feeling about dying laptops. About a year ago, when it was just over 3 years old, the motherboard on my laptop died. Fortunately I was able to track down a replacement part on Ebay, and after carefully removing a lot of screws, swapping over the CPU and heatsink, and convincing Windows that I wasn't running a pirated copy, I managed to get up and going again. My desktop is a bit long in the tooth too, but since I upgraded the hard drive in my laptop and added an external screen and keyboard, the desktop tends to get less use now, although it was a lifesaver when I needed to get online to order the replacement motherboard for the laptop, and do some work while I waited for the part to arrive.
  17. I could use a field like this. I have a directory of local businesses and non-profit organisations, but sometimes their websites change or they go out of business, so it would be really handy to be able to run an automated script that can either hide or un-publish any listings that don't have a valid address. That would save on manually checking every one on a periodic basis to make sure they still exist. Of course I'd probably still double check manually any that get deactivated before removing them, but it would make the process a lot more efficient.
  18. Thanks. I didn't think to look there. There do seem to be a few dire warnings in that post about being careful with using advanced mode, but image fields are very much a core functionality, so hopefully there won't be any issues.
  19. A number of field properties can be specified on a per-template basis that override the field definition. For example it is possible to set minimum and maximum length for text fields, so that it is possible to use the same field on several different templates, but with some different specifications on different templates. It would be nice to be able to do this with image fields, as sometimes I've found I've needed to create multiple image fields simply because on different templates I want to enforce different maximum dimensions. I'm not sure how complicated this would be to implement, but in some scenarios it could potentially cut down the number of fields required quite substantially.
  20. I've managed to resolve the problem. I actually still think the issue might be a core ProcessWire one, but at least I know how to fix it now. Yes, I'm using the PW3 branch of Padloper, and it's working fine on other sites on my WAMP setup. I'm using AIOM+ on many sites with PW3 and it's working fine on all the others. I tried manually deleting all the entries in the cache table in phpMySQL and that allowed me to get into the site admin again temporarily, although it gave some notification about some modules that actually are present not being installed. I went to modules, and did a refresh, and the error came back. One thing I noticed that I wonder about, but don't know enough about how Processwire handles loading modules, is looking at the Modules.site/modules/ entry in the cache table, the modules seem to be listed in alphabetical order, and the offending module that is generating the error is listed before the module that it depends on, which it claims can't be found. I'd hope this shouldn't matter, as it could have serious implications for module naming, as the offending module was working previously, but it seems it does. I manually edited the order of the modules listed in the cache entry via phpMySQL, and the error went away. I've tracked down the issue with AIOM+ I think. There was a namespace conflct in that a reference to a root PHP class was picking up the ProcessWire namespace and obviously not working. I think I must have added a namespace statement to the module so that the module compiler didn't have to do it, but forgot to check any possible conflicts. The good news is AIOM+ works fine without namespaces in Processwire 3.x I think the AIOM+ problem might have actually been a red-herring with me trying to add namespaces to everything to try to get the first error to go away. The real culprit here is that if the Modules.site/modules/ gets regenerated somehow, it seems it can potentially break a site, as it will add modules in alphanumeric order, and if a module depends on another one that comes later in the sort order, then the class will not be found. This can be fixed with careful naming of modules so that a module that has dependencies will always be listed after any dependencies, so in the case of PaymentInvoice, since it depends on PaymentModule, it probably should have been called PaymentModuleInvoice which would ensure that regenerating the modules cache would always load it after PaymentModule.
  21. Further development: I tried deleting the module that said that it couldn't find Payment Module. That solved that error, but now AllInOneMinify module is giving a similar error saying that it can't locate a class that it depends on, even though nothing has changed. Other sites on the same development server are working fine. This has certainly shaken my confidence a bit in the robustness of Processwire, if seemingly at random, it starts throwing out errors about a whole range of supposedly missing classes that are definitely there, and it seems a bit random, as why does it report certain classes missing but not others?
  22. I'm having an odd error similar to this: I'm running WAMP on Windows 10, with Processwire, and get an internal server error trying to access either the front end or admin. Checking my logs I find: Error: Class 'ProcessWire\PaymentModule' not found (line 3 of ...\processwire\site\modules\PaymentInvoice\PaymentInvoice.module) The PaymentModule classs definitely exists, and hasn't been modified, and is namespaced. The other thing I've noticed, is in the modules.txt log usually modules are installed via the site admin, however just before I started getting the error, I see a reference to a new module being installed via access to a frontend page via the following code. $checkout = $modules->get("PadOnePageCheckout"); $checkout->setShippingModule("ShippingFixed"); $checkout->setPaymentModule("PaymentStripe"); // This module was not installed at the point the page was viewed, triggering the module to install. Normally, following module installation, there is an entry in modules.txt saying Saved module info caches. In this case there is no entry for this. The module that installed via the front-end extends the module in question that is supposedly missing. Before the whole site went down, I noticed that the PaymentStripe module was not showing as installable or installed modules, in admin, however it is not this module that is claimed to be missing, but PaymentModule which it extends, and it is another payment module, PaymentInvoice that generates the error. The site was working, although PaymentStripe wasn't showing up in the modules list, until suddenly everything stopped. I'm using the premium Padloper shopping cart package, however I understand payment modules can be used independently of Padloper, and I'm not sure the issue actually relates to Padloper directly.
  23. I'm on PW 3.0.104 and having the same problem.
  24. The current version of ProcessExportProfile module seems to be having issues with not populating data in the exported SQL correctly. I'm getting errors like: SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'created' The problem seems to be here: CREATE TABLE `modules` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `class` varchar(128) CHARACTER SET ascii NOT NULL, `flags` int(11) NOT NULL DEFAULT '0', `data` text NOT NULL, `created` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`id`), UNIQUE KEY `class` (`class`) ) ENGINE=MyISAM AUTO_INCREMENT=188 DEFAULT CHARSET=utf8; The timestamp value that is exported is an invalid value with mySQL 5.7.14 that I'm using, so the import fails with the mySQL error. There also seem to be a whole lot of records (ie all the core modules) like the following which also fail on insert: INSERT INTO `modules` (`id`, `class`, `flags`, `data`, `created`) VALUES('1', 'FieldtypeTextarea', '1', '', '0000-00-00 00:00:00'); Modules that I've installed myself work fine as they have a valid date. Exported profiles did work in the past, so I'm not sure if this is a Processwire issue, or different mySQL configuration that's being more strict about date formats.
  25. Thanks. I hadn't spotted that module before, or maybe hadn't quite realised what it did. It's exactly what I was looking for.
×
×
  • Create New...