Custom Code Insert not working on front-end controller #918

Closed
opened 2022-06-18 23:37:32 +00:00 by cpaschen · 3 comments
cpaschen commented 2022-06-18 23:37:32 +00:00 (Migrated from github.com)

Steps to reproduce the issue

Add an 'insert' custom code into a view's /components/COMPONENT/controllers/VIEW.php file,
in the save function, just before the 'return $saved' line

specific code inserted:

		/***[INSERT<>$$$$]***/
		$linkAuthorDash = Kr_booksHelper::getSystemParam('syslink_dashboard_author');
		$this->setRedirect((JRoute::_($linkAuthorDash)));
		/***[/INSERT<>$$$$]***/

Compile component

Expected result

Code is inserted in the place it was added.

Actual result

code block is inserted into the middle of the cancel function.

System information (as much as possible)

  • OS Name & Version: Windows / WAMP
  • MySql Version: 5.7.31
  • Apache Version: 2.4.46
  • PHP Version: 7.4.9
  • Joomla Version: 3.10.8
  • JCB Version: 2.13.1
  • Browser: (compiled in FireFox developer)

Additional comments

I do have several other custom code blocks in this same file inserted via the GUI.

I do have this sort of insert working in other controller files in the same position, so it must be something related to this specific file or other location-specific issue.

If there is another way to insert custom code for redirect here (and at the end of the cancel function) than with this hard-coded INSERT code method, please let me know.

### Steps to reproduce the issue Add an 'insert' custom code into a view's /components/COMPONENT/controllers/VIEW.php file, in the save function, just before the 'return $saved' line specific code inserted: ``` /***[INSERT<>$$$$]***/ $linkAuthorDash = Kr_booksHelper::getSystemParam('syslink_dashboard_author'); $this->setRedirect((JRoute::_($linkAuthorDash))); /***[/INSERT<>$$$$]***/ ``` Compile component ### Expected result Code is inserted in the place it was added. ### Actual result code block is inserted into the middle of the cancel function. ### System information (as much as possible) - OS Name & Version: Windows / WAMP - MySql Version: 5.7.31 - Apache Version: 2.4.46 - PHP Version: 7.4.9 - Joomla Version: 3.10.8 - JCB Version: 2.13.1 - Browser: (compiled in FireFox developer) ### Additional comments I do have several other custom code blocks in this same file inserted via the GUI. I do have this sort of insert working in other controller files in the same position, so it must be something related to this specific file or other location-specific issue. If there is another way to insert custom code for redirect here (and at the end of the cancel function) than with this hard-coded INSERT code method, please let me know.

try removing the space in front of the comment placeholders and see if it works then, like this:

/***[INSERT<>$$$$]***/
		$linkAuthorDash = Kr_booksHelper::getSystemParam('syslink_dashboard_author');
		$this->setRedirect((JRoute::_($linkAuthorDash)));
/***[/INSERT<>$$$$]***/
try removing the space in front of the comment placeholders and see if it works then, like this: ``` /***[INSERT<>$$$$]***/ $linkAuthorDash = Kr_booksHelper::getSystemParam('syslink_dashboard_author'); $this->setRedirect((JRoute::_($linkAuthorDash))); /***[/INSERT<>$$$$]***/ ```
cpaschen commented 2022-06-20 22:05:33 +00:00 (Migrated from github.com)

Nope. It inserted it in the exact same space.
In the public function cancel
it inserted it right before the elseif ($this->ref) line

Very strange that it is doing that, but also very strange (but hopefully a logical reason) that it is inserting it in the same place each time.

The other custom modification to this controller is that I added some functionality in the postSaveHook function via the GUI.
I tested also by removing that GUI modification, but the insert code still goes to the exact same position.

I went into the Custom Code entry in the JCB admin GUI and noticed that the
From Line (Zero based) - indicated 306, which is almost exactly where it SHOULD be placed, but not anywhere near where it IS being placed.

I added 80 to that line (so it is now 386), which should put it in the proper position.
That didn't change anything (likely because I didn't change the hash for that custom code entry).

I finally went in and just did a custom code block and replaced parts of the save and cancel functions (the 2 places I needed to override the return) and the replace code was inserted perfectely as it should, so the issue is just on the code.

Not sure if this is worth addressing or not with the current version of JCB as I've never experienced this before.

Nope. It inserted it in the exact same space. In the public function cancel it inserted it right before the elseif ($this->ref) line Very strange that it is doing that, but also very strange (but hopefully a logical reason) that it is inserting it in the same place each time. The other custom modification to this controller is that I added some functionality in the postSaveHook function via the GUI. I tested also by removing that GUI modification, but the insert code still goes to the exact same position. I went into the Custom Code entry in the JCB admin GUI and noticed that the From Line (Zero based) - indicated 306, which is almost exactly where it SHOULD be placed, but not anywhere near where it IS being placed. I added 80 to that line (so it is now 386), which should put it in the proper position. That didn't change anything (likely because I didn't change the hash for that custom code entry). I finally went in and just did a <REPLACE> custom code block and replaced parts of the save and cancel functions (the 2 places I needed to override the return) and the replace code was inserted perfectely as it should, so the issue is just on the <INSERT> code. Not sure if this is worth addressing or not with the current version of JCB as I've never experienced this before.
cpaschen commented 2022-06-28 00:10:54 +00:00 (Migrated from github.com)

Well, I just had this happen again on another form's controller.
Trying to do the same thing. Inserted the first bit of code for the re-direct (in the cancel function) and compiled and it worked fine.
Added the 2nd insert redirect in the save and it placed it directly under the previous insert in the cancel section, not in the save section.

I put in a 'feature request' (https://github.com/vdm-io/Joomla-Component-Builder/issues/923) to see if we can just get a GUI way to add some code right before the return on these functions. I think that will do it - unless someone has some other thought of how to make this work properly.

Well, I just had this happen again on another form's controller. Trying to do the same thing. Inserted the first bit of code for the re-direct (in the cancel function) and compiled and it worked fine. Added the 2nd insert redirect in the save and it placed it directly under the previous insert in the cancel section, not in the save section. I put in a 'feature request' (https://github.com/vdm-io/Joomla-Component-Builder/issues/923) to see if we can just get a GUI way to add some code right before the return on these functions. I think that will do it - unless someone has some other thought of how to make this work properly.
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: joomla/Component-Builder#918
No description provided.