[BETA] JRegistry in save method in single view model for custom fieldtype fields & other types #1035

Closed
opened 2024-01-23 23:07:17 +00:00 by Tom van der Laan · 2 comments

Steps to reproduce the issue

create custom field type and add to admin view. Then compile, install and try and save a new item.

Expected result

Save succesfull.

Actual result

Error: 0 Class "JCB\Component\ComponentName\Administrator\Model\JRegistry" not found
JROOT/administrator/components/com_componentname/src/Model/CouponModel.php:855

System information (as much as possible)

  • OS Name & Version:
  • MySql Version:
  • Apache Version:
  • PHP Version:
  • Joomla Version:
  • JCB Version:
  • Browser:

Additional comments

It seems to happen for custom field type fields and i also found a radio button with the same JRegistry in it. Thats a bit weird since radio is a tinyint and not a array. But the code is checking it for an array:

// Set the type items to data.
		if (isset($data['type']) && is_array($data['type']))
		{
			$type = new JRegistry;
			$type->loadArray($data['type']);
			$data['type'] = (string) $type;
		}
		elseif (!isset($data['type']))
		{
			// Set the empty type to data
			$data['type'] = '';
		}

Here is the full save function:

	/**
	 * Method to save the form data.
	 *
	 * @param   array  $data  The form data.
	 *
	 * @return  boolean  True on success.
	 *
	 * @since   1.6
	 */
	public function save($data)
	{
		$input    = Factory::getApplication()->input;
		$filter   = InputFilter::getInstance();

		// set the metadata to the Item Data
		if (isset($data['metadata']) && isset($data['metadata']['author']))
		{
			$data['metadata']['author'] = $filter->clean($data['metadata']['author'], 'TRIM');

			$metadata = new Registry;
			$metadata->loadArray($data['metadata']);
			$data['metadata'] = (string) $metadata;
		}

		// Set the othertrainings items to data.
		if (isset($data['othertrainings']) && is_array($data['othertrainings']))
		{
			$othertrainings = new JRegistry;
			$othertrainings->loadArray($data['othertrainings']);
			$data['othertrainings'] = (string) $othertrainings;
		}
		elseif (!isset($data['othertrainings']))
		{
			// Set the empty othertrainings to data
			$data['othertrainings'] = '';
		}

		// Set the trainingcat items to data.
		if (isset($data['trainingcat']) && is_array($data['trainingcat']))
		{
			$trainingcat = new JRegistry;
			$trainingcat->loadArray($data['trainingcat']);
			$data['trainingcat'] = (string) $trainingcat;
		}
		elseif (!isset($data['trainingcat']))
		{
			// Set the empty trainingcat to data
			$data['trainingcat'] = '';
		}

		// Set the Params Items to data
		if (isset($data['params']) && is_array($data['params']))
		{
			$params = new Registry;
			$params->loadArray($data['params']);
			$data['params'] = (string) $params;
		}

		// Alter the unique field for save as copy
		if ($input->get('task') === 'save2copy')
		{
			// Automatic handling of other unique fields
			$uniqueFields = $this->getUniqueFields();
			if (UtilitiesArrayHelper::check($uniqueFields))
			{
				foreach ($uniqueFields as $uniqueField)
				{
					$data[$uniqueField] = $this->generateUnique($uniqueField,$data[$uniqueField]);
				}
			}
		}

		if (parent::save($data))
		{
			return true;
		}
		return false;
	}
### Steps to reproduce the issue create custom field type and add to admin view. Then compile, install and try and save a new item. ### Expected result Save succesfull. ### Actual result Error: 0 Class "JCB\Component\ComponentName\Administrator\Model\JRegistry" not found JROOT/administrator/components/com_componentname/src/Model/CouponModel.php:855 ### System information (as much as possible) - OS Name & Version: - MySql Version: - Apache Version: - PHP Version: - Joomla Version: - JCB Version: - Browser: ### Additional comments It seems to happen for custom field type fields and i also found a radio button with the same JRegistry in it. Thats a bit weird since radio is a tinyint and not a array. But the code is checking it for an array: ``` // Set the type items to data. if (isset($data['type']) && is_array($data['type'])) { $type = new JRegistry; $type->loadArray($data['type']); $data['type'] = (string) $type; } elseif (!isset($data['type'])) { // Set the empty type to data $data['type'] = ''; } ``` Here is the full save function: ``` /** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success. * * @since 1.6 */ public function save($data) { $input = Factory::getApplication()->input; $filter = InputFilter::getInstance(); // set the metadata to the Item Data if (isset($data['metadata']) && isset($data['metadata']['author'])) { $data['metadata']['author'] = $filter->clean($data['metadata']['author'], 'TRIM'); $metadata = new Registry; $metadata->loadArray($data['metadata']); $data['metadata'] = (string) $metadata; } // Set the othertrainings items to data. if (isset($data['othertrainings']) && is_array($data['othertrainings'])) { $othertrainings = new JRegistry; $othertrainings->loadArray($data['othertrainings']); $data['othertrainings'] = (string) $othertrainings; } elseif (!isset($data['othertrainings'])) { // Set the empty othertrainings to data $data['othertrainings'] = ''; } // Set the trainingcat items to data. if (isset($data['trainingcat']) && is_array($data['trainingcat'])) { $trainingcat = new JRegistry; $trainingcat->loadArray($data['trainingcat']); $data['trainingcat'] = (string) $trainingcat; } elseif (!isset($data['trainingcat'])) { // Set the empty trainingcat to data $data['trainingcat'] = ''; } // Set the Params Items to data if (isset($data['params']) && is_array($data['params'])) { $params = new Registry; $params->loadArray($data['params']); $data['params'] = (string) $params; } // Alter the unique field for save as copy if ($input->get('task') === 'save2copy') { // Automatic handling of other unique fields $uniqueFields = $this->getUniqueFields(); if (UtilitiesArrayHelper::check($uniqueFields)) { foreach ($uniqueFields as $uniqueField) { $data[$uniqueField] = $this->generateUnique($uniqueField,$data[$uniqueField]); } } } if (parent::save($data)) { return true; } return false; } ```
Tom van der Laan added the
Beta
label 2024-01-23 23:07:22 +00:00
Tom van der Laan changed title from [BETA] JRegistry in save method in single view model for custom fieldtype fields to [BETA] JRegistry in save method in single view model for custom fieldtype fields & other types 2024-01-24 15:26:04 +00:00
Owner

In the last beta release I fixed this issue. let me know if its resolved.

In the last beta release I fixed this issue. let me know if its resolved.
Author
Member

This is fixed 👍

This is fixed 👍
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#1035
No description provided.