TDBF Posted March 16 Posted March 16 I normally create my hooks via the ACP and then edit the hook via the file via my IDE. (I have asked many times if you guys could increase the size of the Hooks Textarea or make it expandable, because I hate editing within a letter box. 😋) However, after the last release, this is now borked. If I edit the hook via the file, my IDE will format the code on save, and the next time I edit/add new elements to the hook class a new 'public static function hookData()' class will be created causing a Fatal error: Cannot redeclare IPS\hookData() in. For example: In this test hook, this is the content created by the core. /** * @mixin \IPS\Theme\class_forums_front_topics */ class test_hook_testHook extends _HOOK_CLASS_ { /* !Hook Data - DO NOT REMOVE */ public static function hookData() { return array_merge_recursive( array ( 'post' => array ( 0 => array ( 'selector' => 'div[data-controller=\'core.front.core.comment\'].ipsComment_content.ipsType_medium > div.ipsComment_meta.ipsType_light.ipsFlex.ipsFlex-ai:center.ipsFlex-jc:between.ipsFlex-fd:row-reverse > div.ipsType_light.ipsType_reset.ipsType_blendLinks.ipsComment_toolWrap > div.ipsResponsive_hidePhone.ipsComment_badges > ul.ipsList_reset.ipsFlex.ipsFlex-jc:end.ipsFlex-fw:wrap.ipsGap:2.ipsGap_row:1 > li > strong.ipsBadge.ipsBadge_large.ipsBadge_positive.ipsBadge_reverse > i.fa.fa-check', 'type' => 'replace', 'content' => '', ), ), ), parent::hookData() ); } /* End Hook Data */ } After the code has been formatted/edited: /** * @mixin \IPS\Theme\class_forums_front_topics */ class test_hook_testHook extends _HOOK_CLASS_ { // !Hook Data - DO NOT REMOVE public static function hookData() { return array_merge_recursive( [ 'post' => [ 0 => [ 'selector' => 'div[data-controller=\'core.front.core.comment\'].ipsComment_content.ipsType_medium > div.ipsComment_meta.ipsType_light.ipsFlex.ipsFlex-ai:center.ipsFlex-jc:between.ipsFlex-fd:row-reverse > div.ipsType_light.ipsType_reset.ipsType_blendLinks.ipsComment_toolWrap > div.ipsResponsive_hidePhone.ipsComment_badges > ul.ipsList_reset.ipsFlex.ipsFlex-jc:end.ipsFlex-fw:wrap.ipsGap:2.ipsGap_row:1 > li > strong.ipsBadge.ipsBadge_large.ipsBadge_positive.ipsBadge_reverse > i.fa.fa-check', 'type' => 'replace', 'content' => 'some new content', ], ], ], parent::hookData() ); } // End Hook Data } After I edit/add another element to the hook class: /** * @mixin \IPS\Theme\class_forums_front_topics */ class test_hook_testHook extends _HOOK_CLASS_ { /* !Hook Data - DO NOT REMOVE */ public static function hookData() { return array_merge_recursive( array ( 'post' => array ( 0 => array ( 'selector' => 'div[data-controller=\'core.front.core.comment\'].ipsComment_content.ipsType_medium > div.ipsComment_meta.ipsType_light.ipsFlex.ipsFlex-ai:center.ipsFlex-jc:between.ipsFlex-fd:row-reverse > div.ipsType_light.ipsType_reset.ipsType_blendLinks.ipsComment_toolWrap > div.ipsResponsive_hidePhone.ipsComment_badges > ul.ipsList_reset.ipsFlex.ipsFlex-jc:end.ipsFlex-fw:wrap.ipsGap:2.ipsGap_row:1 > li > strong.ipsBadge.ipsBadge_large.ipsBadge_positive.ipsBadge_reverse > i.fa.fa-check', 'type' => 'replace', 'content' => '', ), ), ), parent::hookData() ); } /* End Hook Data */ // !Hook Data - DO NOT REMOVE public static function hookData() { return array_merge_recursive( [ 'post' => [ 0 => [ 'selector' => 'div[data-controller=\'core.front.core.comment\'].ipsComment_content.ipsType_medium > div.ipsComment_meta.ipsType_light.ipsFlex.ipsFlex-ai:center.ipsFlex-jc:between.ipsFlex-fd:row-reverse > div.ipsType_light.ipsType_reset.ipsType_blendLinks.ipsComment_toolWrap > div.ipsResponsive_hidePhone.ipsComment_badges > ul.ipsList_reset.ipsFlex.ipsFlex-jc:end.ipsFlex-fw:wrap.ipsGap:2.ipsGap_row:1 > li > strong.ipsBadge.ipsBadge_large.ipsBadge_positive.ipsBadge_reverse > i.fa.fa-check', 'type' => 'replace', 'content' => '', ], ], ], parent::hookData() ); } // End Hook Data } Seems like there is an issue with your preg replace method?
Solution BN_IT_Support Posted March 16 Solution Posted March 16 Hi, I don't have the answer, but... I find it interesting that you would use your own editor on a Theme hook. I would agree that using your own editor on a Code hook is far more convenient than using adminCP editor, but for a Theme hook ??? Personally, I find the adminCP editor more convenient as it sorts out all the escapes (among other things). What motivates you to use your own editor? Secondly, if this used to work before 4.7.16 and if you have NOT made any changes to your editor (either configuration or version update) then I can understand your point of view - that it should not have been broken. That said, the Invision comments say "do not remove" and that implies "do not modify, either" and your editor has clearly modified the lines - what was '/*comment*/' is changed by your editor to '//comment' which is not the same thing. John teraßyte 1
TDBF Posted March 16 Author Posted March 16 (edited) 4 hours ago, BN_IT_Support said: Hi, I don't have the answer, but... I find it interesting that you would use your own editor on a Theme hook. I would agree that using your own editor on a Code hook is far more convenient than using adminCP editor, but for a Theme hook ??? Personally, I find the adminCP editor more convenient as it sorts out all the escapes (among other things). What motivates you to use your own editor? Secondly, if this used to work before 4.7.16 and if you have NOT made any changes to your editor (either configuration or version update) then I can understand your point of view - that it should not have been broken. That said, the Invision comments say "do not remove" and that implies "do not modify, either" and your editor has clearly modified the lines - what was '/*comment*/' is changed by your editor to '//comment' which is not the same thing. John With all due respect John, I do not see why I have to justify my workflow to you anyone else for that matter. 🙂 I basically stated in my first paragraph why I do not use the backend editor. I refuse to work in an environment which is limiting to me. I cannot stand working with ACP when it comes to code, I will do what is required and then work from my IDE. As for escaping code, there are plenty of plugins that I can use within my IDE which does the job for me. I have been doing it this way since the launch of version 4. This works for me, I'm sure you have your own workflow which works for you that may not work for others. Each to their own. 🙂 But thank you, you did point me to the reason why this no longer works for me and I was able to fix the issue. Kind Regards, John Edited March 16 by TDBF
Recommended Posts