Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test 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 9447 to 9462

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 17th November 2024 15:35 Europe/London time based on the source file dated 15th November 2024 18:30 Europe/London time.