Jump to content

Robin S

Members
  • Posts

    4,791
  • Joined

  • Days Won

    303

Everything posted by Robin S

  1. Are we sure Tracy is causing the error as opposed to only reporting the error? As in, maybe the session lock times out regardless of whether Tracy is installed, but without Tracy installed you never learn about it. The timeout is a configurable setting in SessionHandlerDB so maybe the solution is that if you expect to run tasks that can take longer than the 50 second default you increase that setting, or if the long task is triggered by your own code do a $session->close() immediately before the task. Or is the sort of exception thrown by SessionHandlerDB when the lock times out supposed to be more silent? There was a Tracy issue similar to that but it was fixed a while back: https://github.com/adrianbj/TracyDebugger/issues/58
  2. Bummer about the Selectize issue. I think it might be the cause of this too: https://github.com/processwire/processwire-issues/issues/1736 A hook to substitute a textarea for the toolbar config without editing the core: $wire->addHookAfter('InputfieldTinyMCE::getConfigInputfields', function(HookEvent $event) { /** @var InputfieldWrapper $wrapper */ $wrapper = $event->return; $toolbar = $wrapper->getChildByName('toolbar'); $replacement = $event->wire()->modules->get('InputfieldTextarea'); $replacement->rows = 3; $settings = [ 'name', 'label', 'description', 'icon', 'textFormat', 'themeOffset', 'notes', 'value', ]; foreach($settings as $setting) $replacement->$setting = $toolbar->$setting; $wrapper->insertBefore($replacement, $toolbar); $wrapper->remove($toolbar); });
  3. Hi @Laksone, welcome to the PW forums 🙂 I think you're right that this is a bug - good find. Could you please open an issue in the GitHub issues repo so that Ryan becomes aware of it? Thanks!
  4. You don't need a different field for this scenario. You can use template overrides for the field settings. In the field settings (Overrides tab): Then from the template settings, edit the field in template context:
  5. Sounds like it would be a good case for a custom Page method (either added by hook or by custom Page class) that falls back to the core $page->get() when no value exists. $value = $page->getFromJson('some_field');
  6. You can actually adapt that to a selector string that will allow you to use Page Autocomplete: In a Page Reference field selector string, "page" is a special keyword that PW converts into "the page that is open in Page Edit". This isn't documented anywhere as far as I know, but it would be good if it was @ryan.
  7. You'll need to write this line as... } else if($dl->ext() == "doc" or $dl->ext() == "docx") { ...or else it will always evaluate as true regardless of the extension. A good candidate for rewriting as a switch statement too.
  8. The core show-if can only work when the test relates to values that are contained in inputfields in the Page Edit form, (e.g. "some_field=foo"). Technically there is a field in Page Edit that relates to the parent - the "Parent" (parent_id) field on the Settings tab. But that inputfield is set to AJAX-load so the value isn't available to the inputfield dependencies JS. But you can use the Custom Inputfield Dependencies module to create show-if conditions that are evaluated by PHP rather than JS: https://processwire.com/modules/custom-inputfield-dependencies/ You would create a show-if condition like this:
  9. Usually such things are the result of being logged in (probably as superuser) in one browser and logged out in the other browser. It looks like that's the case in your screenshots because I can see the Tracy debug bar in one screenshot and not in the other. So probably the difference is due to some access issue, where superuser has access to something that guests do not.
  10. Yes, I do intend to create a new module similar to HannaCodeDialog that supports TinyMCE. But I don't have an estimated date for when it will be ready. For many of my modules, the situation has been that I work on them when I have a need for them myself. And I have quite a number of modules based on CKEditor that I use frequently and that would need to be redeveloped for TinyMCE before I personally can contemplate changing my RTE fields from CKEditor to TinyMCE. So I have quite a lot of work ahead of me and consequently I don't think HannaCodeDialogMCE is going to completed in the very near future.
  11. There are a number of ways you could conditionally add CSS to the PW admin, but one simple way is to add this to /site/templates/admin.php (before the line that requires controller.php) if($user->hasRole('editor')) $config->styles->add($config->urls->templates . 'styles/admin-custom.css');
  12. Another way you could do it... In my example the parent template is "countries" and the child template is "country", and there are 195 child country pages. Using the PageEditPerUser module the user is only allowed to edit country pages "Zambia" and "Zimbabwe": Page List before: The problem being that lots of uneditable pages are included, with the two editable pages being at the end of the 4th pagination. I'm not using Admin Restrict Branch here so (presumably) that's why all the non-editable pages are listed, but that doesn't matter for the purposes of this example. A solution is to add the following hook to /site/ready.php: // Only for a particular role if($user->hasRole('editor')) { $wire->addHookBefore('ProcessPageList::find', function(HookEvent $event) { $selector = $event->arguments(0); /* @var Page $page */ $page = $event->arguments(1); $user = $event->wire()->user; // If the parent template is "countries", restrict the children list to only the pages that the user may edit if($page->template == 'countries') { $selector .= ", id=$user->editable_pages"; $event->arguments(0, $selector); } }); } That fixes it so that only the editable child pages are shown, but the incorrect child count and unnecessary pagination controls are still visible: So the simplest thing is just to hide those things with some custom admin CSS only for the relevant role (if you're not sure how to do that something like this should work, with a check first for the user role). /* Adjust the parent template name to suit */ .PageListTemplate_countries > .PageListNumChildren { display:none; } .PageListTemplate_countries + .PageList > .uk-pagination { display:none; } .PageListTemplate_countries + .PageList > .PageListActions { display:none; } End result:
  13. I don't think you can do that in a selector, but you could add a hidden "owner" field to the "inventory" template and then populate that on page save with the value from the last repeater item. So if "owners" is the repeater field and "owner" is a Page Reference field within the repeater that stores a user... $pages->addHookAfter('saveReady', function(HookEvent $event) { /* @var Page $page */ $page = $event->arguments(0); if($page->template == 'inventory') { $page->owner = $page->owners->last()->owner; } }); Then you can easily find pages like this: $myInventoryPage = $pages->get("template=inventory, owner=$user");
  14. Not sure I understand the question exactly, but the general way to handle URL segments is in the template file. The template setting is just for if you only have one or two fixed segments or have some reason not to use the template file. So in your template file you just throw a 404 if the segment doesn't match your allowed segments, which could be defined dynamically. E.g. // Throw 404 if segment1 isn't in the array of allowed segments (which you could define dynamically) if($input->urlSegment1 && !in_array($input->urlSegment1, $my_allowed_segments)) throw new Wire404Exception(); // Throw 404 if there is more than one segment when there shouldn't be if($input->urlSegment2) throw new Wire404Exception(); // Now generate output according to segment, no segment, etc... Also see the docs here: https://processwire.com/docs/front-end/how-to-use-url-segments/#best-practices
  15. You can view the path history when the page is open in Page Edit, on the Settings tab: And from the API:
  16. It seems to be working here. If the code is going to be executed when the user is other than a superuser then you would need check_access=0 in the selector because the admin template is restricted.
  17. FYI, there is an option in the AdminThemeUikit module config for sticky header and page tree visible in the sidebar.
  18. I don't know what the field structure is in your template. It should work fine as described in my previous post. Inputfield names doesn't have much to do with it - you use field names just as you would in any selector. If the selector matches your page in $pages->find($selector) then it should work in the "Show only if page is matched by selector" setting. Seeing screenshots of your template fields and the settings you have chosen for CustomInputfieldDependencies would help. That isn't related to this module. It comes from the core show-if and required-if features, so if you are seeing that in your markup it means you are not using the features added by CustomInputfieldDependencies. See the screenshot below.
  19. For those who just want to let users upload WEBP format and are looking for a workaround, here is a simple module that converts WEBP to JPG on upload: I wonder though... how is it that the user acquired the WEBP image in the first place? Surely they didn't just pinch it off somebody else's website... 🤔
  20. WebP to JPG Converts WebP images to JPG format on upload. This allows the converted image to be used in ProcessWire image fields, seeing as WebP is not supported as a source image format. Config You can set the quality (0 – 100) to be used for the JPG conversion in the module config. Usage You must set your image fields to allow the webp file extension, otherwise the upload of WebP images will be blocked before this module has a chance to convert the images to JPG format. https://github.com/Toutouwai/WebpToJpg https://processwire.com/modules/webp-to-jpg/
  21. Did you try something already and it didn't work? You should be able to use either the "Show only if page is matched by selector"... your_matrix_field.count>0 ...or the "Show only if custom PHP returns true" setting... $items = $page->getFormatted('your_matrix_field'); if($items && $items->count) return true; If you were wanting to do the opposite, i.e. show the field only when the matrix field is empty, then it should work to put "your_matrix_field.count=0" into the "Show only if page is matched by selector" setting but unfortunately there seems to be a core PW bug: https://github.com/processwire/processwire-issues/issues/1701 So until that's fixed you'd need to use the "Show only if custom PHP returns true" setting instead: $items = $page->getFormatted('your_matrix_field'); if($items && !$items->count) return true;
  22. According to the docs, uppercase letters are not valid for URL segments: https://processwire.com/docs/admin/setup/templates/#allow-url-segments
  23. @AAD Web Team, this module can help with that: https://processwire.com/modules/find-merge/
  24. @adrian, thanks for looking into this request but after some more investigation I don't think there will be a good way for PageRenameOptions to deal with the ProcessPageClone issue. It's something that would need to be addressed within ProcessPageClone. It works out the copy number - (copy 2), (copy 3), etc - by looking at the page name to check for an existing number suffix. So it needs to name the first clone with a "1" suffix and yet it wants to title that first clone without the "1". If we change PageRenameOptions to set the clone name from the title then there's no number suffix on the first clone and so it messes up the calculation for subsequent clones. I don't think there will be changes to ProcessPageClone any time soon, and in fact the whole problem would largely be avoided if my request from 2018 was actioned. So instead I'm going to solve this with a couple of extra hooks: // Make ProcessPageClone always use "Copy Page" form // https://github.com/processwire/processwire-requests/issues/186 $wire->addHookAfter('ProcessPageListActions::getExtraActions', function(HookEvent $event) { $page = $event->arguments(0); $actions = $event->return; if(empty($actions['copy'])) return; $config = $event->wire()->config; $actions['copy']['url'] = "{$config->urls->admin}page/clone/?id={$page->id}"; $event->return = $actions; }, ['priority' => 200]); // Set "Copy Page" name field to match title field $wire->addHookAfter('ProcessPageClone::buildForm', function(HookEvent $event) { /** @var InputfieldForm $form */ $form = $event->return; $title_field = $form->getChildByName('clone_page_title'); $name_field = $form->getChildByName('clone_page_name'); if($title_field && $name_field) { $name_field->value = $event->wire()->sanitizer->pageName($title_field->value, Sanitizer::translate); } }); With these hooks PageRenameOptions will do its normal thing and sync the name field as I type a new title in the ProcessPageClone "Copy Page" form.
  25. To further complicate things, it seems that PageRenameOptions might be interfering with the normal clone titles. When the module isn't installed the (copy 2), (copy 3), etc is what I would expect... ...but when PageRenameOptions is installed I get duplicates like this (edit: to be clear, this is the result after 6 clones)... If the duplicate thing didn't happen then maybe the page names would always match the title without anything else needed? (assuming the hook you suggested) Edit: here are my PageRenameOptions settings: {"PageRenameOptions":{"version":"2.0.1","settings":{"enableForApi":1,"renameMatchTitle":1,"renameWithoutTitleChange":"","renameUnpublishedOnly":"","includeExclude":"exclude","initialDifference":1,"preventManualChanges":1,"liveChanges":null,"uninstall":"","submit_save_module":"Submit","exemptRolesInitialDifferencesProtected":[],"exemptRolesPreventManualChanges":["superuser"],"exemptRolesLiveChangesProtected":["superuser"],"specifiedPages":[],"specifiedTemplates":[],"initialDifferencesProtected":1,"liveChangesProtected":null}}}
×
×
  • Create New...