Jump to content

How to autogenerate page name when add new page? Multiple templates.


Flashmaster82
 Share

Recommended Posts

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
    ]);

});

 

Link to comment
Share on other sites

Come on, man, you can do this ? That’s the same error message from before. Also, like I said, I’m pretty sure you just had to move the one ] to a different place. The number of brackets was correct.

I haven’t been on the computer much today. I can look at the language stuff tomorrow, if you want.

Btw a good “trick” is to just skim the actual source code of PW methods. I often find the docs a little lacking, unfortunately. Ryan’s code is quite readable, and usually one is only interested in what happens to the arguments, where best to hook etc. Somewhat superficial stuff like that, if you will, so it’s not too bad.

For example, it seems your code is mixing up the fielname/value array and the options array when calling setAndSave(). PW functions often takes multiple different types in multiple different places, which can be a blessing and a curse.

  • Thanks 1
Link to comment
Share on other sites

No, because unfortunately the docs don’t show an example with multiple fields and the options array.

I may be wrong and it’s a little difficult to see on mobile, but I would say it needs to be two separate arrays, like this:

12 minutes ago, Flashmaster82 said:
 $page->setAndSave([
     'title' => "($id) $template_label | $address, $ort",
     'name' => "$id $template_label $address $ort"],
     ['noHooks' => true
    ]);

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...