Created
August 2, 2017 15:25
-
-
Save MatthieuScarset/51952018016cfa09c85df9c8b1233902 to your computer and use it in GitHub Desktop.
Programmatically assign meta tags to an entity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @see https://www.drupal.org/docs/8/modules/metatag | |
$entity_type = 'node'; | |
$values = [ | |
'nid' => NULL, | |
'type' => 'article', | |
'title' => 'Testing metatag creation', | |
'uid' => 1, | |
'status' => TRUE, | |
'field_meta_tags' => serialize([ | |
'title' => 'Some title', | |
'description' => 'Some description.', | |
'keywords' => 'Some,Keywords', | |
]), | |
]; | |
$node = \Drupal::entityTypeManager()->getStorage($entity_type)->create($values); | |
$node->save(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment