backdrop-contrib / metatag

Add structured metadata, aka "meta tags", for various pages on your site.
GNU General Public License v2.0
3 stars 15 forks source link

Argument 3 passed to metatag_metatags_form() must be of the type array, null given, called in ../metatag.admin.inc on line 299 #63

Closed alanmels closed 1 year ago

alanmels commented 3 years ago

I've just installed the module and without doing anything else, opened the /admin/config/metadata/metatags page to start overriding the Content part. Clicking on the Configure link it takes to /admin/config/metadata/metatags/config/node page to output:

Error Argument 3 passed to metatag_metatags_form() must be of the type array, null given, called in /var/www/docroot/modules/metatag/metatag.admin.inc on line 299

The line 299 looks like:

metatag_metatags_form($form, $config['instance'], $config['config'], $options);

Checking the content of $config array shows there is no such an array member as $config['config']:

(Array, 8 elements)

    module (String, 7 characters ) metatag
    storage (String, 10 characters ) overridden
    name (String, 4 characters ) node
    instance (String, 4 characters ) node
    label (String, 7 characters ) Content
    disabled (Boolean) FALSE
    api_version (Integer) 1
    config (NULL) Get 
alanmels commented 3 years ago

Could not replicate this on another Backdrop setup, so need to dig deeper on why it's giving on a specific Backdrop site. BTW, similar line for Drupal 7 module looks differently:

metatag_metatags_form($form, $config->instance, $config->config, $options);

so seems Drupal 7 went using object instead of array.

alanmels commented 3 years ago

Quote from the relevant discussion on DO:

Guito339 CreditAttribution: Guito339 as a volunteer commented 7 October 2016 at 19:16

@DamienMcKenna, @Vaene,

I'm running into this as well (v 7.x-1.17) There is likely something wrong with the data in the metatag_config table, but it's not clear what exactly is wrong and I can't just fix that table on one env and copy it to other envs.... so here is my diagnosis and solution.

Diagnosis The function function metatag_config_edit_form($form, &$form_state, $config) requires a $config that is passed to: metatag_metatags_form($form, $config->instance, $config->config, $options)

The function function metatag_config_edit_form($form, &$form_state, $config) should probably confirm that $config->$config is set before passing it to metatag_metatags_form($form, $config->instance, $config->config, $options)

If it's not set, then perhaps some sort of helper message should be sent, or some sort of config default should be set.

The way the menu item works is to call metatag_config_load on the 5th argument to the page. so for admin/config/search/metatags/config/node the menu system would pass the result of metatag_config_load('node')

Solution (Not a good one, as it involves hacking a contrib module) I've used the following code to get around the empty $config in metatag.admin.inc. Right before the call to metatag_metatags_form($form, $config->instance, $config->config, $options); add

if (empty($config->config)) { $config = metatag_config_load(arg(5)); }

This will set the config the same way as the menu system would and only changes $config when its empty.

mazzech commented 3 years ago

I my case, it helped to uninstall (admin/modules/uninstall) and reinstall the module.

allsite commented 2 years ago

I get this same error when clicking Configure on the Homepage default metatags.

quicksketch commented 2 years ago

I think this may have been related to an issue I discovered in https://github.com/backdrop-contrib/metatag/issues/92. The ability to enable/disable particular tags was resulting an incorrect cache being set sometimes. In such situations, the configuration for a particular tag might go missing when the cache has been set in the database. That particular cache problem has been fixed, but if this was occurring in D7 as well then that issue probably doesn't solve 100% of the situations in which this could occur.

If this happens again, could you try clearing all caches from the admin bar and loading the form again?

jenlampton commented 1 year ago

Closing since no one has reported any issues since the fix in #92. If that's not the case for anyone, please re-open.