Closed X-Ryl669 closed 3 years ago
Well, it fails then on second saving with Save Failed: Indirect modification of overloaded property Grav\Common\Page\Header::$aura has no effect
I don't understand the code here:
$page->header()->aura['metadata'] = array($key => $val);
It's in a loop, so it'll be overwritten by the last value anyway. It's causing the exception above since you're not allowed to update a member like this when the member is a reference. In addition, there is no other aura['metadata']
use anywhere so the later array_merge does nothing. In the end, I've removed this line and it works.
Got exactly same issue.
Here's my code that works (on end of onAdminSave
:
// Generate Aura metadata
$metadata = [];
foreach ($aura->webpage->metadata as $tag) {
if (array_key_exists('property', $tag)) {
$metadata[$tag['property']] = $tag['content'];
} else if (array_key_exists('name', $tag)) {
$metadata[$tag['name']] = $tag['content'];
}
}
$original = $page->getOriginal();
$aura_metadata = [];
if ($original !== null && !isset($original->header()->aura) && isset($page->header()->metadata) && is_array($page->header()->metadata)) {
// Page has not been saved since installation of Aura and includes some custom metadata
foreach ($page->header()->metadata as $key => $val) {
if (!array_key_exists($key, $metadata)) {
// A new value has not been supplied via Aura, salvage existing metadata
$metadata[$key] = $val;
}
}
}
$page->header()->metadata = $metadata;
}
I can confirm the error is caused by calling $original->header()
when $original
is null
$original = $page->getOriginal();
if (!is_null($original)) { // added this
if (!isset($original->header()->aura) && isset($page->header()->metadata) && is_array($page->header()->metadata)) {
// Page has not been saved since installation of Aura and includes some custom metadata
foreach ($page->header()->metadata as $key => $val) {
if (!array_key_exists($key, $metadata)) {
// A new value has not been supplied via Aura, salvage existing metadata
$metadata[$key] = $val;
$page->header()->aura['metadata'] = array($key => $val);
}
}
}
} // added this
Thanks for logging the issue and for your suggestions @X-Ryl669. I've updated and created a new release which you can manually install now or update via gpm shortly. Cheers.
Now the plug-in adds Home |
in og:title
before the title itself.
Does someone has observed the same?
I have a multilanguage blog. When I add a item page to a blog, and click save, it breaks with this information, preventing first page saving:
Arguments
$original
is null in that case, since it's the first save of the page. Changing the test to read:works.