function _taxonomy_patterns_prepare_term in Patterns 7
Same name and namespace in other branches
- 7.2 patterns_components/components/taxonomy.inc \_taxonomy_patterns_prepare_term()
1 call to _taxonomy_patterns_prepare_term()
- taxonomy_patterns_prepare in patterns_components/
components/ taxonomy.inc
File
- patterns_components/
components/ taxonomy.inc, line 272 - Patterns component for taxonomy vocabularies and terms.
Code
function _taxonomy_patterns_prepare_term($action, $data, $vid = NULL) {
// Get the vid first
if (isset($data['vocabulary'])) {
$data['vocabulary_machine_name'] = $data['vocabulary'];
unset($data['vocabulary']);
}
// Set the vocabulary-id if not alraeady present
if (!isset($data['vid'])) {
// use the parameter if not null
if (!empty($vid)) {
$data['vid'] = $vid;
}
else {
$taxo = taxonomy_vocabulary_machine_name_load($data['vocabulary_machine_name']);
$data['vid'] = $taxo->vid;
}
}
if (!isset($data['tid'])) {
if (isset($data['name'])) {
// TODO: Check this
$terms = taxonomy_get_term_by_name($data['name']);
// We set it only if there is one and only term with the same name.
if (count($terms) == 1) {
$term = array_pop($terms);
$data['tid'] = $term->tid;
}
}
}
if (isset($data['parent'])) {
$data['parent'] = _taxonomy_patterns_prepare_parent_terms($data['parent']);
}
//return 'taxonomy_form_term';
if (isset($data['delete'])) {
// TODO: action === 'delete'
$data['confirm_delete'] = TRUE;
}
else {
// If it was not a delete request do a lot more
$default_weight = 0;
$default_textformat = 'filtered_html';
if (!isset($data['format'])) {
$data['format'] = $default_textformat;
// was ''
}
if (!isset($data['weight'])) {
$data['weight'] = $default_weight;
}
// @TODO: Check 'tid' => NULL,
if (isset($data['descr'])) {
$data['description']['value'] = $data['descr'];
if (isset($data['descr-format'])) {
$data['description']['format'] = $data['descr-format'];
unset($data['descr-format']);
}
else {
$data['description']['format'] = $default_textformat;
}
unset($data['descr']);
}
}
// End Not Delete
return $data;
}