Collections functions
General functions
Render functions
Theme permission functions
Resource functions



Migrate fixed list field data to text field data for a given resource reference. Useful when changing resource type field from a data type
that can contain multiple values such as a dynamic keywords field. This script will concatenate the existing values and leave one remaining
node for the new text field.

- additional checks maybe need before calling this to ensure the fields are / were of the expected type.
see examples in pages/tools/migrate_fixed_to_text.php
of category tree branches to be preserved e.g. "level1/value, level2/value"


$resource_type_field mixed Resource type field id. ** The field type should have been changed to a text type in advance
$resource mixed Resource reference to be processed.
$category_tree mixed Was the field data being migrated previously of type category tree? Specifying true will allow the format
$separator mixed ' Default is comma and space e.g. "value1, value2"
: ' get_resource_nodes$resource


bool True on success else false.


include/node_functions.php lines 2756 to 2781


function migrate_fixed_to_text(int $resource_type_fieldint $resourcebool $category_treestring $separator ', ') : bool
$current_nodes get_resource_nodes($resource$resource_type_fieldtrueSORT_ASC); # Ordering will be as displayed on the view page.

if (count($current_nodes) < 2)
true# No need to make changes as no node / only one node present.

    if (
$all_treenodes get_cattree_nodes_ordered($resource_type_field$resourcefalse);
$treenodenames get_cattree_node_strings($all_treenodestrue);
$new_value implode($separator$treenodenames);
$current_nodes_names array_column($current_nodes'name');
$current_nodes_translated array_map("i18n_get_translated"$current_nodes_names);
$new_value implode($separator$current_nodes_translated);

delete_resource_nodes($resourcearray_column($current_nodes'ref'), false);
$savenode set_node(NULL$resource_type_field$new_valueNULL0);
add_resource_nodes($resource, [$savenode], truefalse);

This article was last updated 9th June 2023 19:35 Europe/London time based on the source file dated 26th May 2023 12:45 Europe/London time.