Skip to content

Instantly share code, notes, and snippets.

@MatthieuScarset
Created August 2, 2017 15:25
Show Gist options
  • Save MatthieuScarset/51952018016cfa09c85df9c8b1233902 to your computer and use it in GitHub Desktop.
Save MatthieuScarset/51952018016cfa09c85df9c8b1233902 to your computer and use it in GitHub Desktop.
Programmatically assign meta tags to an entity
// @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