Jump to content

Flashmaster82

Members
  • Posts

    166
  • Joined

  • Last visited

Everything posted by Flashmaster82

  1. Ok thanks i will have a second look at it. It works now but the code can be optimized.
  2. Update current code $this->addHookAfter("ProcessPageAdd::buildForm", function(HookEvent $event) { $form = $event->return; $parentField = $form->getChildByName('parent_id'); $parent = pages()->get($parentField->value); if (!$parent->matches('template=dashboard_customer')) return; $form->_pw_page_name->collapsed = Inputfield::collapsedHidden; $form->_pw_page_name->value = 'Arbete'; $form->title->collapsed = Inputfield::collapsedHidden; }); $this->addHookAfter('Pages::added', function(HookEvent $event) { $page = $event->arguments(0); //same as above: only run under certain parents if (!$page->matches('parent.template=dashboard_customer')) return; $page_id = $page->id; $label = $page->template->label; $parent_address = $page->parent->address; $parent_ort = $page->parent->ort->title; $page->setAndSave('name', "$page_id $label $parent_address $parent_ort"); }); $wire->addHookAfter('Pages::saved', function(HookEvent $event) { $page = $event->arguments[0]; if (!$page->matches('template=dashboard_services_bathroomrenovations_servicepage|dashboard_services_demolitions_servicepage|dashboard_services_extensions_servicepage|dashboard_services_recyclings_servicepage|dashboard_services_totalrenovations_servicepage')) return; $id = $page->id; if ($page->customer_project_address === 0) { $address = $page->parent->address; $ort = $page->parent->ort->title; } else if ($page->customer_project_address === 1) { $address = $page->address; $ort = $page->ort->title; } $template_label = $page->template->label; $page->setAndSave('title', "($id) $template_label | $address, $ort", ['noHooks' => true]); $page->setAndSave('name', "$id $template_label $address $ort", ['noHooks' => true]); });
  3. Wow impressive reply thanks! Master class.. This is my current code $this->addHookAfter("ProcessPageAdd::buildForm", function(HookEvent $event) { $form = $event->return; $parentField = $form->getChildByName('parent_id'); $parent = pages()->get($parentField->value); if (!$parent->matches('template=dashboard_customer')) return; $form->_pw_page_name->collapsed = Inputfield::collapsedHidden; $form->_pw_page_name->value = 'Arbete'; $form->title->collapsed = Inputfield::collapsedHidden; }); $this->addHookAfter('Pages::added', function(HookEvent $event) { $page = $event->arguments(0); //same as above: only run under certain parents if (!$page->matches('parent.template=dashboard_customer')) return; $parent_address = $page->parent->address; $parent_ort = $page->parent->ort->title; $page->setAndSave('name', "{$page->id}_{$page->template->label}"); }); Also and i forgot to mention that i have another function below. $wire->addHookAfter('Pages::saved', function(HookEvent $event) { $page = $event->arguments[0]; if (!$page->matches('template=dashboard_services_bathroomrenovations_servicepage|dashboard_services_demolitions_servicepage|dashboard_services_extensions_servicepage|dashboard_services_recyclings_servicepage|dashboard_services_totalrenovations_servicepage')) return; $id = $page->id; if ($page->customer_project_address === 0) { $address = $page->parent->address; $ort = $page->parent->ort->title; } else if ($page->customer_project_address === 1) { $address = $page->address; $ort = $page->ort->title; } $template_label = $page->template->label; $page->setAndSave( 'title', "($id) $template_label | $address, $ort" ); }); And now i when i add a new page this function overrides the title field. I also want that when adding a new page . I want to have the title field in the template as a title but the field itself is hidden and not editable. The id is important because this is an invoice system so the id is the invoice nr btw. So i do want the title to be populated when adding a new page just like the second function when saving. Maybe they are interfering with each other.. I guess your code only targeting the name field. Also when i use the second function i have to save the page twice to change the name field (url). hmm
  4. Ok i think i fixed it now. $this->addHookAfter("ProcessPageAdd::buildForm", function(HookEvent $event) { $form = $event->return; $parentField = $form->getChildByName('parent_id'); $parent = pages()->get($parentField->value); if (!$parent->matches('template=dashboard_customer')) return; $pageid = $page->id; $template = basename($page->template->label,'.php'); $nameField = $form->getChildByName('_pw_page_name'); $nameField->wrapClass = 'InputfieldHidden'; $nameField->value = "($pageid) $template"; $titleField = $event->return; if(!$titleField->has('title')) return; $titleField->title->collapsed = Inputfield::collapsedHidden; });
  5. Thank you for the explanation. I got it working now!! Current code $this->addHookAfter("ProcessPageAdd::buildForm", function(HookEvent $event) { $form = $event->return; $parentField = $form->getChildByName('parent_id'); $parent = pages()->get($parentField->value); if (!$parent->matches('template=dashboard_customer')) return; $pageid = $page->id; $parentaddress->parent->address; $nameField = $form->getChildByName('_pw_page_name'); $nameField->wrapClass = 'InputfieldHidden'; $nameField->value = "($pageid) $parentaddress"; }); Only thing is that when i uncheck the Title global field, it won´t show up on the rest of the pages, only want to not show up at the specific templates. Don´t know how to fix that..
  6. My brain is exploding haha. Trying to understand everything. Current code $this->addHookAfter("ProcessPageAdd::buildForm", function(HookEvent $event) { $form = $event->return; $parentField = $form->getChildByName('parent_id'); $parent = pages()->get($parentField->value); if ($parent->matches('dashboard_servicepage_totalrenovation|dashboard_servicepage_bathroomrenovation|dashboard_servicepage_extension|dashboard_servicepage_demolition|dashboard_servicepage_recycling')) return; $nameField = $form->getChildByName('_pw_page_name'); $nameField->wrapClass = 'InputfieldHidden'; $nameField->value = 'Newpage'; }); It works when adding a page and everything but when i add a new page elsewhere there is no title or name field... My parent template for the customer is "dashboard_customer" and the service templates children are dashboard_servicepage_totalrenovation dashboard_servicepage_bathroomrenovation dashboard_servicepage_extension dashboard_servicepage_demolition dashboard_servicepage_recycling also i did try to get the template label in the last function of ready.php but with no luck $wire->addHookAfter('Pages::saved', function(HookEvent $event) { $page = $event->arguments[0]; if ($page->matches('dashboard_servicepage_totalrenovation|dashboard_servicepage_bathroomrenovations|dashboard_servicepage_extensions|dashboard_servicepage_demolitions|dashboard_servicepage_recyclings')) return; $id = $page->id; if ($page->customer_project_address === 0) { $address = $page->parent->address; } else if ($page->customer_project_address === 1) { $address = $page->address; } $t = $templates->get("dashboard_servicepage_totalrenovation|dashboard_servicepage_bathroomrenovation|dashboard_servicepage_extension|dashboard_servicepage_demolition|dashboard_servicepage_recycling"); $t->label; $page->setAndSave('title', "($id) $t $address", ['noHooks' => true]); });
  7. $this->addHookAfter("ProcessPageAdd::buildForm", function(HookEvent $event) { if ($page->matches('dashboard_servicepage_totalrenovation|dashboard_service_bathroomrenovation|dashboard_service_extension|dashboard_service_demolition|dashboard_service_recycling')) return; $form = $event->return; $nameField = $form->getChildByName('_pw_page_name'); $nameField->wrapClass = 'InputfieldHidden'; $nameField->value = 'Newpage'; }); Hmm i got an error on this.. Fatal Error: Uncaught Error: Call to a member function matches() on null in E:\Wamp\www\MyWebsite\site\assets\cache\FileCompiler\site\ready.php:5 #0 E:\Wamp\www\MyWebsite\wire\core\WireHooks.php(915): ProcessWire->{closure}(Object(HookEvent)) #1 E:\Wamp\www\MyWebsite\wire\core\Wire.php(465): WireHooks->runHooks(Object(ProcessPageAdd), 'buildForm', Array) #2 E:\Wamp\www\MyWebsite\wire\modules\Process\ProcessPageAdd\ProcessPageAdd.module(525): Wire->__call('buildForm', Array) #3 E:\Wamp\www\MyWebsite\wire\core\Wire.php(394): ProcessPageAdd->___execute() #4 E:\Wamp\www\MyWebsite\wire\core\WireHooks.php(823): Wire->_callMethod('___execute', Array) #5 E:\Wamp\www\MyWebsite\wire\core\Wire.php(465): WireHooks->runHooks(Object(ProcessPageAdd), 'execute', Array) #6 E:\Wamp\www\MyWebsite\wire\core\ProcessController.php(337): Wire->__call('execute', Array) #7 E:\Wamp\www\MyWebsiteg\wir (line 5 of E:\Wamp\www\MyWebsite\site\assets\cache\FileCompiler\site\ready.php) This error message was shown because: you are logged in as a Superuser. Error has been logged. I only want to do this bypass on just these templates, when i add a new page elsewhere i get an error.
  8. You sir deserves a medal ? That worked. Changed the second functions with setAndSave also. I dont getting the template label though.. maybe you can give me some help tomorrow, thanks again.
  9. Hi again and thank you for that very detailed feedback ? My site is really complex so its hard to explain everything. I have a website for our company and also i´m working on a dashboard/invoice system that you also can view in password protected view on the site. I did uncheck the global settings for the title "worked" and also implemented your code in ready.php as you can see futher down. So now when i add new page i can choose a template and then it goes to the page "nice". I also have a function in ready.php the third one as you can see that changes the title based on a few things. My problem now is that i have a repeater field in the template and when i add something to that and save an error displays, code below ready.php and also another thing in the last function in ready.php i want to display the label of the template but its not working ? maybe you can see whats wrong with everything, i´m not the best programmer. I didn´t change anything in your code except the namefield, dont know what to do with the _pw_page_name and InputfieldHidden. When i have the first function and the third function in ready.php it doesnt work with the repeater field? Also if possible i only want a couple of templates to bypass the add page stage. Thank you so much for the help so far btw. <?php $this->addHookAfter("ProcessPageAdd::buildForm", function(HookEvent $event) { $form = $event->return; $nameField = $form->getChildByName('_pw_page_name'); $nameField->wrapClass = 'InputfieldHidden'; $nameField->value = 'Newpage'; }); $wire->addHookAfter('Pages::saved', function(HookEvent $event) { $page = $event->arguments(0); $geo = new \OpenCage\Geocoder\Geocoder('API-key'); if ($page->matches('customer_project')) return; $address_parents = $page->parent->address; $addresss = $page->address; $address_parent = str_replace( ' ', '%20', $address_parents) . ","; $address = str_replace(' ', '%20', $addresss) . ","; $zip_parent = str_replace( ' ', '', $page->parent->zipcode); $zip = str_replace(' ', '', $page->zipcode); $ort_parent = $page->parent->ort->title; $ort = $page->ort->title; if ($page->customer_project_address === 0) { $result = $geo->geocode("{$address_parent}%20{$zip_parent}%20{$ort_parent}", ['language' => 'Sweden', 'countrycode' => '+46']); $first = $result['results'][0]; $coordinates = $first['geometry']['lat'] . ',' . $first['geometry']['lng']; $page->setAndSave('mapping3', $coordinates); } else if ($page->customer_project_address === 1) { $result = $geo->geocode("{$address}%20{$zip}%20{$ort}", ['language' => 'Sweden', 'countrycode' => '+46']); $first = $result['results'][0]; $coordinates = $first['geometry']['lat'] . ',' . $first['geometry']['lng']; $page->setAndSave('mapping3', $coordinates); } }); $wire->addHookAfter('Pages::saved', function(HookEvent $event) { $page = $event->arguments[0]; if ($page->matches('dashboard_servicepage_totalrenovation|dashboard_service_bathroomrenovations|dashboard_service_extensions|dashboard_service_demolitions |dashboard_service_recyclings')) return; $id = $page->id; if ($page->customer_project_address === 0) { $address = $page->parent->address; } else if ($page->customer_project_address === 1) { $address = $page->address; } $page->setAndSave('title', "($id) {$template->label} | $address"); }); ?> Fatal Error: Uncaught Error: Maximum function nesting level of '256' reached, aborting! in E:\Wamp\www\MyWebsite\wire\core\Page.php:1138 #0 E:\Wamp\www\MyWebsite\wire\core\Page.php(1138): is_int(false) #1 E:\Wamp\www\MyWebsite\wire\modules\Fieldtype\FieldtypeRepeater\RepeaterPage.php(192): Page->get('templates_id') #2 E:\Wamp\www\MyWebsite\wire\core\Page.php(1846): RepeaterPage->get('templates_id') #3 E:\Wamp\www\MyWebsite\wire\core\PagesType.php(228): Page->__get('templates_id') #4 E:\Wamp\www\MyWebsite\wire\core\Pages.php(1735): PagesType->hasValidTemplate(Object(RepeaterPage)) #5 E:\Wamp\www\MyWebsite\wire\core\Wire.php(397): Pages->___saveReady(Object(RepeaterPage)) #6 E:\Wamp\www\MyWebsite\wire\core\WireHooks.php(823): Wire->_callMethod('___saveReady', Array) #7 E:\Wamp\www\MyWebsite\wire\core\Wire.php(465): WireHooks->runHooks(Object(Pages), 'saveReady', Array) #8 E:\ (line 1138 of E:\Wamp\www\MyWebsite\wire\core\Page.php) This error message was shown because: you are logged in as a Superuser. Error has been logged.
  10. So my idea with this is like when you have added an customer page, then the customer wants a new service let say "Renovation" that we can add a new page choose the renovation template and it will autogenerate a new name. This is the optimal way i think because what name is other people that uses this gonna name it.. And also we have like smaller jobs like delivery so then its hard to make a new name that is easy to read if you have many jobs from the customer. So the end result would look like this in the tree (1234) Renovation June 25 (2343) Delivery Aug 8 (6532) Recycling May 6 (3533) Renovation Jan 16
  11. Exactly.. Auto generate page title like "page->id page->referencefield->title date" like (1234) Referencetitle June 15. I think i will hide the title field for now.
  12. So i have come to realise that i need to autochange the page title instead when add new.
  13. I woudl like to have the name of the template file or the template label with page id and maybe a date that i set in a datetime field later on. 1234 | June 23 | Renovation for example. But i need to set this custom for each template if possible.
  14. I have a page with 5 different templates to choose from when adding a new page. I want to have individual default page names on every new pages that is added as child. I know the function "Name format children" but i only works if you have a single template file attached to the page. Or can i make a default name on each template instead? Hook? Please help!
  15. Thanks for the great reponse i will try to implement this and see if i can get it working.
  16. How do you output only the lat and longitude from the field?
  17. I tried to make an overview of everything so its easier. Well if i have hundreds of addresses it would then make the loading time to a minute ? That´s why i trying to fetch the lat/long json file on every page so that it only needs to request the lat/long coordinates from the field in the map page instead of calling hundreds of json files when visiting the site. So thats why i wanted to have the if statements before the foreach inside ready.php so it wont call the opencagedata twice on every page. The toggle field inside the template (customer_project) is asking for an address inside the template and on the parent page so if i then have them both populated it would then request double operation. Only want one coordinate from every page on the map page. It is working as intended but its the IF statement that i´m struggling with right now. Maybe also the whole process can be faster somehow.
  18. $found = $pages->find('template=customer_project'); $geo = new \OpenCage\Geocoder\Geocoder('API-KEY'); if ($found->customer_project_address === 0){ $result_parent = $geo->geocode("Location", ['language' => 'Sweden', 'countrycode' => '+46']); $first = $result_parent['results'][0]; $coordinates = $first['geometry']['lat'] . ',' . $first['geometry']['lng']; } else if ($found->customer_project_address === 1){ $result = $geo->geocode("Another location", ['language' => 'Sweden', 'countrycode' => '+46']); $first = $result['results'][0]; $coordinates = $first['geometry']['lat'] . ',' . $first['geometry']['lng']; } foreach ($found as $p): { $p->setAndSave('my_location_field',$coordinates); } endforeach; This is my current code. It´s fetching a geolocation with longitude and latitude. But the IF Statements are outside the foreach. I only want one request per page because its slowing down the whole site and admin otherwise. The "customer_project_address" is a toggle field btw. I´m using Opencage to fetch the long/lat from an address in the pages. My purpose of this is to put just put addresses in the pages to then get markers on a map later on. There is modules for this i know but they comes with a map inside admin also which i dont want. Also they cant be inside groups/repeaters etc thats why im doing this instead. But maybe its better to do something with a hook, dont know how to do that though, im no the most experienced programmer only beginner.
  19. You are a life saver Elabx thanks!! That worked.. I´m now facing another problem $found = $pages->find('template=customer_project'); if ($found->customer_project_address === 0){ $coordinates = "Hello world"; } foreach ($found as $p){ $p->setAndSave('location',$coordinates); } customer_project_address is a toggle button that i´m trying to target. But the IF statement just don´t work here i don´t know why.. I needs to be outside the foreach btw. Do you have any clues?
  20. Hi i need some help to solve this. I need to save a specific value when saving a page $p = $pages->get('template=customer_project'); $p->location = "Hello world"; $page->save($p); This is my code right now in ready.php. location is my field "text field" inside template "customer_project". Right now when i refresh a page with the template it only populates one page? I want every page that has this field "location" to say Hello world and save it to the database? Don´t know if a hook is better.. PLEASE HELP!!!
  21. Its not working inside repeaters, groups or closed.. Any Fix?
  22. Also if you want to preview the PDF when working on the styling. I added ob_clean(); because otherwise it only works in Firefox. <?php $pdf = $modules->get('WirePDF'); ob_clean(); $pdf->markupMain = $config->paths->templates . 'pages2pdf/custom.php'; $pdf->markupFooter = $config->paths->templates . 'pages2pdf/custom_footer.php'; $pdf->cssFile = $this->config->paths->templates . 'pages2pdf/custom_style.css'; $pdf->pageOrientation = 'P'; $pdf->pageFormat = 'A4'; $pdf->bottomMargin = 10; $pdf->download('pages2pdf/custom.pdf'); echo "<a href='{$config->urls->templates}pages2pdf/custom.pdf' download>Download PDF</a>"; ?>
  23. For anyone with the same problem here is my code for generating custom and multiple pdf´s on the same page with different content and styling. <?php $pdf = $modules->get('WirePDF'); $pdf->markupMain = $config->paths->templates . '/pages2pdf/custom.php'; $pdf->markupFooter = $config->paths->templates . '/pages2pdf/custom_footer.php'; $pdf->cssFile = $this->config->paths->templates . '/pages2pdf/custom_style.css'; $pdf->pageOrientation = 'P'; $pdf->pageFormat = 'A4'; $pdf->bottomMargin = 10; $pdf->save('pages2pdf/custom.pdf'); echo "<a href='{$config->urls->templates}pages2pdf/custom.pdf' download>Download PDF</a>"; ?>
  24. Hi, i need some help from you prefessionals. I need to generate multiple pdf´s on the same page but with different content and styling. So you could have the folder for example /pages2pdf _footer.php, _header.php, _default.php, styles.css _footer2.php, _header2.php, _default2.php, styles2.css etc.. This is my generated button from the module i have now. So i need multiple buttons on the same page that generates different content and styling. <?php $options = array( 'title' => 'Print PDF', 'markup' => '<a href="{url}" target="_blank" title="OFFERT" rel="noopener"><div class="button secondary-button">OFFERT</div></a>', 'page_id' => '', // Pass a page ID if you want to download the PDF for another page ); echo $modules->get('Pages2Pdf')->render($options);?> Is that possible? Please somebody help...
×
×
  • Create New...