Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
drupal.org
better_exposed_filters
Commits
18a346f6
Commit
18a346f6
authored
May 16, 2016
by
Mike Keran
Browse files
Adds heirarchcal taxonomy terms to the BEF test install.
parent
500a6db7
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/bef_test_content/bef_test_content.install
0 → 100644
View file @
18a346f6
<?php
/**
* Provides install hooks for the BEF Test Content module.
*/
/**
* Adds terms to the hierarchical vocabulary.
*/
function
bef_test_content_update_7001
()
{
// Set up an example hierarchical terms in the "Location" vocab.
$locations
=
array
(
'United States'
=>
array
(
'California'
=>
array
(
'San Francisco'
,
'San Diego'
,
'Santa Barbara'
,
),
'Oregon'
=>
array
(
'Portland'
,
'Eugene'
,
),
'Washington'
=>
array
(
'Seattle'
,
'Spokane'
,
'Walla Walla'
,
),
),
'Canada'
=>
array
(
'British Columbia'
=>
array
(
'Vancouver'
,
'Victoria'
,
'Whistler'
,
),
'Alberta'
=>
array
(
'Calgary'
,
'Edmonton'
,
'Lake Louise'
,
),
),
'Mexico'
=>
array
(),
);
foreach
(
$locations
as
$country
=>
$states
)
{
$country_tid
=
_bef_test_content_add_term
(
$country
);
if
(
$country_tid
&&
!
empty
(
$states
))
{
foreach
(
$states
as
$state
=>
$cities
)
{
$state_tid
=
_bef_test_content_add_term
(
$state
,
$country_tid
);
if
(
$state_tid
&&
!
empty
(
$cities
))
{
foreach
(
$cities
as
$city
)
{
_bef_test_content_add_term
(
$city
,
$state_tid
);
}
}
}
}
}
}
/**
* Adds a new term to the bef_test-location vocabulary. If a TID is specified
* in $parent, the new term is added as a child of that term.
*
* @param string $name
* The name of the new term.
* @param int $parent
* The (optional) TID of the parent term.
*
* @return int
* TID of the newly created term or 0 on an error.
*/
function
_bef_test_content_add_term
(
$name
,
$parent
=
0
)
{
$term
=
new
stdClass
();
// Features manages to create a vocab machine name that includes illegal
// characters (taxonomy-bef_test-location -- the hyphen is not allowed). So
// we use the VID of the vocab instead.
$term
->
vid
=
2
;
$term
->
parent
=
$parent
;
$term
->
name
=
$name
;
if
(
taxonomy_term_save
(
$term
)
==
SAVED_NEW
)
{
return
$term
->
tid
;
}
return
0
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment