function privatemsg_filter_create_tags in Privatemsg 7
Same name and namespace in other branches
- 6.2 privatemsg_filter/privatemsg_filter.module \privatemsg_filter_create_tags()
- 6 privatemsg_filter/privatemsg_filter.module \privatemsg_filter_create_tags()
- 7.2 privatemsg_filter/privatemsg_filter.module \privatemsg_filter_create_tags()
Function to create a tag
Parameters
$tags A single tag or an array of tags.:
4 calls to privatemsg_filter_create_tags()
- privatemsg_filter_add_tag_submit in privatemsg_filter/
privatemsg_filter.module - Form callback for adding a tag to threads.
- privatemsg_filter_form_submit in privatemsg_filter/
privatemsg_filter.module - Form builder function, display a form to modify tags on a thread.
- privatemsg_rules_tag_thread in privatemsg_rules/
privatemsg_rules.rules.inc - privatemsg_rules_thread_has_tag in privatemsg_rules/
privatemsg_rules.rules.inc - Check if a thread has a specific tag.
File
- privatemsg_filter/
privatemsg_filter.module, line 180 - Allows users to tag private messages and to filter based upon those tags.
Code
function privatemsg_filter_create_tags($tags) {
if (!is_array($tags)) {
$tags = array(
$tags,
);
}
$tag_ids = array();
foreach ($tags as $tag) {
$tag = trim($tag);
if (empty($tag)) {
// Do not save a blank tag.
continue;
}
// Check if the tag already exists and only create the tag if it does not.
$tag_id = db_query("SELECT tag_id FROM {pm_tags} WHERE tag = :tag", array(
':tag' => $tag,
))
->fetchField();
if (empty($tag_id) && privatemsg_user_access('create private message tags')) {
$tag_id = db_insert('pm_tags')
->fields(array(
'tag' => $tag,
))
->execute();
}
elseif (empty($tag_id)) {
// The user does not have permission to create new tags - disregard this tag and move onto the next.
drupal_set_message(t('Tag %tag was ignored because you do not have permission to create new tags.', array(
'%tag' => $tag,
)));
continue;
}
$tag_ids[] = $tag_id;
}
return $tag_ids;
}