Skip to content

Instantly share code, notes, and snippets.

@keopx
Forked from facine/__INDEX.txt
Last active August 29, 2015 14:22
Show Gist options
  • Save keopx/5e2d22fc4790b78b9ade to your computer and use it in GitHub Desktop.
Save keopx/5e2d22fc4790b78b9ade to your computer and use it in GitHub Desktop.
<?php
// Programmatically create and translate nodes.
use Drupal\node\Entity\Node;
$node = Node::create([
// The node entity bundle.
'type' => 'article',
'langcode' => 'en',
'created' => REQUEST_TIME,
'changed' => REQUEST_TIME,
// The user ID.
'uid' => 1,
'title' => 'My test!',
// An array with taxonomy terms.
'field_tags' =>[2],
'body' => [
'summary' => '',
'value' => '<p>The body of my node.</p>',
'format' => 'full_html',
],
]);
$node->save();
\Drupal::service('path.alias_storage')->save("node/" . $node->id(), "my/path", "en");
$node_es = $node->getTranslation('es');
$node_es->title = 'Mi prueba!';
$node_es->body->value = '<p>El cuerpo de mi nodo.</p>';
$node_es->body->format = 'full_html';
$node_es->save();
\Drupal::service('path.alias_storage')->save("node/" . $node->id(), "mi/ruta", "es");
<?php
// Programmatically create and translate taxonomy terms.
use Drupal\taxonomy\Entity\Term;
$term = Term::create([
'vid' => 'sport_activity',
'langcode' => 'en',
'name' => 'My tag',
'description' => [
'value' => '<p>My description.</p>',
'format' => 'full_html',
],
'weight' => -1
'parent' => array (0);
]);
$term->save();
\Drupal::service('path.alias_storage')->save("taxonomy/term/" . $term->id(), "tags/my-tag", "en");
$term_es = $term->getTranslation('es');
$term_es->name = 'Mi etiqueta';
$term_es->description->value = '<p>Mi descripción.</p>';
$term_es->description->format = 'full_html';
$term_es->save();
\Drupal::service('path.alias_storage')->save("taxonomy/term/" . $term->id(), "etiquetas/mi-etiqueta", "es");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment