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

node_field_options_override()

Description

Overrides either a field[options] array structure or a flat option array with values derived from nodes.
If a field, then will also add field=>nodes[] sub array ready for field rendering.

Parameters

ColumnTypeDefaultDescription
&$field
$resource_type_field integer null ID of the metadata field, if specified will treat as flat options list
$field mixed Either field array structure or flat options list array

Return

boolean

Location

include/node_functions.php lines 955 to 1014

Definition

 
function node_field_options_override(&$field,$resource_type_field=null)
    {
    global 
$FIXED_LIST_FIELD_TYPES;
    if(isset(
$field["type"]) && !in_array($field["type"],$FIXED_LIST_FIELD_TYPES))
        {
        return 
false;
        }
    if (!
is_null($resource_type_field))     // we are dealing with a single specified resource type so simply return array of options
        
{
        
$options get_nodes($resource_type_field);
        if(
count($options) > 0)     // only override if field options found within nodes
            
{
            
$field = array();
            foreach (
$options as $option)
                {
                
array_push($field,$option['name']);
                }
            }
        return 
true;
        }

    if (
        !isset(
$field['ref']) ||
        !isset(
$field['type']) ||
        !
in_array($field['type'], array(237912))
    )
        {
        return 
false;       // get out of here if not a node supported field type
        
}

    
migrate_resource_type_field_check($field);

    
$field['nodes'] = array();          // setup new nodes associate array to be used by node-aware field renderers
    
$field['node_options'] = array();   // setup new node options list for render of flat fields such as drop down lists (saves another iteration through nodes to grab names)

    
if ($field['type'] == FIELD_TYPE_CATEGORY_TREE)
        {
        
$category_tree_nodes get_nodes($field['ref'], nullfalse);
        if (
count($category_tree_nodes) > 0)
            {
            foreach (
$category_tree_nodes as $node)
                {
                
$field['nodes'][$node['ref']] = $node;
                }
            }
        }
    else        
// normal comma separated options used for checkboxes, selects, etc.
        
{
        
$nodes get_nodes($field['ref'],null,false,null,null,null,null,(bool)$field['automatic_nodes_ordering']);
        if (
count($nodes) > 0)
            {
            foreach (
$nodes as $node)
                {
                
$field['nodes'][$node['ref']]=$node;
                
array_push($field['node_options'],$node['name']);
                }
            }
        }
    return 
true;
    }

This article was last updated 19th March 2024 10:05 Europe/London time based on the source file dated 15th March 2024 17:00 Europe/London time.