Skip to content

Instantly share code, notes, and snippets.

@timonweb
Forked from facine/__INDEX.txt
Created July 6, 2016 13:05
Show Gist options
  • Save timonweb/6af02fe14b376e7b12ce8e3e9f15dea8 to your computer and use it in GitHub Desktop.
Save timonweb/6af02fe14b376e7b12ce8e3e9f15dea8 to your computer and use it in GitHub Desktop.
Drupal 8 - Examples
// 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");
unset($term);
unset($term_es);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment