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

apply_resource_default()

Description

When changing resource type, new resource type specific fields may become available. This function will apply any resource default
values for resource type specific fields that were not previously available (i.e. not containing user data). This is used by upload
then edit mode after switching resource types and also when locking the resource type with save and next.

Parameters

ColumnTypeDefaultDescription
$old_resource_type int Original resource type.
$new_resource_type int Resource type being switched to.
$resource int array_columnget_resource_type_fields$old_resource_type Resource id.
$fields_for_old_resource_type;

Return

void

Location

include/resource_functions.php lines 9323 to 9338

Definition

 
function apply_resource_default(int $old_resource_typeint $new_resource_typeint $resource) : void
    
{
    
$fields_for_old_resource_type array_column(get_resource_type_fields($old_resource_type), 'ref');
    
$fields_for_new_resource_type array_column(get_resource_type_fields($new_resource_type), 'ref');
    
$check_resource_default_fields array_diff($fields_for_new_resource_type$fields_for_old_resource_type);
    if (
count($check_resource_default_fields) > 0)
        {
        global 
$get_resource_data_cache;
        if (isset(
$get_resource_data_cache[$resource]))
            {
            
# update_field() calls get_resource_data() which needs to return the new resource type.
            
unset($get_resource_data_cache[$resource]);
            }
        
set_resource_defaults($resource$check_resource_default_fields);
        }
    }

This article was last updated 29th May 2024 09:05 Europe/London time based on the source file dated 24th May 2024 10:10 Europe/London time.