Jump to content

Recommended Posts

Posted

Not sure if I'm being silly, but it seems to me that the core Field::exportData (3.0.184) has a bug in the following two lines

$typeData = $this->type->exportConfigData($this, $data);
$data = array_merge($data, $typeData);

This code seems to cause the $typedata from the default fieldtype config settings to over-ride the actual field data. I have experienced a number of errors that appear to be caused by this. 
Shouldn't the 2nd line be this?

$data = array_merge($typeData, $data);

Per the PHP manual, the second array will overwrite the first if the keys match.
I have written a hook (before Fieldtype::exportConfigData) to fix this by merging the data the 'correct' way before returning it to Field::exportData. Effectively it performs the merge the other way around and returns the already merged array (see code at end). However, I'm concerned that this may have side effects where child classes call parent::___exportConfigData($field, $data). Assuming it is a bug, would I be better just hacking the core until it is fixed. I haven't raised a core issue before, so am a bit nervous about doing so (and would need some time to build a simple case to demonstrate the issue).

Code for hook is:

	public function afterExportConfigData(HookEvent $event) {
		$data = $event->arguments(0)->data;
		$value = $event->return;
		$event->return = array_merge($value, $data);
	}

 

Posted
5 hours ago, MarkE said:

Per the PHP manual, the second array will overwrite the first if the keys match.

Only if the keys are strings ?...which they probably are in this case.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...