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.
I am programmatically generating nodes and need to override the metatag defaults. I have added the metatag field to the content type but I do not see in the docs how to do this.
I'm willing to help update the docs once I figure out how to do this.
Comment | File | Size | Author |
---|---|---|---|
#12 | metatag-n2809915-12.interdiff.txt | 1.89 KB | DamienMcKenna |
#12 | metatag-n2809915-12.patch | 1.72 KB | DamienMcKenna |
|
Comments
Comment #2
DamienMcKennaLets document this properly for both branches.
Comment #3
DamienMcKennaSo, lets look at the basics:
https://gaiaes.com/article/create-a-node-programmatically-drupal-8
Comment #4
DamienMcKennaentityManager() was replaced with entityTypeManager(), so it should be:
Comment #5
DamienMcKennaI wonder would this work?
Comment #6
haynescw CreditAttribution: haynescw commentedI will give your last comment a try today.
Comment #7
haynescw CreditAttribution: haynescw commentedWell, given your example i found that all i needed to do was serialize the data, but you dont have to add it to x-default, you can just assign it to the field like so.
Comment #8
nicxvan CreditAttribution: nicxvan as a volunteer commentedI was just able to confirm that using the following works as well.
$node->set('field_metatags', serialize([
'keywords' => 'Some Keywords',
'description' => 'Some Description',
]));
Where should I document this?
Comment #9
DamienMcKenna@haynescw: Awesome, thanks for testing that and working out the correct structure.
@nixvan: Great, thanks!
Additions to the README.txt would be the best step, for now.
Comment #10
nicxvan CreditAttribution: nicxvan as a volunteer commentedAdded some steps to the README.
Comment #11
DamienMcKennaDocumentation can go in 1.0.
Comment #12
DamienMcKennaSome improvements.
Comment #13
DamienMcKennaCommitted. Thanks, nicxvan!
Comment #16
itsnadeem CreditAttribution: itsnadeem commentedplease see this article for dynamically adding metatags.