Commit b6a04ed1 authored by Gábor Hojtsy's avatar Gábor Hojtsy

Issue #3028627 by Eli-T, rakesh.gectcr, shaal, smaz, Gábor Hojtsy, kjay:...

Issue #3028627 by Eli-T, rakesh.gectcr, shaal, smaz, Gábor Hojtsy, kjay: Restructure Umami's default content files so more than one language can be included
parent d649b7f4
title,body,author,slug,image,alt,tags
Give it a go and grow your own herbs,give-it-a-go-and-grow-your-own-herbs.html,Holly Foat,articles/give-it-a-go-and-grow-your-own-herbs,home-grown-herbs.jpg,"Fresh cut herbs including mint, parsley, thyme and dill","Grow your own,Seasonal,Herbs"
Dairy-free and delicious milk chocolate,dairy-free-delicious-milk-chocolate.html,Umami,articles/dairy-free-and-delicious-milk-chocolate,vegan-chocolate.jpg,"A delicious bar of dairy-free milk chocolate, broken into pieces.","Vegan,Chocolate"
The real deal for supermarket savvy shopping,the-real-deal-for-supermarket-savvy-shopping.html,Megan Collins Quinlan,articles/the-real-deal-for-supermarket-savvy-shopping,supermarket-savvy-umami.jpg,Products presented on supermarket shelving.,"Supermarkets,Shopping"
The Umami guide to our favorite mushrooms,the-umami-guide-to-our-favourite-mushrooms.html,Umami,articles/the-umami-guide-to-our-favourite-mushrooms,mushrooms-umami.jpg,A delightful selection of mushroom varieties laid out on a simple wooden plate.,"Mushrooms,Vegetarian"
Let's hear it for carrots,lets-hear-it-for-carrots.html,Umami,articles/lets-hear-it-for-carrots,heritage-carrots.jpg,"Purple, orange, yellow and white heritage carrots.","Carrots,Vegetarian,Healthy"
Baking mishaps - our troubleshooting tips,baking-mishaps-our-troubleshooting-tips.html,"Umami",articles/baking-mishaps-our-troubleshooting-tips,chocolate-brownie-umami.jpg,"A delicious chocolate brownie","Baking,Learn to cook"
Skip the spirits with delicious mocktails,skip-the-spirits-with-delicious-mocktails.html,Megan Collins Quinlan,articles/skip-the-spirits-with-delicious-mocktails,mojito-mocktail.jpg,"Fresh mojito mocktail with garnish of mint leaves, ice, and sliced lime","Alcohol free,Drinks,Party,Cocktail party,Dinner party"
Give your oatmeal the ultimate makeover,give-your-oatmeal-the-ultimate-makeover.html,Umami,articles/give-your-oatmeal-the-ultimate-makeover,oatmeal-fruit-syrup-topping.jpg,"Oatmeal topped with a vibrant mix of berries, nuts, and seeds","Vegan,Vegetarian,Oats,Breakfast,Dessert"
Give it a go and grow your own herbs,give-it-a-go-and-grow-your-own-herbs.html,Holly Foat,articles/give-it-a-go-and-grow-your-own-herbs,home-grown-herbs.jpg,"Fresh cut herbs including mint, parsley, thyme and dill","14,23,16"
Dairy-free and delicious milk chocolate,dairy-free-delicious-milk-chocolate.html,Umami,articles/dairy-free-and-delicious-milk-chocolate,vegan-chocolate.jpg,"A delicious bar of dairy-free milk chocolate, broken into pieces.","27,7"
The real deal for supermarket savvy shopping,the-real-deal-for-supermarket-savvy-shopping.html,Megan Collins Quinlan,articles/the-real-deal-for-supermarket-savvy-shopping,supermarket-savvy-umami.jpg,Products presented on supermarket shelving.,"26,24"
The Umami guide to our favorite mushrooms,the-umami-guide-to-our-favourite-mushrooms.html,Umami,articles/the-umami-guide-to-our-favourite-mushrooms,mushrooms-umami.jpg,A delightful selection of mushroom varieties laid out on a simple wooden plate.,"18,28"
Let's hear it for carrots,lets-hear-it-for-carrots.html,Umami,articles/lets-hear-it-for-carrots,heritage-carrots.jpg,"Purple, orange, yellow and white heritage carrots.","6,28,15"
Baking mishaps - our troubleshooting tips,baking-mishaps-our-troubleshooting-tips.html,"Umami",articles/baking-mishaps-our-troubleshooting-tips,chocolate-brownie-umami.jpg,"A delicious chocolate brownie","3,17"
Skip the spirits with delicious mocktails,skip-the-spirits-with-delicious-mocktails.html,Megan Collins Quinlan,articles/skip-the-spirits-with-delicious-mocktails,mojito-mocktail.jpg,"Fresh mojito mocktail with garnish of mint leaves, ice, and sliced lime","1,12,20,8,11"
Give your oatmeal the ultimate makeover,give-your-oatmeal-the-ultimate-makeover.html,Umami,articles/give-your-oatmeal-the-ultimate-makeover,oatmeal-fruit-syrup-topping.jpg,"Oatmeal topped with a vibrant mix of berries, nuts, and seeds","27,28,19,4,10"
title,image,alt,summary,author,recipe_category,preparation_time,cooking_time,total_time,difficulty,ingredients,recipe_instruction,number_of_servings,tags,slug
Deep mediterranean quiche,mediterranean-quiche-umami.jpg,"A delicious deep layered Mediterranean quiche with basil garnish.",An Italian inspired quiche with sun dried tomatoes and courgette. A perfect light meal for a summer's day.,Umami,Main course,40,30,70,medium,"For the pastry:,280g plain flour,140g butter,Cold water,For the filling:,1 onion,2 garlic cloves,Half a courgette,450ml soya milk,500g grated parmesan,2 eggs,200g sun dried tomatoes,100g feta",mediterranean-quiche-umami.html,8,"Pastry,Egg",recipes/deep-mediterranean-quiche
Vegan chocolate and nut brownies,vegan-chocolate-nut-brownies.jpg,"A stack of chocolate and pecan brownies, sprinkled with pecan crumbs and crushed walnut, fresh out of the oven","Scrumptious vegan chocolate brownies that are rich, fudgy, and nutty. These delights have a surprise hint of coconut making them the perfect indulgence. Serve warm with a little vanilla dairy-free ice cream!",Umami,Snack,20,20,40,medium,"6 tbsp sunflower oil, 80g vegan dark chocolate, 170g plain flour, 80g coconut flour, 1 tsp baking powder, 9 tsp cocoa powder, 100g caster sugar, 3 tbsp of maple syrup, 1/4 tsp sea salt, 1 tsp vanilla extract, 230ml unsweetened organic soya milk, 100g pecan nuts, 80g walnut halves",vegan-chocolate-nut-brownies.html,12,"Baking,Chocolate,Vegan,Dairy-free",recipes/vegan-chocolate-and-nut-brownies
Super easy vegetarian pasta bake,veggie-pasta-bake-umami.jpg,Cheesy pasta dish with vegetarian sausages and topped with mozzarella cheese and basil,A wholesome pasta bake is the ultimate comfort food. This delicious bake is super quick to prepare and an ideal midweek meal for all the family.,Umami,Main course,5,20,25,easy,"400g wholewheat pasta, 1 onion, 2 garlic cloves, 1 pack vegetarian sausages, 400g chopped tomatoes, 50g sliced sun dried tomatoes, 1 pinch sugar, 3 tbsp red pesto, 50g cheddar cheese, Basil or mixed herbs, 100g mozzarella",veggie-pasta-bake-umami.html,4,"Vegetarian,Pasta,Baked",recipes/super-easy-vegetarian-pasta-bake
Watercress soup,watercress-soup-umami.jpg,Watercress soup with a sprig of coriander as garnish in a white bowl with green trim.,"A wonderfully simple and light soup, making the most of seasonal, local produce. ",Umami,Starter,10,20,30,easy,"3 bunches watercress,3 potatoes,3 onions,2 leeks,800ml stock,5 tbsp crème fraîche",watercress-soup-umami.html,4,"Soup,Vegetarian",recipes/watercress-soup
Victoria sponge cake,victoria-sponge-umami.jpg,"A classic, uncut Victoria sponge with a deep filling of butter cream and jam","A traditional Victoria sponge cake, perfect for any afternoon with a cup of tea.",Umami,Dessert,20,20,40,easy,"225g butter or margarine,225g caster sugar,225g self-raising flour,4 eggs,1 tsp baking powder,3 tbsp of jam for the filling,Icing sugar to dust the top,Cream to serve",victoria-sponge-umami.html,10,Cake,recipes/victoria-sponge-cake
Gluten free pizza,pizza-umami.jpg,"Olives, basil, and mozzarella top a gluten free pizza crust with marinara sauce.","A gorgeous and simple gluten free pizza, with deliciously indulgent mozzarella and Parma ham. Can easily be vegetarian by leaving out the ham.",Umami,Main course,15,15,30,,"400g gluten free flour, 125ml warm water, 125ml milk, 1 sachet dried yeast, 2 tsp sugar, 1 tsp salt, 2 tbsp olive oil, 4 tbsp tomato puree, 1 garlic clove, Fresh basil, 200g mozzarella, 100g rocket, 5 slices Parma ham",pizza-umami.html,4,,recipes/gluten-free-pizza
Thai green curry,thai-green-curry-umami.jpg,"A traditional bowl of creamy, aromatic Thai green curry with chunks of chicken in a small bowl with jasmine rice.",A quick and easy version of the classic Thai green curry. Perfect for a midweek meal!,Umami,Main course,10,15,25,,"400g coconut milk, 400g chicken or tofu, 1 tbsp Thai green curry paste, 1 garlic clove, 2 tsp fish sauce, 400g mushrooms, 200g green beans, Fresh coriander leaves, Jasmine rice",thai-green-curry-umami.html,4,,recipes/thai-green-curry
Crema catalana,crema-catalana-umami.jpg,"Typical Catalan dessert made from cream and egg yolks, covered with a traditional layer of caramelized sugar to provide a crispy contrast.",Enjoy this sweet recipe for one of the oldest desserts in Europe. It requires very few ingredients!,Umami,Dessert,10,20,30,,"1l milk, 200g sugar, 6 egg yolks, 30g cornstarch, 1 cinnamon stick, 1 piece lemon peel",crema-catalana-umami.html,8,"Egg, Vegetarian",recipes/crema-catalana
Fiery chili sauce,chili-sauce-umami.jpg,"An iridescent array of chilies, onions, and garlic, slowly sweating over a low heat","A rich and fiery chili sauce. Take care when handling chili peppers. And serve sparingly!",Umami,Accompaniment,10,50,60,easy,"2 red onions, 1 lemon, 2 limes, 250ml malt vinegar, 7 garlic cloves, 1 green bell pepper, 1 red bell pepper, 800g cherry tomatoes, 30 mixed chilies, Olive oil, 1 tbsp ground black pepper, 1 tbsp brown sugar",chili-sauce-umami.html,60,Vegetarian,recipes/fiery-chili-sauce
Deep mediterranean quiche,mediterranean-quiche-umami.jpg,"A delicious deep layered Mediterranean quiche with basil garnish.",An Italian inspired quiche with sun dried tomatoes and courgette. A perfect light meal for a summer's day.,Umami,3,40,30,70,medium,"For the pastry:,280g plain flour,140g butter,Cold water,For the filling:,1 onion,2 garlic cloves,Half a courgette,450ml soya milk,500g grated parmesan,2 eggs,200g sun dried tomatoes,100g feta",mediterranean-quiche-umami.html,8,"22,13",recipes/deep-mediterranean-quiche
Vegan chocolate and nut brownies,vegan-chocolate-nut-brownies.jpg,"A stack of chocolate and pecan brownies, sprinkled with pecan crumbs and crushed walnut, fresh out of the oven","Scrumptious vegan chocolate brownies that are rich, fudgy, and nutty. These delights have a surprise hint of coconut making them the perfect indulgence. Serve warm with a little vanilla dairy-free ice cream!",Umami,4,20,20,40,medium,"6 tbsp sunflower oil, 80g vegan dark chocolate, 170g plain flour, 80g coconut flour, 1 tsp baking powder, 9 tsp cocoa powder, 100g caster sugar, 3 tbsp of maple syrup, 1/4 tsp sea salt, 1 tsp vanilla extract, 230ml unsweetened organic soya milk, 100g pecan nuts, 80g walnut halves",vegan-chocolate-nut-brownies.html,12,"3,7,27,9",recipes/vegan-chocolate-and-nut-brownies
Super easy vegetarian pasta bake,veggie-pasta-bake-umami.jpg,Cheesy pasta dish with vegetarian sausages and topped with mozzarella cheese and basil,A wholesome pasta bake is the ultimate comfort food. This delicious bake is super quick to prepare and an ideal midweek meal for all the family.,Umami,3,5,20,25,easy,"400g wholewheat pasta, 1 onion, 2 garlic cloves, 1 pack vegetarian sausages, 400g chopped tomatoes, 50g sliced sun dried tomatoes, 1 pinch sugar, 3 tbsp red pesto, 50g cheddar cheese, Basil or mixed herbs, 100g mozzarella",veggie-pasta-bake-umami.html,4,"28,21,2",recipes/super-easy-vegetarian-pasta-bake
Watercress soup,watercress-soup-umami.jpg,Watercress soup with a sprig of coriander as garnish in a white bowl with green trim.,"A wonderfully simple and light soup, making the most of seasonal, local produce. ",Umami,5,10,20,30,easy,"3 bunches watercress,3 potatoes,3 onions,2 leeks,800ml stock,5 tbsp crème fraîche",watercress-soup-umami.html,4,"25,28",recipes/watercress-soup
Victoria sponge cake,victoria-sponge-umami.jpg,"A classic, uncut Victoria sponge with a deep filling of butter cream and jam","A traditional Victoria sponge cake, perfect for any afternoon with a cup of tea.",Umami,2,20,20,40,easy,"225g butter or margarine,225g caster sugar,225g self-raising flour,4 eggs,1 tsp baking powder,3 tbsp of jam for the filling,Icing sugar to dust the top,Cream to serve",victoria-sponge-umami.html,10,5,recipes/victoria-sponge-cake
Gluten free pizza,pizza-umami.jpg,"Olives, basil, and mozzarella top a gluten free pizza crust with marinara sauce.","A gorgeous and simple gluten free pizza, with deliciously indulgent mozzarella and Parma ham. Can easily be vegetarian by leaving out the ham.",Umami,3,15,15,30,,"400g gluten free flour, 125ml warm water, 125ml milk, 1 sachet dried yeast, 2 tsp sugar, 1 tsp salt, 2 tbsp olive oil, 4 tbsp tomato puree, 1 garlic clove, Fresh basil, 200g mozzarella, 100g rocket, 5 slices Parma ham",pizza-umami.html,4,,recipes/gluten-free-pizza
Thai green curry,thai-green-curry-umami.jpg,"A traditional bowl of creamy, aromatic Thai green curry with chunks of chicken in a small bowl with jasmine rice.",A quick and easy version of the classic Thai green curry. Perfect for a midweek meal!,Umami,3,10,15,25,,"400g coconut milk, 400g chicken or tofu, 1 tbsp Thai green curry paste, 1 garlic clove, 2 tsp fish sauce, 400g mushrooms, 200g green beans, Fresh coriander leaves, Jasmine rice",thai-green-curry-umami.html,4,,recipes/thai-green-curry
Crema catalana,crema-catalana-umami.jpg,"Typical Catalan dessert made from cream and egg yolks, covered with a traditional layer of caramelized sugar to provide a crispy contrast.",Enjoy this sweet recipe for one of the oldest desserts in Europe. It requires very few ingredients!,Umami,2,10,20,30,,"1l milk, 200g sugar, 6 egg yolks, 30g cornstarch, 1 cinnamon stick, 1 piece lemon peel",crema-catalana-umami.html,8,"13,28",recipes/crema-catalana
Fiery chili sauce,chili-sauce-umami.jpg,"An iridescent array of chilies, onions, and garlic, slowly sweating over a low heat","A rich and fiery chili sauce. Take care when handling chili peppers. And serve sparingly!",Umami,1,10,50,60,easy,"2 red onions, 1 lemon, 2 limes, 250ml malt vinegar, 7 garlic cloves, 1 green bell pepper, 1 red bell pepper, 800g cherry tomatoes, 30 mixed chilies, Olive oil, 1 tbsp ground black pepper, 1 tbsp brown sugar",chili-sauce-umami.html,60,28,recipes/fiery-chili-sauce
id,term
1,Alcohol free
2,Baked
3,Baking
4,Breakfast
5,Cake
6,Carrots
7,Chocolate
8,Cocktail party
9,Dairy-free
10,Dessert
11,Dinner party
12,Drinks
13,Egg
14,Grow your own
15,Healthy
16,Herbs
17,Learn to cook
18,Mushrooms
19,Oats
20,Party
21,Pasta
22,Pastry
23,Seasonal
24,Shopping
25,Soup
26,Supermarkets
27,Vegan
28,Vegetarian
......@@ -55,6 +55,17 @@ class InstallHelper implements ContainerInjectionInterface {
*/
protected $fileSystem;
/**
* Term ID map.
*
* Used to store term IDs created in the import process against
* vocabulary and row in the source CSV files. This allows the created terms
* to be cross referenced when creating articles and recipes.
*
* @var array
*/
protected $termIdMap;
/**
* Constructs a new InstallHelper object.
*
......@@ -75,6 +86,7 @@ public function __construct(AliasManagerInterface $aliasManager, EntityTypeManag
$this->moduleHandler = $moduleHandler;
$this->state = $state;
$this->fileSystem = $fileSystem;
$this->termIdMap = [];
}
/**
......@@ -92,15 +104,89 @@ public static function create(ContainerInterface $container) {
/**
* Imports default contents.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* @throws \Drupal\Core\Entity\EntityStorageException
*/
public function importContent() {
$this->importEditors()
$this->importTerms('tags', 'tags.csv')
->importTerms('recipe_category', 'recipe_categories.csv')
->importEditors()
->importArticles()
->importRecipes()
->importPages()
->importBlockContent();
}
/**
* Imports terms for a given vocabulary and filename.
*
* @param string $vocabulary
* Machine name of vocabulary to which we should save terms.
* @param string $filename
* Filename of the file containing the terms to import.
*
* @return $this
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* @throws \Drupal\Core\Entity\EntityStorageException
*/
protected function importTerms($vocabulary, $filename) {
$module_path = $this->moduleHandler->getModule('demo_umami_content')->getPath();
$term_storage = $this->entityTypeManager->getStorage('taxonomy_term');
if (($handle = fopen($module_path . "/default_content/languages/en/$filename", 'r')) !== FALSE) {
$header = fgetcsv($handle);
while (($data = fgetcsv($handle)) !== FALSE) {
$data = array_combine($header, $data);
$term_name = trim($data['term']);
$term = $term_storage->create([
'name' => $term_name,
'vid' => $vocabulary,
'path' => ['alias' => '/' . Html::getClass($vocabulary) . '/' . Html::getClass($term_name)],
]);
$term->save();
$this->storeCreatedContentUuids([$term->uuid() => 'taxonomy_term']);
$this->saveTermId($vocabulary, $data['id'], $term->id());
}
}
return $this;
}
/**
* Retrieves the Term ID of a term saved during the import process.
*
* @param string $vocabulary
* Machine name of vocabulary to which it was saved.
* @param int $term_csv_id
* The term's ID from the CSV file.
*
* @return int
* Term ID, or 0 if Term ID could not be found.
*/
protected function getTermId($vocabulary, $term_csv_id) {
if (array_key_exists($vocabulary, $this->termIdMap) && array_key_exists($term_csv_id, $this->termIdMap[$vocabulary])) {
return $this->termIdMap[$vocabulary][$term_csv_id];
}
return 0;
}
/**
* Saves a Term ID generated when saving a taxonomy term.
*
* @param string $vocabulary
* Machine name of vocabulary to which it was saved.
* @param int $term_csv_id
* The term's ID from the CSV file.
* @param int $tid
* Term ID generated when saved in the Drupal database.
*/
protected function saveTermId($vocabulary, $term_csv_id, $tid) {
$this->termIdMap[$vocabulary][$term_csv_id] = $tid;
}
/**
* Imports editors.
*
......@@ -137,7 +223,7 @@ protected function importEditors() {
protected function importArticles() {
$module_path = $this->moduleHandler->getModule('demo_umami_content')
->getPath();
if (($handle = fopen($module_path . '/default_content/articles.csv', "r")) !== FALSE) {
if (($handle = fopen($module_path . '/default_content/languages/en/articles.csv', "r")) !== FALSE) {
$uuids = [];
$header = fgetcsv($handle);
while (($data = fgetcsv($handle)) !== FALSE) {
......@@ -151,7 +237,7 @@ protected function importArticles() {
// Fields mapping starts.
// Set Body Field.
if (!empty($data['body'])) {
$body_path = $module_path . '/default_content/article_body/' . $data['body'];
$body_path = $module_path . '/default_content/languages/en/article_body/' . $data['body'];
$body = file_get_contents($body_path);
if ($body !== FALSE) {
$values['body'] = [['value' => $body, 'format' => 'basic_html']];
......@@ -165,8 +251,10 @@ protected function importArticles() {
if (!empty($data['tags'])) {
$values['field_tags'] = [];
$tags = explode(',', $data['tags']);
foreach ($tags as $term) {
$values['field_tags'][] = ['target_id' => $this->getTerm($term)];
foreach ($tags as $tag_id) {
if ($tid = $this->getTermId('tags', $tag_id)) {
$values['field_tags'][] = ['target_id' => $tid];
}
}
}
// Set article author.
......@@ -201,7 +289,7 @@ protected function importArticles() {
protected function importRecipes() {
$module_path = $this->moduleHandler->getModule('demo_umami_content')->getPath();
if (($handle = fopen($module_path . '/default_content/recipes.csv', "r")) !== FALSE) {
if (($handle = fopen($module_path . '/default_content/languages/en/recipes.csv', "r")) !== FALSE) {
$header = fgetcsv($handle);
$uuids = [];
while (($data = fgetcsv($handle)) !== FALSE) {
......@@ -236,8 +324,10 @@ protected function importRecipes() {
if (!empty($data['recipe_category'])) {
$values['field_recipe_category'] = [];
$tags = array_filter(explode(',', $data['recipe_category']));
foreach ($tags as $term) {
$values['field_recipe_category'][] = ['target_id' => $this->getTerm($term, 'recipe_category')];
foreach ($tags as $tag_id) {
if ($tid = $this->getTermId('recipe_category', $tag_id)) {
$values['field_recipe_category'][] = ['target_id' => $tid];
}
}
}
// Set field_preparation_time Field.
......@@ -266,7 +356,7 @@ protected function importRecipes() {
}
// Set field_recipe_instruction Field.
if (!empty($data['recipe_instruction'])) {
$recipe_instruction_path = $module_path . '/default_content/recipe_instructions/' . $data['recipe_instruction'];
$recipe_instruction_path = $module_path . '/default_content/languages/en/recipe_instructions/' . $data['recipe_instruction'];
$recipe_instructions = file_get_contents($recipe_instruction_path);
if ($recipe_instructions !== FALSE) {
$values['field_recipe_instruction'] = [['value' => $recipe_instructions, 'format' => 'basic_html']];
......@@ -276,8 +366,10 @@ protected function importRecipes() {
if (!empty($data['tags'])) {
$values['field_tags'] = [];
$tags = array_filter(explode(',', $data['tags']));
foreach ($tags as $term) {
$values['field_tags'][] = ['target_id' => $this->getTerm($term)];
foreach ($tags as $tag_id) {
if ($tid = $this->getTermId('tags', $tag_id)) {
$values['field_tags'][] = ['target_id' => $tid];
}
}
}
......@@ -297,7 +389,7 @@ protected function importRecipes() {
* @return $this
*/
protected function importPages() {
if (($handle = fopen($this->moduleHandler->getModule('demo_umami_content')->getPath() . '/default_content/pages.csv', "r")) !== FALSE) {
if (($handle = fopen($this->moduleHandler->getModule('demo_umami_content')->getPath() . '/default_content/languages/en/pages.csv', "r")) !== FALSE) {
$headers = fgetcsv($handle);
$uuids = [];
while (($data = fgetcsv($handle)) !== FALSE) {
......@@ -485,38 +577,6 @@ protected function getUser($name) {
return $user->id();
}
/**
* Looks up a term by name, if it is missing the term is created.
*
* @param string $term_name
* Term name.
* @param string $vocabulary_id
* Vocabulary ID.
*
* @return int
* Term ID.
*/
protected function getTerm($term_name, $vocabulary_id = 'tags') {
$term_name = trim($term_name);
$term_storage = $this->entityTypeManager->getStorage('taxonomy_term');
$terms = $term_storage->loadByProperties([
'name' => $term_name,
'vid' => $vocabulary_id,
]);
if (!$terms) {
$term = $term_storage->create([
'name' => $term_name,
'vid' => $vocabulary_id,
'path' => ['alias' => '/' . Html::getClass($vocabulary_id) . '/' . Html::getClass($term_name)],
]);
$term->save();
$this->storeCreatedContentUuids([$term->uuid() => 'taxonomy_term']);
return $term->id();
}
$term = reset($terms);
return $term->id();
}
/**
* Creates a file entity based on an image path.
*
......
......@@ -21,9 +21,9 @@ public function testAccessDeniedToFiles() {
$files_to_test = [
'images/heritage-carrots.jpg',
'recipe_instructions/mediterranean-quiche-umami.html',
'article_body/lets-hear-it-for-carrots.html',
'articles.csv',
'languages/en/recipe_instructions/mediterranean-quiche-umami.html',
'languages/en/article_body/lets-hear-it-for-carrots.html',
'languages/en/articles.csv',
];
foreach ($files_to_test as $file) {
// Hard code the path since the demo_umami profile is not installed.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment