Jump to content

suntrop

Members
  • Posts

    322
  • Joined

Everything posted by suntrop

  1. Hi. I am not sure if I got what what you want correctly. But have you checked th redirect isn’t cached? Topically browsers chance 301 redirects. Other than that, if a user with two roles assigned and one has view permission and one has not the user itself will have permission to view that page.
  2. // EDIT It works now. There is a conflict with another Pages::saveReady hook, that updates the title, when a particular field is changed. It seems $page->isChanged('fieldname') is true when I create a new page and the field was already set in the source. I'll see how to get a workaround for this.
  3. That is a nice solution! I will definitely try this if I can't get my hook to work … but I really would like to know what the problem is with my code. And when it works, I go and try your solution and compare them I am always happy to see how other people find their way to the same outcome. However, on that custom endpoint I would have to run just the same code and clone the page. Well … I'll test it now
  4. Yes. At the end I need three buttons and each must clone the page to different destinations, with different templates and different code that runs before the page gets saved. If here is just one clone button I can’t distinguish “how” the page needs to be copied.
  5. I'd like to add a button next to PW's built in Save button on the edit page to clone a page. I can't use the Clone module from PW, because there need to be some other code be executed. I had seen some related posts here, but my code doesn't work properly. When I click the button, the page will get cloned 6 times instead of only once. The page has a PageTable field on it with 5 sub-pages. Perhaps the hook gets executed for every child? It doesn't make any difference if I remove the $copy->save() action. Saved in /site/init.php wire()->addHookBefore('ProcessPageEdit::processInput', NULL, 'cloneAsOrder'); function cloneAsOrder($event) { $p = $event->object->getPage(); $event->replace = true; if ( wire()->input->post('submit_clone_as_order') ) { $parent = wire()->pages->get('/crm/accounting/order/'); $copy = wire()->pages->clone($p, $parent); // $copy->parent = '/crm/accounting/order/'; $copy->template = 'order'; $copy->title = 'UNFINISHED-'; $copy->name = 'unfinished-r327' . date('Y-m-d-h:i:s'); // $copy->removeStatus("published"); // $copy->addStatus("unpublished"); $copy->save(); // wire()->message('Copy created:' . $p->title . ' » <a href="' . $copy->url . '">' . $copy->title . '"</a>'); } } And … is it possible to clone a page without publishing it? I will need (later) a hook that hooks into the publishing method and save an order number. That number will come from a 'next doc number' and gets incremented automatically.
  6. JFYI — That loading screen won’t disappear on my iPad (iOS 11) Backend looks like a hell lot of work. ?
  7. Yes, I have. I would have to fork and modify Map Maker, because I need address in separate fields and with more data. And I need them to be manageable by PHP … I guess Map Maker counts on the JS API. And as wbmnfktr says, I really just need the lat/long … nothing more. I just figured out, where the conversion takes place. I put this into my wwwroot <?php include 'index.php'; // setlocale(LC_NUMERIC, 'C'); $json = json_decode( '{"test": 48.8555648}' , true); var_dump($json); die(); The code prints: array(1) { ["test"]=> float(48,8555648) } When I don't include the PW bootstrap file (index.php) it prints: array(1) { ["test"]=> float(48.8555648) } When I include the index.php and uncomment the setlocale() it prints: array(1) { ["test"]=> float(48.8555648) } I don't think it has to do with the Textareas module, but how the locale is set in PW. I couldn't find much about setlocale(LC_NUMERIC, 'C') but it seems the C sets numeric values to C++ default type (e.g. 3.14 not 3,14). https://processwire.com/talk/topic/4123-decimal-point-changed-to-in-base-of-setlocale/?do=findComment&comment=142861 It doesn't work if I put the setlocale() into my /site/config.php or /site/template/_init.php However, it looks more like a bug and not like "this is how it should work"
  8. Sure! I have something like a store locator and need to store the latitude and longitude for each place. Therefore I created a field named "latlong" This field is of type "Textareas" and has two "Text" sub-fields "lat" and "long". When I save a page the fields contents (the coordinates) are getting converted, the point turns into a comma This happens since I installed the German language pack. Prior saved locations don't have a comma saved. While the default German decimal separator is a comma, this conversion makes things very complicated. That is my hook in /site/ready.php $pages->addHookBefore('saveReady', function($event) { $page = $event->arguments[0]; if($page->template == 'location') { if ( empty($page->street) || empty($page->city) ) { return; } // Get address $address = $page->street . ', ' . $page->zip . ' ' . $page->city . ', ' . $page->country; // Get JSON results from this request $geo = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($address) . '&sensor=false'); $geo = json_decode($geo, true); if ($geo['status'] == 'OK') { $page->latlong->lat = $geo['results'][0]['geometry']['location']['lat']; $page->latlong->long = $geo['results'][0]['geometry']['location']['lng']; $this->message('Saved for: ' . $geo['results'][0]['formatted_address']); } else { $this->error('Error msg...'); } } });
  9. Does anybody know how to NOT convert these numbers ?
  10. Thanks for pointing to DC, sometimes it is ok to have it And that is some quiet simple code snippet ! Thanks again.
  11. Hi gmclelland. Thanks. Yes, that would be a way I would go. Maybe it's just me, but I would prefer not having an "invalid" URL – although if implemented as 301 it wouldn't be indexed by Google (but nonetheless doesn't count as a good link). And as I said, I really need to learn more about hooking into PW
  12. Sometimes I need pages in the site tree that are basically just a reference to another page – to redirect to the original page or display the same content under the new page url. I was surprised I couldn't find anything like that in the forum or as a module already. However, there is a new module by @Robin S but not exactly what I need. Example Home News Press Newsroom Media Services About Newsroom (virtual page for /news/newsroom/) Contact Example I: The page /about/newsroom/ should act as /news/newsroom/ – so, wehen I loop all pages for a sitemap both pages should have the URL /news/newsroom/. Example II: Another example (not often used) would be tu display the exact same content on /about/newsroom/ – although the page itself has no content on its own. Those examples don't have much in common, but they are just virtual or fake pages in the site tree. While the second one should be an easy task with wireRenderFile(), the first example isn't quite obvious to me. I think I have to use hooks and I have no idea where to start. I really appreciate you guys come up with a solution for everything, but I need to learn this myself So just some hints to start would be great! Do I put the code into a module or some of the _init.php, ready.php etc. files? Or do I have to use a template file (e.g. virtual-page.php)? When I look into Captain Hook – how do I find the appropriate point to hook into? (/wire/core/ Page.php and loaded()?) Do I need to create/manipulate each field separately (path, title, summary)? Sorry for the long read
  13. HI Robin. Thanks for checking. But I can't get this to work, double checked my wording. I am using PW 3.0.78. Perhaps we are using other "checkbox modules"? How can I tell what module this checkbox field is exactly? I am pretty sure I have not installed any module like this … but possibly I am wrong
  14. I have got a Textareas field (latlong) with two Text fields (lat and long). I query Google Maps for the coordinates and use a hook to save both fields. The problem is, after I installed the German language pack those fields are saved with a comma as decimal separator. But that doesn't work with Google Maps, because it needs 50.43578373748 and not 50,43578373748. As I remember Float can only take up to 7 points after the decimal point – so I can't just change it from Text to Float. Currently I just str_replace the decimal to a point in the template for my JSON fiel. But I was wondering if thee is a way I can tell PW to not convert the point to decimal – regardless of of the language.
  15. I thought it is possible within one selector … and I only have to rewrite my selector. My other solution looks better $page->children('highlight=1, sort=-chiffre')->add( $page->children('highlight=0, sort=-chiffre') )
  16. I know. The problem is it doesn't seem to work with checkboxes.
  17. Nobody loves my riddles It should read … "The 'checkbox' field is a default checkbox field, no special module" <?php foreach ($page->children('sort=-chiffre') as $child): ?> <div class="job <?= $child->highlight ? 'hightlight' : 'default' ?>">Chiffre <?= $child->chiffre ?> | <?= $child-title ?> – <?= $child->body ?></div> <?php endofreach ?> … will render … <div class="jobs"> <div class="job">Chiffre 734 | Job Title – Job Description …</div> <div class="job">Chiffre 732 | Job Title – Job Description …</div> <div class="job highlight">Chiffre 722 | Job Title – Job Description …</div> <div class="job">Chiffre 720 | Job Title – Job Description …</div> <div class="job">Chiffre 718 | Job Title – Job Description …</div> <div class="job highlight">Chiffre 605 | Job Title – Job Description …</div> </div> But what I need … <div class="jobs"> <div class="job highlight">Chiffre 605 | Job Title – Job Description …</div> <div class="job highlight">Chiffre 722 | Job Title – Job Description …</div> <div class="job">Chiffre 734 | Job Title – Job Description …</div> <div class="job">Chiffre 732 | Job Title – Job Description …</div> <div class="job">Chiffre 720 | Job Title – Job Description …</div> <div class="job">Chiffre 718 | Job Title – Job Description …</div> </div> … the pages with a checked "highlight" (the checkbox field) should be on top and ordered by the chiffre. The other pages should follow and ordered by chiffre too.
  18. Hi all! I want to sort child-pages by two fields but I don't know if it is possible within one selector or if I have to make two separate queries <?php foreach ($page->children('sort=checkbox, sort=-number') as $child): ?> I want to keep 'checked' pages on top and sort them and all following by the 'number' field. The 'checkbox' field is a
  19. That is great! Many thanks.
  20. I had added the title filed to the roles template. And I found I can configure the roles module to display other fields in the listing under Access > Roles – but currently I found no way to display the title instead the name on the user profile pages.
  21. On the user-edit page for example
  22. I would like to use the label for roles, as the label is used for templates. My role names are more technical and in englisch, but I would like to give them a more readable and lengthier name. When I edit the "role" template there is no field "templateLabel" I can add.
  23. I thought there is some hidden config and an easy step. Seems there is no option at all https://github.com/processwire/processwire/blob/master/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.module#L978 @adrian I am using labels, because template files are in Englisch, but my clients prefer a more eligible, German name. Will have a look tomorrow
  24. Yes, I am talking about the settings tab, so after the page is saved or for existing pages. The dropdown list is about 20 entries long and it is pretty hard to find the exact template you're looking for, because there is naturally no order. That is bad usability and I want it to sort in an alphabetically order to make it easier finding a template. The exact same use case goes for excluding templates that make no sense for the editor (like templates just for settings or "admin" pages, etc.).
  25. On the Settings-Tab you can select the template of a page. Two questions: How do I change the order of them? Currently it looks very messy and I would like to sort it alphabetically How do I exclude certain templates from this list? I couldn't find a system field for it and have looked at other field configs, but noting helped. I've got some pages I don't want my client to be selectable. I have set "Can this template be used for new pages?" to no, but that doesn't work.
×
×
  • Create New...