Jump to content

Flashmaster82

Members
  • Posts

    182
  • Joined

  • Last visited

Everything posted by Flashmaster82

  1. It worked like a charm. Thank you so much!!! I tried to specify the parent but i didnt worked? $wire->addHookAfter('Pages::added', function(HookEvent $event) { $page = $event->arguments(0); if($page->template != 'booking, parent=/nya-bokningar/') return; $selectable_pages = $page->getInputfield('booking_searchactivator_option')->getSelectablePages($page); $first_selectable_page = $selectable_pages->eq(0); $page->setAndSave('booking_searchactivator_option', $first_selectable_page); });
  2. I want to select the first option in a page reference fieldtype when adding a new page (admin). Dont want to target the option id because the value may change. Field = booking_searchactivator_option Template = booking Page reference template = searchactivator My current code is only targeting the page id and not the value. So now it becomes id=1. Also i want to be able to change the value to the second value, third value / position in the dropdown. $wire->addHookAfter('Pages::added', function(HookEvent $event) { $page = $event->arguments(0); if (!$page->matches('template=booking')) return; $aktivator = 1; $page->setAndSave('booking_searchactivator_option', $aktivator); }); i also have another hook that removes already selected page references. $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { $page = $event->arguments(0); if($event->object->hasField == 'booking_searchactivator_option') { $pages = $event->wire()->pages; $already_selected_on_another_page = $pages->find("template=searchactivator, booking_searchactivator_option.owner.template=booking, booking_searchactivator_option.owner.id!=$page->id"); $event->return = $event->pages->find("template=searchactivator, sort=sort, id!=$already_selected_on_another_page"); } }); Please help!!
  3. Thank you so much for the solution it worked! This is my current code. $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { $page = $event->arguments(0); if($event->object->hasField == 'booking_searchactivator_option') { $pages = $event->wire()->pages; $already_selected_on_another_page = $pages->find("template=searchactivator, booking_searchactivator_option.owner.template=booking, booking_searchactivator_option.owner.id!=$page->id"); $event->return = $event->pages->find("template=searchactivator, id!=$already_selected_on_another_page"); } }); Page reference field: booking_searchactivator_option Template that is referred to in the reference field: searchactivator Template that "booking_searchactivator_option" is used on: booking Selector string in the settings: parent=/sokaktivatorer/, template=searchactivator, sort=name I don´t know what the "owner" does though? If i remove it then it will break? /Thanks
  4. I have a couple of pages that has a specific template. In the template i have a page reference field (Activator). What im trying to achive is when i select an option in the dropdown (Activator) in admin and save, then the specific option is disabled (greyed out) in all of the other pages that has the page reference field (Activator). So basically you can only select one specific option once. But when i unselect the same one i want it to be reset and can be selected again in other pages. Please help!
  5. You can only have Jpg images so try and change and see if it works.
  6. I used this module on my website, but then i unprotected all pages, but in Google results it still says "protected page login etc"? How to fix this?
  7. Is it possible to duplicate/Clone the module so that you have 2 different Forms/Template/Fields/Settings/Admin?
  8. That worked! Yaay. Thanks. I´m only a beginner at php, so it´s not that easy for me ?
  9. Well im lost ? This is my current code $page->setAndSave([ 'title' => "($id) $template_label | $address, $ort", 'name' => "$id $template_label $address $ort", 'noHooks' => true ]); and its exactly like in the docs..? https://processwire.com/api/ref/page/set-and-save/
  10. Fatal Error: Uncaught Error: Maximum function nesting level of '256' reached, aborting! in E:\Wamp\www\Website\wire\core\Fieldgroup.php:81 #0 E:\Wamp\www\Website\wire\core\Fieldgroup.php(81): is_int('language') #1 E:\Wamp\www\Website\wire\core\Fieldgroup.php(242): Fieldgroup->isValidKey('language') #2 E:\Wamp\www\Website\wire\core\Page.php(1261): Fieldgroup->getField('language') #3 E:\Wamp\www\Website\wire\core\Page.php(1471): Page->getField('language') #4 E:\Wamp\www\Website\wire\core\User.php(451): Page->getFieldValue('language', '') #5 E:\Wamp\www\Website\wire\core\Page.php(1221): User->getFieldValue('language') #6 E:\Wamp\www\Website\wire\core\Page.php(1846): Page->get('language') #7 E:\Wamp\www\Website\wire\core\PageFinder.php(2070): Page->__get('language') #8 E:\Wamp\www\Website\wire\core\PageFinder.php(1695): PageFinder->getQuerySortSelector(Object(Database (line 81 of E:\Wamp\www\Website\wire\core\Fieldgroup.php) This error message was shown because: you are logged in as a Superuser. Error has been logged. $wire->addHookAfter('Pages::saved', function(HookEvent $event) { $page = $event->arguments[0]; if (!$page->matches('template=dashboard_services_bathroomrenovation_servicepage|dashboard_services_demolition_servicepage|dashboard_services_extension_servicepage|dashboard_services_recycling_servicepage|dashboard_services_totalrenovation_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", 'name' => "$id $template_label $address $ort", 'noHooks' => true ]); });
  11. $page->setAndSave([ 'title' => "($id) $template_label | $address, $ort", 'name' => "$id $template_label $address $ort", 'noHooks' => true ]); This should be correct but not working https://processwire.com/api/ref/page/set-and-save/
  12. $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_nonprofit_association|dashboard_customer_municipality_authority|dashboard_customer_housing_cooperative|dashboard_customer_company|dashboard_customer_client_contractor|dashboard_customer_private_person')) 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); if (!$page->matches('parent.template=dashboard_customer_nonprofit_association|dashboard_customer_municipality_authority|dashboard_customer_housing_cooperative|dashboard_customer_company|dashboard_customer_client_contractor|dashboard_customer_private_person')) return; $page_id = $page->id; $label = $page->template->label; $parent_address = $page->parent->address; $parent_ort = $page->parent->ort->title; $page->setAndSave('title', "($page_id) $label | $parent_address, $parent_ort", ['noHooks' => true]); $page->setAndSave('name', "$page_id $label $parent_address $parent_ort", ['noHooks' => true]); }); $wire->addHookAfter('Pages::saved', function(HookEvent $event) { $page = $event->arguments[0]; if (!$page->matches('template=dashboard_services_bathroomrenovation_servicepage|dashboard_services_demolition_servicepage|dashboard_services_extension_servicepage|dashboard_services_recycling_servicepage|dashboard_services_totalrenovation_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]); }); Currrent code. It works, only thing is that because i have multiple language i have to save twice to change the url.. And of course to many setandsave. I tried with this below but no luck.. $page->setAndSave([ 'title' => "($id) $template_label | $address, $ort", 'name' => "$id $template_label $address $ort", ['noHooks' => true] ]);
  13. Ok thanks i will have a second look at it. It works now but the code can be optimized.
  14. 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]); });
  15. 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
  16. 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; });
  17. 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..
  18. 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]); });
  19. $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.
  20. 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.
  21. 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.
×
×
  • Create New...