-
Posts
407 -
Joined
-
Last visited
-
Days Won
10
Everything posted by monollonom
-
include _main.php only when it's not an ajax call
monollonom replied to froot's topic in API & Templates
It should work for your situation as well. Render your HTML markup and once you're done and want to stop PW output call $this->halt. Try and let me know if it works. Edit: That is, in your initial setup where you have _main.php included by default after your template -
include _main.php only when it's not an ajax call
monollonom replied to froot's topic in API & Templates
I assume you're using the markup regions output strategy ? If so, when getting an ajax call, once you're done in your code and have echoed your response, you can call $this->halt(); to stop the template output (from https://processwire.com/blog/posts/processwire-2.6.8-brings-new-version-of-reno-admin-theme-and-more/#new-this-gt-halt-method-for-use-in-template-files) (I couldn't find it referenced in the doc though...) So for example in my case I have (in my page.php) if ($config->ajax) { http_response_code(200); header('Content-Type: application/json'); // code to populate $json echo json_encode($json); return $this->halt(); } -
change default template selected upon page creation
monollonom replied to froot's topic in API & Templates
Ok one issue though is that it's a global setting so I'm not sure how it will play out with the rest of your setup... so maybe you do need to use a hook in the end to be able to change this setting before ProcessPageAdd is started. -
change default template selected upon page creation
monollonom replied to froot's topic in API & Templates
What if you try to put all the template names except the one you want to be selected ? Re: "space-separated template names" $config->pageAdd("disableTemplates", "template1 template2 template4") Is "template3" then selected as you want ? -
change default template selected upon page creation
monollonom replied to froot's topic in API & Templates
Lol you're not alone, I struggle a bit sometimes too... To tell you the truth here was my train of thought: when trying to replicate your situation by adding several templates as authorized children, I came across the ProcessPageAdd module settings, and thought I might take a look at its code to see where it does the check to pull out the available templates. And then I finally stumbled upon this option I linked above... In your config.php file (in the /site/ folder), you can just add a line $config->pageAdd("noSuggestTemplates", true) So no need for a hook. Let me know how it goes. -
change default template selected upon page creation
monollonom replied to froot's topic in API & Templates
I've never had your situation so I wanted to be sure first. I quickly had a look at the code and I found this "Disable suggestions" option in $config->pageAdd, maybe try this ? -
change default template selected upon page creation
monollonom replied to froot's topic in API & Templates
Does the parent page need to accept multiple templates as children ? If not you can set this in the "Family" tab of your template to only allow for one template, and then it will be automatically selected upon page creation. -
PW 3.0.172 – Find faster and more efficiently
monollonom replied to ryan's topic in News & Announcements
Hi, Many thanks Ryan for this update. It's great to have something like this in the core! I have a question though: is the autojoin working with PageImages? I quickly tried on my setup but my PageImages field acts as if it was empty. Here is the dump when using $object = $pages->get("parent=$objects, $sort, field=gallery"); bd($object); -
Styles / Format dropdown in Repeater opens on double click only
monollonom replied to Bike's topic in General Support
I had a similar issue with CKEditor in multi-language websites but Ryan corrected it after I reported it here https://github.com/processwire/processwire-issues/issues/1260. I don't know if the fix is only in the dev version or already on the main one. Can you try and see if it works for you ? -
It...worked. Thank you so much @elabx, I absolutely am going to save this for later! Now that I am seeing the solution I do understand what is going on, but shouldn't something like this (the safe-guard) be built-in when hooks are facing this recursion issue ? Or it should be made clearer maybe in the doc ? Also it's weird because at first I just tried @markus_blue_tomato snippet, and he doesn't seem to have faced my issue. Is it because he added the hook in the init() function of a module ?
-
Hi, I can't really explain why (I have a hard time finding valuable error logs) but when I try to hook on either Pagefile::url or Pagefile::filename, it results in 500 errors. The only log I manage to have, sometimes, is a "Server gone away". One thing to note: I don't have the error when hooking onto Pagefile::httpUrl, and the only difference between this method and the two others is this condition on line 862, calling Wire::__call. Maybe this is where the culprit is ? Does it go into a loop of some sort it can't escape ? I have the same issue both on my client's server and locally. Context: I'm trying to change (in ready.php) the return of Pagefile::url to use a subdomain pointing to site/assets/files. Does it ring a bell to someone ? Many thanks in advance !
-
@Robin S, bouncing on your mockup, I'm not sure if mixing permanent / appear-on-hover UI is good for the end user. To me, what seems to be the issue is the visual space PW's UI takes and I think it could (partially) be solved by allowing (in the field's settings) to remove the label + padding around it. Mixed with the inline CKEditor, it almost looks like your screenshot, except that it's still clear we're still dealing with "components" that the user can move around.
-
Hey, My 2 cents on the page layout / builder : about editor.js, I see it more as a nice-looking alternative to CKEditor than something genuinely different in what it offers (apart from for the structured data) and it seems a bit limited to be a page builder more than what is already available to us. And I agree with your pros & cons @ryan. But I do think that adding some improvements to the RepeaterMatrix module, which we all seem to use as a "page builder", is a good way to go. As much as I don't want my clients to have too much freedom when it comes to the layout, I think there could be a way to introduce a "layout abstraction" into RM, something simple and limited, but that could give more flexibility. In a (distant?) way, it would be like giving the user the ability we have, as admins, to define fields' width or group them in a fieldset. I drafted some screenshots to show what I had in mind, that could be "user-friendly" (close to what @Jonathan Lahijani showed in his video). The idea would be to have "layouts" which would be described just like RM items but instead contain abstract "containers". Just like you would with fields, you could change the width of said containers, and make sure they add up to 100%. Then in the page editor where your RM is, you would have the possibility to either add a "layout" or an item. A layout and its containers would reflect the way we described them in the settings, re: width. To show that the layout is something different, we could use the secondary color. And this could be how we translate that into (hopefully not with repeating parts like mine) code: <?php foreach($page->test_matrix as $item) { if($item->type == 'matrix_layout') { // reserved type name if($item->layoutType == 'two-columns') { echo '<div class="grid">'; foreach($item->subItems as $subItem) { echo '<div class="column-1-2">'; if($subItem->type == 'type_text') { echo $subItem->text; } else if($item->type == 'type_image') { echo $subItem->image->render(); } echo '</div>'; } echo '</div>'; } } else if($item->type == 'type_text') { echo $item->text; } else if($item->type == 'type_image') { echo $item->image->render(); } } A few notes : Don't be fooled by my screenshots, I just messed around with Firefox's dev tools. To keep things simpler a layout should not contain another layout. The page editor may become too dense, even unpractical, if there is too much containers. Maybe a toggle on a container to expand it along the horizontal axis could be a solution ? End of my 2 cents. (also : I like how @bernhard is removing the field's label to gain space and I think it could be nice to have such option in the core, like "☑️ Do not display the field's label". Of course it would then remove the ability to collapse the field, but it would be a conscious choice. Edit : this is especially useful in context where you use RM and have 1-field types, like I used in my example above)
-
Question regarding "2006 MySQL server has gone away"
monollonom replied to monollonom's topic in General Support
I just wanted to be sure that it wasn't me just trying too hard to find a bug for my problem, but I will go ahead and fill one on Github. Thanks again. Edit: we'll see how it goes -
Question regarding "2006 MySQL server has gone away"
monollonom replied to monollonom's topic in General Support
Since I'm able to reproduce the error after exactly 60 seconds, this clearly indicates that the wait_timeout MySQL settings of my server is set to 60. A fix could be to increase it, but it doesn't change the fact that the execute function from WireDatabasePDO does not work as advertised. I mean, it does retry to execute the query, but since it's tied to the previously failed PDO connection, it doesn't work as expected. What could be done is to re-prepare the query after the creation of a new PDO connection. However, since you can't access the binded values from the PDOStatement, an idea could be to create a custom PDOStatement (like the one used for debugging), that would keep a track of binded values so that if you recreate the query, you can re-bind the values and thus re-execute the complete query. (at least from my understanding based on the informations I gathered, I might be completely wrong !) -
Question regarding "2006 MySQL server has gone away"
monollonom replied to monollonom's topic in General Support
Hi @netcarver, Could you point me out how to check if my code is forking a process ? You're mentioning IDs, from which object could I print it to Tracy ? To me, I am just doing a single thing (create variations) so I don't really see why it would fork. Trying further, and to reproduce the problem using in a simpler case, I managed to trigger a "2006 MySQL server has gone away" using this in the Tracy console : $page->of(false); $title = $page->title; $page->title = "Test"; $page->save(); sleep(60); $page->title = $title; $page->save(); return "ok"; I'm making several tests in the WireDatabasePDO file to see if I can get something out of it. -
Hi again, The reason I went for creating a hook generating image variations when uploading was to avoid the "reload the front-end page until you have all your variations generated", because each time I was getting this error "2006 MySQL server has gone away". But it kept happening, even with the splitted ajax calls. I do generate a lot of variations (3 sizes + webp variants for 10+ images per page), so I understand it takes a lot time for Imagick (and memory, both of which I increased) but I'm assuming it shouldn't impact MySQL, especially since the connection is supposed to be closed / recreated up to three times if you get this error. However, reading the code, I can see the connection is correctly closed but is it actually recreated on the next try ? It's obviously getting too technical to me, but my question would be: if a PDOStatement is executed and the connection is closed, does it try to reconnect by itself ? Or I am right assuming there is someting missing here ? Like a new call to the prepare() function, which then recreate the pdo ? It's mostly a question for @ryan but maybe someone else could tell me ? Many thanks in advance ! Edit: Github issue created
-
Thanks for the pointer @adrian ! Here is what I ended up with : <?php class ImageCreateVariations extends WireData implements Module { public static function getModuleInfo() { return array( "title" => "ImageCreateVariations", "version" => 100, "summary" => "", "href" => "", "singular" => true, "autoload" => true ); } public function init() { if ($this->wire('page')->process == "ProcessPageEdit") { $this->addHookAfter("InputfieldFile::fileAdded", $this, "sizeImage"); } else { $this->addHookAfter("Pagefile::install", $this, "sizeImage"); } } public function sizeImage($event) { $inputfield = $event->object; if ($event->method == "install") { $inputfield = $inputfield->pagefiles->getField(); } if ($inputfield->name != "gallery" && $inputfield->name != "image") return; if ($event->method == "install") { $image = $event->object; } else { $image = $event->arguments(0); } $sizes = [300, 600, 1200, 1800]; foreach ($sizes as $size) { $retina = $size * 2; if ($retina >= $image->width) { $image->width(floor($image->width / 2)); break; } $image->width($size); $image->width($retina); } } } I simplified your condition in line 94, but maybe it's the wrong thing to do ? Anyway it now works as expected so thanks again !
-
My apologies, you were also right @Zeka ! As the parent_id does not persist after ___renderAddable, I'm adding the same hook for both functions in my ready.php : $wire->addHookBefore('InputfieldPage::renderAddable', null, "changeParentId"); $wire->addHookBefore('InputfieldPage::processInputAddPages', null, "changeParentId"); function changeParentId($event) { $inputfieldPage = $event->object; $page = $inputfieldPage->hasPage; if($inputfieldPage->hasField == "subcategories") { if ($page->category) { $inputfieldPage->set("parent_id", $page->category->id); } } } And it works great ! Thank you !
-
Hm this is actually happening when saving the page, while I was looking to be able to show the "Create new" link in the admin panel. Sorry I must have not been clear enough in my post. But you pointed me to the right place to look at, I think I should instead change the parent_id in a beforeHook of https://github.com/processwire/processwire/blob/master/wire/modules/Inputfield/InputfieldPage/InputfieldPage.module#L682
-
Hi, I'm looking for the right hook to change the parent_id property of an InputfieldPage. I have another InputfieldPage in my template which determines the parent of the selectable pages using this hook : $wire->addHookAfter("InputfieldPage::getSelectablePages", function($event) { $page = $event->arguments(0); if($event->object->hasField == "subcategories") { if ($page->category) { $event->return = $event->pages->find("template=subcategory,parent=$page->category"); } else { $event->return = []; } } }); But in order to be able to create new pages using the field I need to dynamically change the parent_id before it [the field] is created in the edit page. What would be the right hook (or way ?) to do so ? Thanks !
-
ProcessWire .htaccess adding URL parameter to redirects
monollonom replied to FireWire's topic in General Support
I'm going to have to do the same — migrate a website to Processwire and redirect to new pages’ url if need be — but I thought of using the Page Path History (core) module and its ability to add new redirect URLs per page. Have you tried it ? Have anybody used it that way ?- 15 replies
-
- multilanguage
- redirects
-
(and 2 more)
Tagged with:
-
processwire.dev — Tutorials for web development with ProcessWire
monollonom replied to MoritzLost's topic in Tutorials
Thank you for sharing ! I've already had a good read and it's interesting to see your way of dealing with PW. I'm not sure I'm into Twig, but I really like the way you're organising your files and allowing to use composer / nodejs, I'll try that in my next project. I would also be interested to read more about your development flow, like how you deal with git or the transition between local and prod environments.