gornycreative Posted October 14, 2024 Share Posted October 14, 2024 A minor issue, but if a site isn't running multiple languages, the $language api var is null. There needs to be a null check on line 322 in the .module file, such as: if ($this->wire('languages')->count()) { $lang_id = $this->wire('languages')->getLanguage()->id; } to: if ($this->wire('languages') && $this->wire('languages')->count()) { $lang_id = $this->wire('languages')->getLanguage()->id; } 1 Link to comment Share on other sites More sharing options...
Juergen Posted October 14, 2024 Author Share Posted October 14, 2024 Thanks for reporting this issue!! 😃 I have fixed this bug yesterday, but I have not bumped up the module version, because I am optimizing the code at the moment. So please replace the current file on Github with yours and everything should be fine. Best regards 1 Link to comment Share on other sites More sharing options...
gornycreative Posted October 15, 2024 Share Posted October 15, 2024 Cool. I should've check issues on github first. Thanks! Link to comment Share on other sites More sharing options...
MarkE Posted January 11 Share Posted January 11 (edited) Hi @Juergen. This is a nice module, but unfortunately it becomes unusable when there are a lot of pages. This is because on every page edit it autoloads and runs getParentPages() which has the following: return wire('pages')->find('id!=' . $exclude_pages . ',templates_id=' . $templates); On one site of mine this takes 20 seconds to run - so that's how long it takes to load a page in the back end. I'm only using the publish/unpublish functionality, so I disabled everything else and it loaded in a flash. However, that's not a solution if you want an 'after' action, so I looked into it a bit more. On my problem site, I have lots of parents and templates but I am only using the module on 2 templates which have a total of 47 pages, so I would have thought it would be possible to write it more efficiently. The problem seems to be that the above code is run on every page edit, not just pages of templates where the 'jk_...' fields are enabled. That means that, unless restricted parents are defined for every parent, the 'find' will run across all pages, with a large template array to match. I suggest adding the following after line 224 if(!in_array($this->page->template->id, array_keys($this->input_templates))) { return new PageArray(); } Then if, for the relevant templates, the allowed parents are set, it all runs pretty swiftly. EDIT: Ideally it might be nice to use this, as then the jk_move_child field could be removed from the template if not required and there would be no need to specify allowable parent templates (which may not be desirable for other reasons) if(!in_array($this->page->template->id, array_keys($this->input_templates)) || !$this->page->hasField('jk_move_child')) { return new PageArray(); } However, re-submitting the module will reinstate the jk_move_child field. A bit more flexibility here would be nice. It would be better if 'move child' was an optional extra. Edited January 11 by MarkE Afterthought 1 Link to comment Share on other sites More sharing options...
Juergen Posted January 12 Author Share Posted January 12 Hello @MarkE Thank you for reporting this issue on sites with many pages (and providing a solution). My websites don't have many pages, so I've never encountered such an issue. 😉 I've integrated your fix into the latest version (1.3.15), so the issue should be fixed by now. According to your suggestion to make the "move" of a child page optional, I will take a look at it in the near future. Thanks Jürgen 2 Link to comment Share on other sites More sharing options...
MarkE Posted February 16 Share Posted February 16 Hi @Juergen. I've hit another issue that seems to be related to your module. I have what I believe to be 2 identical environments for dev and live. However, after adding a new page, the dev environment (when in superuser) shows 2 buttons: 'Publish' and 'Save & keep unpublished', but the live environment (or not as superuser) just has 'Publish' and 'Save'. Any ideas what might be causing that (the dev superuser version is more helpful, I think). For this particular page, I don't want the 'Publish' button to be available unless certain criteria are met, so I added a hook: public function afterPageEditBuildForm(HookEvent $event) { $form = $event->arguments(0); // Get the form $page = $event->object->getPage(); // Get the page being edited if($page->template->name == 'NewsItem' && (!$page->final || !$page->approved)) { foreach($form->children as $field) { if($field->name == 'submit_publish') { $form->remove($field); } } } } That removes the 'Publish' button OK. However, if I am not superuser, clicking the 'Save' button does actually publish the page, even though the 'Publish' button was removed. If I am superuser, clicking 'save' saves it as unpublished. In order to make the hook work in all instances, I have to add: $page->addStatus('unpublished'); $page->of(false); $page->save(); but that really ought not to be necessary. The page in question is selected to 'add fields to templates' in your module but the fields are left blank. If I deselect the template then everything works correctly, but the helpful 'Save & keep unpublished' is just replaced by 'Save' (and of course, I no longer have the functionality). All a bit confusing! Link to comment Share on other sites More sharing options...
Juergen Posted February 16 Author Share Posted February 16 Hello @MarkE The issue you reported sounds a little strange. I have tested it on localhost and on a live site, with the module installed and not, but I cannot reproduce this issue. On localhost: On a live site: As you can see, there is no difference between localhost and the live site. I was logged in as a superuser and as a manager. The manager role allows me to add new pages. There is no difference whether the module is installed or not (both on the live site and on localhost). Therefore there must be another reason for the behavior. I'm guessing you have different permissions for your roles on the development and live site. The module does not include a hook that affects the Save and Publish button on an admin page. Therefore, the module is unlikely to cause such an issue. The publishing of the pages works as expected too. I am sorry, but I guess you need to check if your roles or your template permissions could be responsible for your issue. Jürgen Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now