Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video 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 844 to 898

Definition

 
function node_field_options_override(&$field,$resource_type_field=null)
    {
    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'] == 7)        // 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 25th November 2020 04:05 Europe/London time based on the source file dated 13th November 2020 16:50 Europe/London time.