Peter Falkenberg Brown Posted April 30, 2017 Share Posted April 30, 2017 Hi All, I copied a 3.0.42 site to a new domain, and then upgraded it to 3.0.61. All was well. After finishing that domain, I copied the new 3.0.61 site to a new domain, and modified all of the variables, settings, etc, as normal. When I went to the home page, I got this error: Recoverable Fatal Error: Argument 1 passed to menu_post_process() must be an instance of HookEvent, instance of ProcessWire\HookEvent given, called in /home/USER/public_html/wire/core/WireHooks.php on line 777 and defined (line 80 of /home/USER/public_html/site/templates/inc_create_menu_mobile.php) I saw that error once before, in 3.0, when I tried to put a file compiler false directive in config.php. That was solved when I placed this directive: # FileCompiler=0 in a php file in my home dir. That is, it had nothing to do with the menu code at all, but it was affecting it. That fix still exists, and none of this happened on my first 3.0.61 site that I copied *from*. That earlier issue is documented in this post: I'm wondering if it's something in 3.0.61 that got screwy because I copied the site. I deleted the cache, and sessions, to no avail. In fact, I deleted the code that even uses the above php file that has the FileCompiler directive in it. The pages load fine when I comment out the menu. The menu uses the MarkupSimpleNavigation module. The menu file has this code in it: function menu_post_process(HookEvent $event) { $page = $event->arguments[1]; $new_code = $event->return; # check for open_in_new_tab if($page->open_in_new_tab) { $new_code = str_replace('href=','target="_blank" href=', $new_code); } $event->return = $new_code; } I'm stumped. Thanks for any help! Peter Link to comment Share on other sites More sharing options...
Robin S Posted April 30, 2017 Share Posted April 30, 2017 It's a namespace issue. The file where function menu_post_process() is defined is not being processed by the file compiler, maybe because it is in an include. So add... namespace ProcessWire; ...at the top of that PHP file. 1 Link to comment Share on other sites More sharing options...
Peter Falkenberg Brown Posted April 30, 2017 Author Share Posted April 30, 2017 Dear Robin, That resolved it. Thanks! However, I'm curious: the other 3.0.61 site works fine, without that namespace declaration. Any thoughts on why that might be so? Also, all the files in my system are include files, running off a controller file. All of the field templates are defined to pull up this file: custom_template_controller.php, which then pulls up various page files, like 'home.php', 'section.php', 'article.php', etc. Those top level includes then include around a dozen or more smaller include files, like the menu, the header, etc, etc. I'm wondering why the menu file choked, but the other includes did not. Because of the Hook code? Here's the code in the top control file: <?php include("./inc_vars.php"); include("./inc_functions.php"); #.................................................................... # block future publish dates; don't block home page (id 1) if ( ( $page->id == '1' ) || ( ! empty( $publish_date ) and $publish_date <= $now ) ) { # page can be displayed } else { throw new Wire404Exception(); } #.................................................................... include("./$custom_template_file"); Thanks for your help! Peter Link to comment Share on other sites More sharing options...
Robin S Posted April 30, 2017 Share Posted April 30, 2017 3 minutes ago, Peter Falkenberg Brown said: I'm wondering why the menu file choked, but the other includes did not. Because of the Hook code? In PW3 all the core PW classes (e.g. Page, PageArray, or in your current case HookEvent) are in the ProcessWire namespace. So where in PW2 you can write the type hinting as... function menu_post_process(HookEvent $event) ...in PW3 you need the ProcessWire namespace, like this... function menu_post_process(ProcessWire\HookEvent $event) But rather than use the namespace every time you create a new instance of a class you can just declare it once at the top of the PHP file. namespace ProcessWire; And the idea of the file compiler is that you don't even need to do this - the file compiler takes care of it for you. But there are some files that the file compiler does not process. As LostKobrakai said in the other thread you linked to: On 7/01/2017 at 6:12 AM, LostKobrakai said: The FileCompiler does not automatically iterate over any folders or files. It does only compile files directly included by processwire (modules/templates and so on) and any files included in any of those files. And it sounds like in your case you have deliberately disabled the file compiler in certain files with: # FileCompiler=0 So therefore you need to manually insert the namespace declaration yourself wherever you instantiate a PW class. 2 Link to comment Share on other sites More sharing options...
Peter Falkenberg Brown Posted April 30, 2017 Author Share Posted April 30, 2017 Thanks, Robin, for that explanation. The # FileCompiler=0 declaration was in only one file. Also, my other site didn't have this problem. I wonder why... I thought I read somewhere that you could include the namespace declaration in the top include file, so I tried that in the controller file listed above, but it didn't work. But... in any case, adding that declaration did fix the issue. Thanks, again! Peter Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now