Coding standards
Security in ResourceSpace
Developer reference
Database
Mcp browse functions
Mcp report functions

mcp_field_options()

Description

Page through active options in an authorised vocabulary, optionally under one parent.

Parameters

ColumnTypeDefaultDescription
$args: array

Location

include/mcp_browse_functions.php lines 163 to 190

Definition

 
function mcp_field_options(array $args): array
{
    
$field = $args['field'];
    
$entry = mcp_field_catalogue($args['resource_type'] ?? null)[$field] ?? null;
    if (empty(
$entry['options_available'])) {
        throw new 
DomainException('Field options unavailable.');
    }
    if (!empty(
$args['parent'])) {
        
$node = [];
        if (!
get_node($args['parent'], $node) || !$node['active'] || (int) $node['resource_type_field'] !== $field) {
            throw new 
DomainException('Parent option unavailable.');
        }
    }
    
$nodes = get_nodes(
        
$field,
        empty(
$args['parent']) ? null : $args['parent'],
        
offset: $args['offset'] ?? 0,
        
rows: $args['limit'] ?? 25,
        
name: $args['query'] ?? '',
        
active_only: true,
        
all_parents: !isset($args['parent'])
    );
    
$rows = [];
    foreach (
$nodes as $node) {
        
$rows[] = ['ref' => (int) $node['ref'], 'name' => i18n_get_translated($node['name']), 'parent' => isset($node['parent']) ? (int) $node['parent'] : null];
    }
    return 
mcp_result(['field' => $field, 'options' => $rows]);
}

This article was last updated 3rd December 2026 16:35 Europe/London time based on the source file dated 3rd December 2026 16:30 Europe/London time.