Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Add an easy way to generate tags for an entity that isn't the current page entity.
Currently you seemingly can't do it without replicating a large portion of the metatag_entity_view() function.
Comment | File | Size | Author |
---|---|---|---|
#13 | metatag_metatags_save.JPG | 46.75 KB | RAWDESK |
#7 | metatag-generate_entity_metatags-2241083-7.patch | 7.75 KB | rooby |
Comments
Comment #1
rooby CreditAttribution: rooby commentedMy initial code example:
doesn't work.
Basically the best way seems to be to replicate metatags_entity_view() but without the specifics that make that function only work for the current page.
Like this:
Comment #2
rooby CreditAttribution: rooby commentedComment #3
rooby CreditAttribution: rooby commentedComment #4
rooby CreditAttribution: rooby commentedHere is a patch that makes it easy for another module to generate tags for an entity.
I included as an optional extra the metatags_get_entity_metatags() function, which further simplifies what a user would have to do to get the metatags, but maybe that part isn't really necessary.
Comment #6
rooby CreditAttribution: rooby commentedOops, new patch.
I don't love the idea of using entity_extract_ids() twice but the alternatives aren't really that crash hot either.
Comment #7
rooby CreditAttribution: rooby commentedHere is a new version of the patch for latest dev.
Comment #10
DamienMcKennaI tested this out locally, ran through a few scenarios, and everything still worked =) This is a great improvement, and finally provides a way of obtaining the final meta tags for a given entity. Thank you! I've committed this after some testing and review of the changes.
Comment #11
rooby CreditAttribution: rooby commentedGreat, thanks!
Comment #13
RAWDESK CreditAttribution: RAWDESK commented@rooby,
I've been experimenting with #1 for this goal :
-> programmatically create nodes from a remote http feed
-> load entity meta tags as by default configured in metatags UI (your get_entity_metatags helper function)
-> modify specific tags like og:locality og:latitude etc etc based on given http feed attributes
Is it possible to somehow save this by your helper function created output array ?
Have been looking inside the metatag.module for a crUd and could only come up with this provided function :
dpm'ing the 4 argument just gave me 2 metatags as shown in attached screenshot.
Comment #14
DamienMcKennaI've updated the documentation of metatag_metatags_save(), please open a new issue or let us know in #1466292: Document all Metatag's hooks if there's anything else that needs documentation. Thanks.