Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

get_valid_custom_fields()

Description

Get collection of valid custom fields. A valid fields has at least the expected field properties

IMPORTANT: these fields are not metadata fields - they are configured through config options such as custom_researchrequest_fields

Parameters

ColumnTypeDefaultDescription
$fields array List of custom fields. Often this will simply be the global configuration option (e.g custom_researchrequest_fields)

Return

array

Location

include/request_functions.php lines 1069 to 1097

Definition

 
function get_valid_custom_fields(array $fields)
    {
    return 
array_filter($fields, function($field)
        {
        global 
$lang$FIXED_LIST_FIELD_TYPES;

        
$expected_field_properties = array("id""title""type""required");
        
$available_properties      array_keys($field);
        
$missing_required_fields   array_diff(
            
$expected_field_properties,
            
array_intersect($expected_field_properties$available_properties));

        if(
count($missing_required_fields) > 0)
            {
            
debug("get_valid_custom_fields: custom field misconfigured. Missing properties: "
                
implode(", "array_values($missing_required_fields)));
            return 
false;
            }

        
// options property required for fixed list fields type
        
if(in_array($field["type"], $FIXED_LIST_FIELD_TYPES) && !array_key_exists("options"$field))
            {
            
debug("get_valid_custom_fields: custom fixed list field misconfigured. Missing the 'options' property!");
            return 
false;
            }

        return 
true;
        });
    }

This article was last updated 30th November 2020 13:35 Europe/London time based on the source file dated 28th September 2020 10:05 Europe/London time.