[BUG]: can't create link using dynamic get of type getCustoms, custom code is not added just before "return $items;" #1224

Open
opened 2025-06-04 00:59:18 +00:00 by oxido · 4 comments

What Happened?

I created a dynamic get of type getCustoms, in it I added code in the custom script -> Add PHP (after getting the Items) section.
After compiling the component I expected getCustoms to work like getListQuery and add the custom script just before "return $items;" , but it wasn't.

Steps to reproduce the Bug

  1. Create dynamic get of type getCustoms
  2. Add your code in custom script tab, section "Add PHP (after getting the Items)"
  3. Compile the component.
  4. Check the model where the code from dynamic get, was added
  5. The custom code was not added just before "return $items;"

Which Joomla version are you compiling in?

5.3.0

Which PHP version are you compiling in?

8.2.23

Which Joomla versions are you targeting?

v5.x

Which PHP version are you targeting?

8.x

Which Web server is JCB running on?

Apache/2.4.62 (Debian)

Which Relational Database is JCB running on?

Mysql, 11.6.2-MariaDB-ubu2404

Which OS is JCB running on?

Ubuntu

Which JCB version are you using?

v5.1.1-alpha5

Where in JCB did this issue occur?

Dynamic Get(admin_view)

On which browsers did you encounter the issue?

Firefox

Additional Comments

...
// [VDM\Joomla\Componentbuilder\Compiler\Helper\Interpretation 3718] Reset the query using our newly populated query object.
		$db->setQuery($query);
		$items = $db->loadObjectList();
		/***[JCBGUI.dynamic_get.php_after_getitems.44.$$$$]***/
		// creat links for items
		foreach ($items as $itemKey => $itemValue) {
			$items[$itemKey]->link = RouteHelper::getBookchapterRoute($itemValue->slug);
		}/***[/JCBGUI$$$$]***/


		if (empty($items))
		{
			return false;
		}

		// [VDM\Joomla\Componentbuilder\Compiler\Helper\Interpretation 4427] Insure all item fields are adapted where needed.
		if (UtilitiesArrayHelper::check($items))
		{
			foreach ($items as $nr => &$item)
			{
				// [VDM\Joomla\Componentbuilder\Compiler\Helper\Interpretation 4436] Always create a slug for sef URL's
				$item->slug = ($item->id ?? '0') . (isset($item->alias) ? ':' . $item->alias : '');
			}
		}
		// [VDM\Joomla\Componentbuilder\Compiler\Helper\Interpretation 3744] return items
		return $items;
### What Happened? I created a dynamic get of type getCustoms, in it I added code in the custom script -> Add PHP (after getting the Items) section. After compiling the component I expected getCustoms to work like getListQuery and add the custom script just before "return $items;" , but it wasn't. ### Steps to reproduce the Bug 1. Create dynamic get of type getCustoms 2. Add your code in custom script tab, section "Add PHP (after getting the Items)" 3. Compile the component. 4. Check the model where the code from dynamic get, was added 5. The custom code was not added just before "return $items;" ### Which Joomla version are you compiling in? 5.3.0 ### Which PHP version are you compiling in? 8.2.23 ### Which Joomla versions are you targeting? v5.x ### Which PHP version are you targeting? 8.x ### Which Web server is JCB running on? Apache/2.4.62 (Debian) ### Which Relational Database is JCB running on? Mysql, 11.6.2-MariaDB-ubu2404 ### Which OS is JCB running on? Ubuntu ### Which JCB version are you using? v5.1.1-alpha5 ### Where in JCB did this issue occur? Dynamic Get(admin_view) ### On which browsers did you encounter the issue? Firefox ### Additional Comments ``` ... // [VDM\Joomla\Componentbuilder\Compiler\Helper\Interpretation 3718] Reset the query using our newly populated query object. $db->setQuery($query); $items = $db->loadObjectList(); /***[JCBGUI.dynamic_get.php_after_getitems.44.$$$$]***/ // creat links for items foreach ($items as $itemKey => $itemValue) { $items[$itemKey]->link = RouteHelper::getBookchapterRoute($itemValue->slug); }/***[/JCBGUI$$$$]***/ if (empty($items)) { return false; } // [VDM\Joomla\Componentbuilder\Compiler\Helper\Interpretation 4427] Insure all item fields are adapted where needed. if (UtilitiesArrayHelper::check($items)) { foreach ($items as $nr => &$item) { // [VDM\Joomla\Componentbuilder\Compiler\Helper\Interpretation 4436] Always create a slug for sef URL's $item->slug = ($item->id ?? '0') . (isset($item->alias) ? ':' . $item->alias : ''); } } // [VDM\Joomla\Componentbuilder\Compiler\Helper\Interpretation 3744] return items return $items; ```
oxido added the
Bug
label 2025-06-04 00:59:18 +00:00
oxido changed title from [BUG]: to [BUG]: dynamic get of type getCustoms do not add the custom code just before "return $items;" 2025-06-04 01:02:20 +00:00
oxido changed title from [BUG]: dynamic get of type getCustoms do not add the custom code just before "return $items;" to [BUG]: can't create slug using dynamic get of type getCustoms, custom code is not added just before "return $items;" 2025-07-04 21:32:25 +00:00
Owner

