In my configuration in some cases first call of metatag_entity_supports_metatags('smth') happens before hook metatag_entity_info_alter() is called. So when metatag_entity_supports_metatags('taxonomy_term') is called, taxonomy_term is already marked as not supporting metatags due to entities' info static chaching in metatag_entity_supports_metatags(). So in this case no metatags data stored for taxonomy term entity is loaded.

Attached patch fixes the problem but may result in slight performance degradation -- you can check if better solution could be found.

Comments

damienmckenna’s picture

Lets make sure this is fully fixed for the next release.

damienmckenna’s picture

Can you please install & enable the Devel module and let me know what data is shown in the 'metatags' array?

potop’s picture

I've never used Devel, so I don't know what you expect to see.

This is what it prints as a part of $page array when patch isn't applied:

[metatags] => Array
                (
                    [taxonomy_term:types] => Array
                        (
                            [h1] => Array
                                (
                                    [#attached] => Array
                                        (
                                            [drupal_add_html_head] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [#theme] => lacrema_metatags_hidden
                                                                    [#tag] => meta
                                                                    [#id] => metatag_h1_0
                                                                    [#name] => h1
                                                                    [#value] => Уход за кожей и волосами
                                                                    [#weight] => 5
                                                                )

                                                            [1] => metatag_h1_0
                                                        )

                                                )

                                        )

                                )

                            [seo_text_block] => Array
                                (
                                )

                            [title] => Array
                                (
                                    [#attached] => Array
                                        (
                                            [metatag_set_preprocess_variable] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [0] => html
                                                            [1] => head_title
                                                            [2] => Уход за кожей и волосами | Lacrema.ru
                                                        )

                                                    [1] => Array
                                                        (
                                                            [0] => html
                                                            [1] => head_array
                                                            [2] => Array
                                                                (
                                                                    [title] => Уход за кожей и волосами | Lacrema.ru
                                                                )

                                                        )

                                                )

                                        )

                                )

                            [description] => Array
                                (
                                    [#attached] => Array
                                        (
                                            [drupal_add_html_head] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [#theme] => metatag
                                                                    [#tag] => meta
                                                                    [#id] => metatag_description_0
                                                                    [#name] => description
                                                                    [#value] => Ежедневный уход за кожей тела и волосами мужчины может быть одновременно не только необходимостью, но и удовольствием. Из-за большего количества нагрузок в течение дня, мужчине необходимы особые средства по уходу, которые обеспечат не только эффективное очищение и защиту от бактерий и запахов, но и стойкое ощущение свежести и комфорта. Мужчине также важно, чтобы косметика для ухода за телом и волосами не раздражали неуместным запахом. Хотя мужская кожа кажется более грубой, она, как и женская, нуждается в бережном уходе. Чтобы кожа не потеряла своих защитных свойств, средства для ухода и очищения должны справляться с проблемами, с которыми мужчина сталкивается ежедневно. Мужская косметика должна поддерживать необходимый уровень увлажнённости кожи, защищать её от сухости или чрезмерной жирности и быстро снимать раздражения.
                                                                    [#weight] => 2.1
                                                                )

                                                            [1] => metatag_description_0
                                                        )

                                                )

                                        )

                                )

                            [robots] => Array
                                (
                                )

                            [generator] => Array
                                (
                                )

                            [canonical] => Array
                                (
                                    [#attached] => Array
                                        (
                                            [drupal_add_html_head] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [#theme] => metatag_link_rel
                                                                    [#tag] => link
                                                                    [#id] => metatag_canonical
                                                                    [#name] => canonical
                                                                    [#value] => http://local.lacrema.ru/types/muzhchiny/uhod-za-kozhey
                                                                    [#weight] => 11
                                                                    [#attached] => Array
                                                                        (
                                                                            [drupal_add_http_header] => Array
                                                                                (
                                                                                    [0] => Array
                                                                                        (
                                                                                            [0] => Link
                                                                                            [1] => <http://local.lacrema.ru/types/muzhchiny/uhod-za-kozhey>; rel="canonical"
                                                                                            [2] => 1
                                                                                        )

                                                                                )

                                                                        )

                                                                )

                                                            [1] => metatag_canonical
                                                        )

                                                )

                                        )

                                )

                            [shortlink] => Array
                                (
                                )

                        )

                )

And this one with my patch applied:

[metatags] => Array
                (
                    [taxonomy_term:types] => Array
                        (
                            [h1] => Array
                                (
                                    [#attached] => Array
                                        (
                                            [drupal_add_html_head] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [#theme] => lacrema_metatags_hidden
                                                                    [#tag] => meta
                                                                    [#id] => metatag_h1_0
                                                                    [#name] => h1
                                                                    [#value] => Уход за кожей для мужчин
                                                                    [#weight] => 5
                                                                )

                                                            [1] => metatag_h1_0
                                                        )

                                                )

                                        )

                                )

                            [title] => Array
                                (
                                    [#attached] => Array
                                        (
                                            [metatag_set_preprocess_variable] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [0] => html
                                                            [1] => head_title
                                                            [2] => Купить средства ухода за кожей для мужчин
                                                        )

                                                    [1] => Array
                                                        (
                                                            [0] => html
                                                            [1] => head_array
                                                            [2] => Array
                                                                (
                                                                    [title] => Купить средства ухода за кожей для мужчин
                                                                )

                                                        )

                                                )

                                        )

                                )

                            [description] => Array
                                (
                                    [#attached] => Array
                                        (
                                            [drupal_add_html_head] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [#theme] => metatag
                                                                    [#tag] => meta
                                                                    [#id] => metatag_description_0
                                                                    [#name] => description
                                                                    [#value] => Средства ухода за кожей и волосами для мужчин – бесплатные онлайн-консультации профессиональных косметологов, оперативная доставка по России. Уход за кожей лица мужчин с применением лечебной французской косметики обеспечит ее здоровый, молодой вид!
                                                                    [#weight] => 2.1
                                                                )

                                                            [1] => metatag_description_0
                                                        )

                                                )

                                        )

                                )

                            [keywords] => Array
                                (
                                    [#attached] => Array
                                        (
                                            [drupal_add_html_head] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [#theme] => metatag
                                                                    [#tag] => meta
                                                                    [#id] => metatag_keywords_0
                                                                    [#name] => keywords
                                                                    [#value] => уход, волосы, мужчины, мужские, средства, голова, купить
                                                                    [#weight] => 4.2
                                                                )

                                                            [1] => metatag_keywords_0
                                                        )

                                                )

                                        )

                                )

                            [seo_text_block] => Array
                                (
                                )

                            [robots] => Array
                                (
                                )

                            [generator] => Array
                                (
                                )

                            [canonical] => Array
                                (
                                    [#attached] => Array
                                        (
                                            [drupal_add_html_head] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [#theme] => metatag_link_rel
                                                                    [#tag] => link
                                                                    [#id] => metatag_canonical
                                                                    [#name] => canonical
                                                                    [#value] => http://local.lacrema.ru/types/muzhchiny/uhod-za-kozhey
                                                                    [#weight] => 11
                                                                    [#attached] => Array
                                                                        (
                                                                            [drupal_add_http_header] => Array
                                                                                (
                                                                                    [0] => Array
                                                                                        (
                                                                                            [0] => Link
                                                                                            [1] => <http://local.lacrema.ru/types/muzhchiny/uhod-za-kozhey>; rel="canonical"
                                                                                            [2] => 1
                                                                                        )

                                                                                )

                                                                        )

                                                                )

                                                            [1] => metatag_canonical
                                                        )

                                                )

                                        )

                                )

                            [shortlink] => Array
                                (
                                )

                        )

                )

In first case long "description" text comes from term's description, not from metatags' description.

damienmckenna’s picture

If you go to the taxonomy term page you'll see a Devel tab - go to that page, click the box to make it expand out one level and you should see a "metatags" item, then let me know what it contains - a screenshot might make it easier than cutting & pasting code. Please do this on a term that you've manually assigned values to, that'll help identify where the problem might be. Thanks.

potop’s picture

StatusFileSize
new115.25 KB

Let me know if this makes more sense to you

damienmckenna’s picture

Can you please show me what the Devel module shows on the "load" tab, e.g. "taxonomy/term/1/devel" instead of "taxonomy/term/1/devel/render"? Thanks.

potop’s picture

StatusFileSize
new67.15 KB

Unfortunately there's no "metatags" item on this page

damienmckenna’s picture

@potop: Can you try editing the term, make some changes to the term, hit Save and then see what it says? Thanks.

damienmckenna’s picture

Version: 7.x-1.4 » 7.x-1.x-dev
potop’s picture

StatusFileSize
new99.52 KB

After editing and saving it does show correct metatags.

If I then clear all caches it doesn't even show metatags fieldset on term's editing page, and after reloading the page fieldset is displayed with metatags fields filled by default values.

damienmckenna’s picture

Where are the "h1" and "seo_text_block" coming from? Did you write a custom module to add new meta tags?

potop’s picture

Yes, I did!

damienmckenna’s picture

Please try disabling the custom module, see if that makes a difference.

potop’s picture

As I mentioned in the original post, the reason of metatags not being loaded is the early call of metatag_entity_supports_metatags('smth').
I disabled anything custom that deals with metatags in my project but it didn't make it.
In debugger I can see that this first call of metatag_entity_supports_metatags() origins by commerce_coupon module when hook_entity_load() is invoked for commerce_coupon_type, metatag_entity_info_alter() which enables metatags support for taxonomy terms is being called later.
When I disable commerce_coupon module metatags work as expected.

damienmckenna’s picture

@potop: Ah! That's great detail and will help a TON in tracking down the problem. Thanks!

damienmckenna’s picture

@potop: Out of interest, are you using Commerce Coupon v1 or v2?

potop’s picture

commerce_coupon 7.x-1.0-beta7
and I usually have both commerce_coupon_fixed_amount and commerce_coupon_pct enabled.
Haven't check who among these 3 is doing this trick with metatags.

damienmckenna’s picture

StatusFileSize
new4.73 KB

Ah! The execution process is as follows:

  • commerce_coupon_entity_info_alter()
  • commerce_coupon_get_types()
  • entity_load() for all entities of type 'commerce_coupon_type',
  • metatag_entity_load()
  • metatag_entity_supports_metatags()
  • entity_get_info()

But, as you said yourself, at that point metatag_entity_info_alter() hasn't ran yet, so from that point onwards it won't have enabled Metatag support for entities.

Given the above, your patch makes complete sense now.

I've rerolled the patch to fix the file path issue, and tweak both metatag_entity_load() and metatag_entity_supports_metatags() slightly.

damienmckenna’s picture

Status: Active » Needs review

The last submitted patch, metatags_patch.patch, failed testing.

damienmckenna’s picture

@potop: Can you please give my patch a spin, just to make sure that I wasn't too ambitious with the changes? Thanks.

potop’s picture

@DamienMcKenna my environment works smoothly with your patch.

btw, if you set "Needs review" status for the issue -- does it mean that my action is required?

damienmckenna’s picture

Status: Needs review » Fixed

@potop: It wasn't specifically directed at you, but in this scenario it's worth checking to see if a newer patch also resolves the problem you raised or if it either does not or introduces regressions.

Thanks for your help on this! Committed!

  • DamienMcKenna committed 72418db on 7.x-1.x authored by potop
    Issue #2370439 by potop, DamienMcKenna: Work around hook_entity_load()...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

ciss’s picture

This fix should come with a change notice regarding metatag_entity_supports_metatags().
I was relying on metatag_entity_supports_metatags() to preload entity types, and the change broke some of my code (easy to fix, but hard to spot).

damienmckenna’s picture

@ciss: What was the specific problem you ran into? I've started a change notice for it but would appreciate some insight into the problem you had.

ciss’s picture

@DamienMcKenna: I was calling metatag_entity_supports_metatags() without arguments to retrieve a complete list of supported entities (code). After updating metatag to HEAD, that list was empty.
In my particular case that broke the views relationships to Metatag supporting entities which I were retrieving dynamically.

Unless I've missed other functions better suited to this task, this function seems to be central in determining metatag support.