Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working when used as a custom field (for FieldtypeFile/Image) #5

Open
romaincazier opened this issue May 4, 2023 · 0 comments
Open

Comments

@romaincazier
Copy link

Hi,

There is an issue when using your module as a custom field for a FieldtypeFile/Image due to the way you are caching the oembed object.

In a custom field (e.g. video) of a FieldtypeFile/Image (gallery) $page is a reference to a dummy page created on the fly to get the field’s value stored in the db (not in the field_video table as one might expect but in the field_gallery one, with each value saved in a json in the filedata column).

So because $page is different between ___wakeupValue() and ___formatValue() it results in _oembedObj returning null.

I created a PR that solves this issue by using the same dummy page per file but unless Ryan approves / merges it this issue remains.

Another way to go is to make changes to your files but it's clearly not the best as it would result in unnecessary calls to get the oembed data (since it's there in the db):

In FieldtypeOembed.module, replace line 150 with:

$oembedObj = $page->get('_oembedObj' . $field->name);
if(!$oembedObj) {
	$oembedObj = $this->getBlankValue($page, $field);
	$oembedData = $this->fetch($value);
	if(is_array($oembedData)) $oembedObj->setArray($oembedData);
	$page->setQuietly('_oembedObj' . $field->name, $oembedObj); // if need be?
}
return $oembedObj;

And in InputfieldOembed.module, replace line 43 with:

if(!$this->hasPage->id && $this->hasPage->status === Page::statusOn | Page::statusCorrupted) { // we're dealing with a dummy page
	$preview = $this->oembedPreview($field->type->formatValue($this->hasPage, $fieldtype, $this->get("value")));
} else {
	$preview = $this->oembedPreview($this->hasPage->getFormatted($field->name));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant