Collections functions
General functions
Render functions
Theme permission functions
User functions
Resource functions

prepareTags()

Description

Utility function which allows annotation tags to be prepared (i.e make sure they are all valid nodes)
before creating associations between annotations and tags


IMPORTANT: a tag should have the same structure as a node

Parameters

ColumnTypeDefaultDescription
$dirty_tags array Original array of tags. These can be (in)valid tags/ new tags.

Return

array

Location

include/annotation_functions.php lines 508 to 581

Definition

 
function prepareTags(array $dirty_tags)
    {
    if(
=== count($dirty_tags))
        {
        return array();
        }

    global 
$annotate_fields;

    
$clean_tags = array();

    foreach(
$dirty_tags as $dirty_tag)
        {
        
// Check minimum required information for a node
        
if(!isset($dirty_tag['resource_type_field'])
            || 
>= $dirty_tag['resource_type_field']
            || !
in_array($dirty_tag['resource_type_field'], $annotate_fields)
        )
            {
            continue;
            }

        if((!isset(
$dirty_tag['name']) || '' == $dirty_tag['name']))
            {
            continue;
            }

        
// No access to field? Next...
        
if(!metadata_field_view_access($dirty_tag['resource_type_field']))
            {
            continue;
            }

        
// New node?
        
if(is_null($dirty_tag['ref']) || (is_string($dirty_tag['ref']) && '' == $dirty_tag['ref']))
            {
            
$dirty_field_data get_resource_type_field($dirty_tag['resource_type_field']);

            
// Only dynamic keywords lists are allowed to create new options from annotations if permission allows it
            
if(
                !(
                    
FIELD_TYPE_DYNAMIC_KEYWORDS_LIST == $dirty_field_data['type'
                    && !
checkperm("bdk{$dirty_tag['resource_type_field']}")
                )
            )
                {
                continue;
                }

            
// Create new node but avoid duplicates
            
$new_node_id set_node(null$dirty_tag['resource_type_field'], $dirty_tag['name'], nullnull);
            if(
false !== $new_node_id && is_numeric($new_node_id))
                {
                
$dirty_tag['ref'] = $new_node_id;

                
$clean_tags[] = $dirty_tag;
                }

            continue;
            }

        
// Existing tags
        
$found_node = array();
        if(
get_node((int) $dirty_tag['ref'], $found_node))
            {
            if(
$found_node['resource_type_field'] == $dirty_tag['resource_type_field'])
                {
                
$clean_tags[] = $found_node;
                }
            }
        }

    return 
$clean_tags;
    }

This article was last updated 2nd December 2023 08:35 Europe/London time based on the source file dated 13th March 2023 14:05 Europe/London time.