-
-
Save timonweb/6af02fe14b376e7b12ce8e3e9f15dea8 to your computer and use it in GitHub Desktop.
Drupal 8 - Examples
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
// 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 | |
]); | |
$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