Admin Fields view not loading #1010

Closed
opened 2023-09-18 17:50:39 +00:00 by marcusivanhoe · 4 comments
Member

Steps to reproduce the issue

Opening of the admin fields view, either via the Admin view Edit button or via the list button.

Expected result

To be able to edit the list of fields related to that view

Actual result

Getting the following Error

0 VDM\Joomla\Utilities\GetHelper::between(): Argument #1 ($content) must be of type string, null given, called in D:\xampp\htdocs\Andaluz\libraries\jcb_powers\VDM.Joomla\src\Utilities.php on line 397
D:\xampp\htdocs\Andaluz\libraries\jcb_powers\VDM.Joomla\src\Utilities\GetHelper.php:238

Call Stack in attached picture.

I have tried to debug on my own tracing back the call stack, I have not been able to determing why the $content variable is empty in

JROOT\administrator\components\com_componentbuilder\models\fields\fields.php:54

/**
	 * Method to get a list of options for a list input.
	 *
	 * @return	array    An array of JHtml options.
	 */
	protected function getOptions()
	{
		$db = JFactory::getDBO();
		$query = $db->getQuery(true);
		$query->select($db->quoteName(array('a.id', 'a.name', 'a.xml', 'b.name'), array('id', 'field_name', 'xml', 'type')));
		$query->from($db->quoteName('#__componentbuilder_field', 'a'));
		$query->join('LEFT', '#__componentbuilder_fieldtype AS b ON b.id = a.fieldtype');
		$query->where($db->quoteName('a.published') . ' >= 1');
		$query->order('a.name ASC');
		$db->setQuery((string) $query);
		$items = $db->loadObjectList();
		$options = array();
		if ($items)
		{
			$options[] = JHtml::_('select.option', '', 'Select an option');
			foreach($items as $item)
			{
				// get the field name (TODO this could slow down the system so we will need to improve on this)
				$field_name = ComponentbuilderHelper::safeFieldName(ComponentbuilderHelper::getBetween(json_decode($item->xml),'name="','"'));
				$options[] = JHtml::_('select.option', $item->id, $item->field_name . ' [ ' . $field_name . ' - ' . $item->type . ' ]');
			}
		}

		return $options;
	}

being line 54

$field_name = ComponentbuilderHelper::safeFieldName(ComponentbuilderHelper::getBetween(json_decode($item->xml),'name="','"'));
database is working properly and the json stored data is not corrupt.

This happens to any Admin view realeted admin fields view.

System information (as much as possible)

  • OS Name & Version: Linux 4.18.0-372.19.1.lve.el7h.x86_64
  • MySql Version: 10.5.22-MariaDB-log
  • Apache Version: 2.4.57
  • PHP Version: 8.0
  • Joomla Version: 3.10.12
  • JCB Version: 3.1.25 beta (updated Today, in case this was solved in last push)
  • Browser: Opera One(versión: 101.0.4843.43) / Chromium:115.0.5790.171

Additional comments

In admin wiew, the list showing the fields of that view is working properly, so far I have been able to work arround this issue by editing the parameters in the db itself.

### Steps to reproduce the issue Opening of the admin fields view, either via the Admin view Edit button or via the list button. ### Expected result To be able to edit the list of fields related to that view ### Actual result Getting the following Error ``` 0 VDM\Joomla\Utilities\GetHelper::between(): Argument #1 ($content) must be of type string, null given, called in D:\xampp\htdocs\Andaluz\libraries\jcb_powers\VDM.Joomla\src\Utilities.php on line 397 D:\xampp\htdocs\Andaluz\libraries\jcb_powers\VDM.Joomla\src\Utilities\GetHelper.php:238 ``` Call Stack in attached picture. I have tried to debug on my own tracing back the call stack, I have not been able to determing why the $content variable is empty in JROOT\administrator\components\com_componentbuilder\models\fields\fields.php:54 ``` /** * Method to get a list of options for a list input. * * @return array An array of JHtml options. */ protected function getOptions() { $db = JFactory::getDBO(); $query = $db->getQuery(true); $query->select($db->quoteName(array('a.id', 'a.name', 'a.xml', 'b.name'), array('id', 'field_name', 'xml', 'type'))); $query->from($db->quoteName('#__componentbuilder_field', 'a')); $query->join('LEFT', '#__componentbuilder_fieldtype AS b ON b.id = a.fieldtype'); $query->where($db->quoteName('a.published') . ' >= 1'); $query->order('a.name ASC'); $db->setQuery((string) $query); $items = $db->loadObjectList(); $options = array(); if ($items) { $options[] = JHtml::_('select.option', '', 'Select an option'); foreach($items as $item) { // get the field name (TODO this could slow down the system so we will need to improve on this) $field_name = ComponentbuilderHelper::safeFieldName(ComponentbuilderHelper::getBetween(json_decode($item->xml),'name="','"')); $options[] = JHtml::_('select.option', $item->id, $item->field_name . ' [ ' . $field_name . ' - ' . $item->type . ' ]'); } } return $options; } ``` being line 54 `$field_name = ComponentbuilderHelper::safeFieldName(ComponentbuilderHelper::getBetween(json_decode($item->xml),'name="','"')); ` database is working properly and the json stored data is not corrupt. This happens to any Admin view realeted admin fields view. ### System information (as much as possible) - OS Name & Version: Linux 4.18.0-372.19.1.lve.el7h.x86_64 - MySql Version: 10.5.22-MariaDB-log - Apache Version: 2.4.57 - PHP Version: 8.0 - Joomla Version: 3.10.12 - JCB Version: 3.1.25 beta (updated Today, in case this was solved in last push) - Browser: Opera One(versión: 101.0.4843.43) / Chromium:115.0.5790.171 ### Additional comments In admin wiew, the list showing the fields of that view is working properly, so far I have been able to work arround this issue by editing the parameters in the db itself.
Owner

Please make sure to use Firefox for JCB development, and try the last beta-update from today.

Please make sure to use Firefox for JCB development, and try the last beta-update from today.
Author
Member

Hello @Llewellyn Apply suggestions, and I´m still getting this problem, and I haven't been able to catch with var_dump the null parameter given, any ideas How can I get it?

Hello @Llewellyn Apply suggestions, and I´m still getting this problem, and I haven't been able to catch with var_dump the null parameter given, any ideas How can I get it?
Owner

Hmm to try and see when this is happening is hard. The class in question is: GetHelper::between(...)

As you can see its looking for @param string $content The content to search and since null is given its falling over. To avoid the error remove the string data type from $content. So while this will work, it essentially means there is data in your component that should be a string but is a null, this is normally related to a field.

So the function should look like:

/**
 * get a string between two other strings
 * 
 * @param  string       $content    The content to search
 * @param  string       $start      The starting value
 * @param  string       $end        The ending value
 * @param  string       $default    The default value if none found
 *
 * @return  string          On success / empty string on failure
 * @since  3.0.9
 */
public static function between($content, string $start, string $end, string $default = ''): string
{
	$array = explode($start, $content);
	if (isset($array[1]) && strpos($array[1], $end) !== false)
	{
		$array = explode($end, $array[1]);

		// return string found between
		return $array[0];
	}

	return $default;
}

From:

public static function between(string $content, string $start, string $end, string $default = ''): string

to:

public static function between($content, string $start, string $end, string $default = ''): string

You see this line is trying to load the xml value of your fields:

$field_name = ComponentbuilderHelper::safeFieldName(ComponentbuilderHelper::getBetween(json_decode($item->xml),'name="','"'));

And since the field probably does not have a value it returns null.

This issue has come up a few times, and in the end it gets resolved by building complete views, full fields... as empty things are currently not being anticipated in JCB.

The fix for this particular issue could be to add a if statement to the getOptions:

// get the field name (TODO this could slow down the system so we will need to improve on this)
if (isset($item->xml) && ComponentbuilderHelper::checkJson($item->xml))
{
	$field_xml = json_decode($item->xml);
	$field_name = ComponentbuilderHelper::getBetween($field_xml,'name="','"');
	$field_name = ComponentbuilderHelper::safeFieldName($field_name);
	$options[] = JHtml::_('select.option', $item->id, $item->name . ' [ ' . $field_name . ' - ' . $item->type . ' ]');
}
else
{
	$options[] = JHtml::_('select.option', $item->id, $item->name . ' [ empty - ' . $item->type . ' ]');
}

I have added this fix to the beta-branch a few minutes ago... let me know.

Hmm to try and see when this is happening is hard. The class in question is: [GetHelper::between(...)](https://git.vdm.dev/joomla/Component-Builder/src/branch/staging/libraries/jcb_powers/VDM.Joomla/src/Utilities/GetHelper.php#L238) As you can see its looking for `@param string $content The content to search` and since null is given its falling over. To avoid the error remove the `string` data type from `$content`. So while this will work, it essentially means there is data in your component that should be a string but is a null, this is normally related to a field. So the function should look like: ``` /** * get a string between two other strings * * @param string $content The content to search * @param string $start The starting value * @param string $end The ending value * @param string $default The default value if none found * * @return string On success / empty string on failure * @since 3.0.9 */ public static function between($content, string $start, string $end, string $default = ''): string { $array = explode($start, $content); if (isset($array[1]) && strpos($array[1], $end) !== false) { $array = explode($end, $array[1]); // return string found between return $array[0]; } return $default; } ``` From: ``` public static function between(string $content, string $start, string $end, string $default = ''): string ``` to: ``` public static function between($content, string $start, string $end, string $default = ''): string ``` You see this line is trying to load the xml value of your fields: ``` $field_name = ComponentbuilderHelper::safeFieldName(ComponentbuilderHelper::getBetween(json_decode($item->xml),'name="','"')); ``` And since the field probably does not have a value it returns null. This issue has come up a few times, and in the end it gets resolved by building complete views, full fields... as empty things are currently not being anticipated in JCB. The fix for this particular issue could be to add a if statement to the `getOptions`: ``` // get the field name (TODO this could slow down the system so we will need to improve on this) if (isset($item->xml) && ComponentbuilderHelper::checkJson($item->xml)) { $field_xml = json_decode($item->xml); $field_name = ComponentbuilderHelper::getBetween($field_xml,'name="','"'); $field_name = ComponentbuilderHelper::safeFieldName($field_name); $options[] = JHtml::_('select.option', $item->id, $item->name . ' [ ' . $field_name . ' - ' . $item->type . ' ]'); } else { $options[] = JHtml::_('select.option', $item->id, $item->name . ' [ empty - ' . $item->type . ' ]'); } ``` I have added this fix to the beta-branch a few minutes ago... let me know.
Author
Member

Thank you @Llewellyn the fix has worked,

You mention an empty field is most probable the reason why it is happening, I wonder why then, it was happening to all my admin field views, If I find where this empty field is occurring I´ll let you know.

Thanks.

Thank you @Llewellyn the fix has worked, You mention an empty field is most probable the reason why it is happening, I wonder why then, it was happening to all my admin field views, If I find where this empty field is occurring I´ll let you know. Thanks.
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 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#1010
No description provided.