Give us some screen shots of each tab you are using in the Dynamic get area... so I can explain to you what you can do to get the expected outcome,

Give us some screen shots of each tab you are using in the Dynamic get area... so I can explain to you what you can do to get the expected outcome,
Author

Is not a real problem for me right now, I just need to move that piece of custom script a little bit down every time I compile the app.
If this is how it should work, there is no problem, except that in the normal dynamicGet, the custom script is placed just before
return $items; , I just assumed that this should be the case in getCustoms as well.

Because the slug is created a little bit down, I can't use it in my custom script.

Is not a real problem for me right now, I just need to move that piece of custom script a little bit down every time I compile the app. If this is how it should work, there is no problem, except that in the normal dynamicGet, the custom script is placed just before `return $items; `, I just assumed that this should be the case in getCustoms as well. Because the slug is created a little bit down, I can't use it in my custom script.
oxido changed title from [BUG]: can't create slug using dynamic get of type getCustoms, custom code is not added just before "return $items;" to [BUG]: can't create link using dynamic get of type getCustoms, custom code is not added just before "return $items;" 2025-07-05 11:51:57 +00:00
Owner

hmmm lets fix this for you... and we can investigate this to see if this change will work for everyone.

So first... in the crazy file: Interpretation

We replace line 3705-3727 with:

					$main .= PHP_EOL . PHP_EOL . Indent::_(2)
						. "if (empty(\$items))";
					$main .= PHP_EOL . Indent::_(2) . "{";
					$main .= PHP_EOL . Indent::_(3) . "return false;";
					$main .= PHP_EOL . Indent::_(2) . "}";
					// SITE_GET_ITEMS <<<DYNAMIC>>>
					$main .= $this->setCustomViewGetItems($view, $view->code);
					// set after items php
					if (isset($view->add_php_after_getitems)
						&& $view->add_php_after_getitems == 1
						&& isset($view->php_after_getitems)
						&& StringHelper::check(
							$view->php_after_getitems
						))
					{
						$main .= CFactory::_('Placeholder')->update_(
							$view->php_after_getitems
						);
					}
					$main .= PHP_EOL . Indent::_(2) . "//" . Line::_(
							__LINE__,__CLASS__
						) . " return items";
					$main .= PHP_EOL . Indent::_(2) . "return \$items;";

This should fix the issue for you.

This moves the code that is in the php_after_getitems to be below the auto generated loop. Ideal would be that we can in the loop add our code actually. So I will add this to the possible improvement towards the next release. For now this fix should help you, but we might need to do more here, and so you might have to refactor this again with the next stable release.

hmmm lets fix this for you... and we can investigate this to see if this change will work for everyone. So first... in the crazy file: [Interpretation](https://git.vdm.dev/joomla/Component-Builder/src/commit/e097540a7d8867b5665b08510e91f80fdff085c3/libraries/vendor_jcb/VDM.Joomla/src/Componentbuilder/Compiler/Helper/Interpretation.php#L3705-L3727) We replace line 3705-3727 with: ``` $main .= PHP_EOL . PHP_EOL . Indent::_(2) . "if (empty(\$items))"; $main .= PHP_EOL . Indent::_(2) . "{"; $main .= PHP_EOL . Indent::_(3) . "return false;"; $main .= PHP_EOL . Indent::_(2) . "}"; // SITE_GET_ITEMS <<<DYNAMIC>>> $main .= $this->setCustomViewGetItems($view, $view->code); // set after items php if (isset($view->add_php_after_getitems) && $view->add_php_after_getitems == 1 && isset($view->php_after_getitems) && StringHelper::check( $view->php_after_getitems )) { $main .= CFactory::_('Placeholder')->update_( $view->php_after_getitems ); } $main .= PHP_EOL . Indent::_(2) . "//" . Line::_( __LINE__,__CLASS__ ) . " return items"; $main .= PHP_EOL . Indent::_(2) . "return \$items;"; ``` This should fix the issue for you. This moves the code that is in the `php_after_getitems` to be below the auto generated loop. Ideal would be that we can in the loop add our code actually. So I will add this to the possible improvement towards the next release. For now this fix should help you, but we might need to do more here, and so you might have to refactor this again with the next stable release.
Llewellyn added this to the Compiler Improvements project 2025-07-05 15:49:05 +00:00
Llewellyn moved this to In Progress in Compiler Improvements on 2025-07-05 15:49:34 +00:00
Author

It is working.

It is working.
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

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