Issue Context
When an unauthenticated user visits a node-based page, the page will (intermittently) not load properly, and the following error message will be generated in the server error log:
"Message Recoverable fatal error: Argument 2 passed to metatag_get_instance() must be an array, string given, called in /var/www/[...]/sites/all/modules/metatag/metatag.module on line 706 and defined in metatag_get_instance() (line 1268 of /var/www/[...]/sites/all/modules/metatag/metatag.module)."
If an administrator (i.e., authenticated user) then visits the same node-based page, the page will load properly for the administrator. Subsequent to the page visit by the administrator, and after a refresh by the unauthenticated user, the node-based page will then load properly.
Temporary Solution
This issue was patched by making the following change to .../metatag/metatag.module:
Original code (beginning on line 702, php tags added locally):
// Add any default tags to the mix.
$metatags += metatag_config_load_with_defaults($instance);
foreach ($metatags as $metatag => $data) {
if ($metatag_instance = metatag_get_instance($metatag, $data)) {
$output[$metatag] = $metatag_instance->getElement($options);
}
}
Revised code (new conditional, php tags added locally):
// Add any default tags to the mix.
$metatags += metatag_config_load_with_defaults($instance);
foreach ($metatags as $metatag => $data) {
if (gettype($data) != 'array') {
continue;
}
if ($metatag_instance = metatag_get_instance($metatag, $data)) {
$output[$metatag] = $metatag_instance->getElement($options);
}
}
Question
Would it be possible/desirable to have the small code addition added to future releases of the metatag module?
Comments
Comment #1
damienmckennaPlease test the latest -dev release and let me know if the problem persists.
Comment #2
m_david_ae commentedThanks very much for the quick response. I downloaded and replaced the beta4 metag files with the 7.x-1.x-dev files, and the (intermittent) improper loading of node-based pages did not occur, with some considerable testing.
Please note that I experienced an additional issue when using the dev files. Namely, the drupal-variable $head_title (used in .html.tpl.php) was found to be different. Of course, for the current project, the lesser of the two issues is that associated with the beta4 files.
Summarily, I would like to advocate for adoption of the 3-liner change to the beta4 files. However, I defer to your judgement on the matter.
Comment #3
damienmckenna@m_david_ae: Glad to hear the problem appears to have been fixed along the way. Please open a new issue if you'd like to discuss the variable changing.
Comment #4
damienmckennaNow that Metatag v7.x-1.0-beta5 is out am closing this to keep the issue queue clean.