tft_archive.pages.inc in Taxonomy File Tree 7.2
Page and form callbacks.
File
modules/tft_archive/includes/tft_archive.pages.incView source
<?php
/**
* @file
* Page and form callbacks.
*/
/**
* Page callback: restore element.
*/
function tft_archive_restore_element($id, $type) {
$tid = tft_archive_restore_archived_element($id, $type);
if (!$tid) {
$term = t("Root");
}
else {
$term = taxonomy_term_load($tid);
$term = $term->name;
}
$url = explode('%23', $_GET['destination']);
drupal_set_message(t("The element was restored to <a href='!link'>%term</a>.", array(
'!link' => url($url, array(
'fragment' => "tft/{$tid}",
)),
'%term' => $term,
)));
if (isset($_GET['destination'])) {
drupal_goto($_GET['destination']);
}
else {
drupal_goto();
}
}
/**
* Form callback: archive a term form.
*/
function tft_archive_term_form($form, $form_state, $tid) {
$redirect = FALSE;
if (!tft_term_access($tid)) {
drupal_set_message(t("You do not have access to this folder. You cannot edit or delete it."), 'error');
$redirect = TRUE;
}
elseif (tft_archive_is_archive_folder($tid)) {
drupal_set_message(t("Archive folders cannot be archived."), 'error');
$redirect = TRUE;
}
$name = db_query("SELECT name FROM {taxonomy_term_data} WHERE tid = :tid", array(
':tid' => $tid,
))
->fetchField();
if (!$name) {
drupal_set_message(t("An error occured. The '@tid' folder could not be found. Please contact the site administrator.", array(
'@tid' => $tid,
)), 'error');
$redirect = TRUE;
}
if ($redirect) {
if ($destination = str_replace('%23', '#', $_GET['destination'])) {
drupal_goto($destination);
}
else {
drupal_goto();
}
}
drupal_set_title(t("Are you sure you want to archive folder @term ?", array(
'@term' => $name,
)));
$form['tid'] = array(
'#type' => 'hidden',
'#value' => $tid,
);
$form['name'] = array(
'#type' => 'hidden',
'#value' => $name,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t("Archive"),
);
$form['cancel'] = array(
'#markup' => '<a href="/' . str_replace('%23', '#', $_GET['destination']) . '">' . t("cancel") . '</a>',
);
return $form;
}
/**
* Submission callback for tft_archive_term_form().
*/
function tft_archive_term_form_submit($form, $form_state) {
$name = $form_state['values']['name'];
$tid = $form_state['values']['tid'];
$archive_tid = tft_archive_get_closest_parent_archive_tid($tid);
$parent_tid = tft_get_parent_tid($tid);
db_update('taxonomy_term_hierarchy')
->fields(array(
'parent' => $archive_tid,
))
->condition('tid', $form_state['values']['tid'])
->execute();
tft_archive_log($form_state['values']['tid'], 'term', $parent_tid);
drupal_set_message(t("The <em>@term</em> folder was archived.", array(
'@term' => $name,
)));
}
/**
* Form callback: archive a node form.
*/
function tft_archive_file_form($form, $form_state, $nid) {
$node = node_load($nid);
$redirect = FALSE;
if (!node_access('update', $node)) {
drupal_set_message(t("You cannot edit this file."), 'error');
$redirect = TRUE;
}
elseif (empty($node->{"taxonomy_vocabulary_" . variable_get('tft_vocabulary_vid', 0)})) {
drupal_set_message(t("This file is not part of any tree. You cannot archive it."), 'error');
$redirect = TRUE;
}
if ($redirect) {
if ($destination = str_replace('%23', '#', $_GET['destination'])) {
drupal_goto($destination);
}
else {
drupal_goto();
}
}
drupal_set_title(t("Are you sure you want to archive file @title ?", array(
'@title' => $node->title,
)));
$form['#node'] = $node;
$form['name'] = array(
'#type' => 'hidden',
'#value' => $node->title,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t("Archive"),
);
$form['cancel'] = array(
'#markup' => '<a href="/' . str_replace('%23', '#', $_GET['destination']) . '">' . t("cancel") . '</a>',
);
return $form;
}
/**
* Submission callback for tft_archive_term_form().
*/
function tft_archive_file_form_submit($form, $form_state) {
$node = $form['#node'];
$taxonomy = array();
foreach ($node->{"taxonomy_vocabulary_" . variable_get('tft_vocabulary_vid', 0)}[LANGUAGE_NONE] as $item) {
$archive_tid = tft_archive_get_closest_parent_archive_tid($item['tid']);
if ($archive_tid) {
tft_archive_log($node->nid, 'node', $item['tid']);
$taxonomy[] = array(
'tid' => $archive_tid,
);
}
}
$node->{"taxonomy_vocabulary_" . variable_get('tft_vocabulary_vid', 0)}[LANGUAGE_NONE] = $taxonomy;
node_save($node);
drupal_set_message(t("The <em>@title</em> file was archived.", array(
'@title' => $node->title,
)));
}
Functions
Name | Description |
---|---|
tft_archive_file_form | Form callback: archive a node form. |
tft_archive_file_form_submit | Submission callback for tft_archive_term_form(). |
tft_archive_restore_element | Page callback: restore element. |
tft_archive_term_form | Form callback: archive a term form. |
tft_archive_term_form_submit | Submission callback for tft_archive_term_form(). |