Skip to content
Snippets Groups Projects
Commit 5b256ecb authored by Igor Biki's avatar Igor Biki
Browse files

Merge branch...

Merge branch 'feature/ISTWCMS-4824-l26yan-Consolidate-taxonomy-term-creation-functions' into '1.0.x'

ISTWCMS-4824 Use _uw_cfg_common_create_term instead of _uw_ct_event_term_create and remove _uw_ct_event_term_create

See merge request !53
parents f02546ef 7e86b6fe
No related branches found
No related tags found
1 merge request!53ISTWCMS-4824 Use _uw_cfg_common_create_term instead of _uw_ct_event_term_create and remove _uw_ct_event_term_create
......@@ -7,7 +7,6 @@
use Drupal\field\Entity\FieldConfig;
use Drupal\node\Entity\Node;
use Drupal\taxonomy\Entity\Term;
/**
* Implements hook_install().
......@@ -28,48 +27,12 @@ function uw_ct_event_install() {
'Workshop',
];
$weight = 0;
foreach ($types as $type) {
_uw_ct_event_term_create($type, 'uw_tax_event_type', []);
_uw_cfg_common_create_term($type, 'uw_tax_event_type', $weight, []);
}
}
/**
* Helper function to create a taxonomy term programmatically.
*
* @code
* // Create top level term
* $term_id = _nodemaker_term_create('My Term', 'my_vocab', []);
*
* // Create term with parent term with an id of 999
* $term_id = _nodemaker_term_create('My Term', 'my_vocab', [999]);
* @endcode
*
* @param string $term
* - Term Name.
* @param string $vocabulary
* - System id of the vocabulary term will be added to.
* @param array $parent
* - Array of term ids to be assigned as parent.
*
* @return int|null
* - Returns the term id of the created term on success, null on failure.
*/
function _uw_ct_event_term_create($term, $vocabulary, array $parent = []) {
// Create the taxonomy term.
$new_term = Term::create([
'name' => $term,
'vid' => $vocabulary,
'parent' => $parent,
]);
// Save the taxonomy term.
$new_term->save();
// Return the taxonomy term id.
return $new_term->id();
}
/**
* Removes the first and last section from events.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment