Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uw_cfg_common
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WCMS
uw_cfg_common
Commits
c838f96e
Commit
c838f96e
authored
4 years ago
by
Lily Yan
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-4156 Create and pre-load audience taxonomy terms same as those in D7
parent
662394ea
No related branches found
No related tags found
1 merge request
!3
Feature/istwcms 4156 l26yan set up catalogs terms
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
uw_cfg_common.install
+78
-0
78 additions, 0 deletions
uw_cfg_common.install
with
78 additions
and
0 deletions
uw_cfg_common.install
+
78
−
0
View file @
c838f96e
...
@@ -95,4 +95,82 @@ function uw_cfg_common_install() {
...
@@ -95,4 +95,82 @@ function uw_cfg_common_install() {
],
],
];
];
UwPermissions
::
grantRevoke
(
$permissions_to_process
,
'grant'
);
UwPermissions
::
grantRevoke
(
$permissions_to_process
,
'grant'
);
// Add terms to the vocabulary 'uw_vocab_audience'.
$terms
=
[
'Current students'
=>
[
'Current undergraduate students'
,
'Current graduate students'
,
],
'Future students'
=>
[
'Future undergraduate students'
,
'Future graduate students'
,
],
'Faculty'
,
'Staff'
,
'Alumni'
,
'Parents'
,
'Donors | Friends | Supporters'
,
'Employers'
,
'International'
,
'Media'
,
];
$weight
=
0
;
foreach
(
$terms
as
$key
=>
$term
)
{
if
(
is_array
(
$term
))
{
$parent
=
_uw_cfg_common_create_term
(
$key
,
'uw_vocab_audience'
,
$weight
,
[]);
foreach
(
$term
as
$child
)
{
_uw_cfg_common_create_term
(
$child
,
'uw_vocab_audience'
,
$weight
,
[
$parent
]);
}
}
else
{
_uw_cfg_common_create_term
(
$term
,
'uw_vocab_audience'
,
$weight
,
[]);
}
$weight
++
;
}
}
/**
* @file
* Contains various helper functions.
*/
/**
* Helper function to create a taxonomy term programmatically.
*
* @code
* // Create top level term
* $term_id = _nodemaker_term_create('My Term', 'my_vocab', 0, []);
*
* // Create term with parent term with an id of 999
* $term_id = _nodemaker_term_create('My Term', 'my_vocab', 0, [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_cfg_common_create_term
(
$taxonomy_name
,
$vocab_machine_name
,
$weight
,
array
$parent_tid
=
[])
{
// Create the taxonomy term.
$new_term
=
Drupal\taxonomy\Entity\Term
::
create
([
'name'
=>
$taxonomy_name
,
'vid'
=>
$vocab_machine_name
,
'parent'
=>
$parent_tid
,
'weight'
=>
$weight
,
]);
// Save the taxonomy term.
$new_term
->
save
();
// Return the taxonomy term id.
return
$new_term
->
id
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment