getItems(); $Tree = []; foreach ($Items as $Index => $Item) { if ($Item instanceof MetadataField) { $Tree[$Index]["Id"] = $Item->id(); $Tree[$Index]["Label"] = $Item->getDisplayName(); $Tree[$Index]["Children"] = []; $Tree[$Index]["Type"] = TYPE_FIELD; } elseif ($Item instanceof MetadataFieldGroup) { $Tree[$Index]["Id"] = $Item->Id(); $Tree[$Index]["Label"] = $Item->name(); $Tree[$Index]["Children"] = []; foreach ($Item->GetFields() as $Field) { $Tree[$Index]["Children"][] = [ "Label" => $Field->getDisplayName(), "Type" => TYPE_FIELD, "Id" => $Field->id() ]; } $Tree[$Index]["Type"] = TYPE_GROUP; } } return $Tree; } /** * Print all items in order using passed MetadataFieldOrder object * @param MetadataFieldOrder $Order containing items in order to print them * @param string $Type display or edit, depending on which order to display for * @param int $SchemaId id of schema for printing in inputs * @param int $GroupIdOffset offset for group IDs so we know they're groups */ function printOrder( MetadataFieldOrder $Order, string $Type, int $SchemaId, int $GroupIdOffset ): void { # load the javascript we need $AF = ApplicationFramework::getInstance(); $AF->RequireUIFile("jquery-ui.js"); $AF->RequireUIFile("jquery-ui-nestedsortable.js"); $AF->RequireUIFile("MetadataFieldOrdering.js"); $ToPrint = getTree($Order); # exclude all disabled fields $ToPrint = array_filter($ToPrint, __NAMESPACE__."\\fieldOrderFilter"); foreach ($ToPrint as $Index => $Item) { if ($Item["Type"] == TYPE_GROUP) { $ToPrint[$Index]["Children"] = array_filter( $Item["Children"], __NAMESPACE__."\\fieldOrderFilter" ); } } # print all fields & groups using the tree print "
"; printItems($ToPrint, $Type, $SchemaId, $Order->id(), $GroupIdOffset); print "
"; # output the javascript to wire-in the jquery-ui-nestedsortable print "
"; } /** * Print all hidden types * @param array $Types hidden types */ function printHiddenInputs(array $Types): void { foreach ($Types as $Type) { print ""; } } /** * @param array $Items to print, in tree structure * @param string $Type specifying whether this is the list for display or edit * @param int $SchemaId to print in inputs in getGroupButtons() (delete button) * @param int $OrderId id of order, for printing in getGroupButtons() (delete button) * @param int $GroupIdOffset offset for group IDs so we know they're groups */ function printItems( array $Items, string $Type, int $SchemaId, int $OrderId, int $GroupIdOffset ): void { print "

"; foreach ($Items as $Info) { $IsGroup = $Info["Type"] == TYPE_GROUP; $ItemId = ($IsGroup ? $Info["Id"] + $GroupIdOffset : $Info["Id"]); # if isn't a group, add class to specify nesting as not allowed # if is a group, then add pb-2 to pad bottom for buttons (which are a bit tall) # if is a group, bold text, then add buttons. print "
- ". "
  ". ($IsGroup ? "" : "").htmlspecialchars($Info["Label"]).($IsGroup ? "" : ""). ($IsGroup ? getGroupButtons($SchemaId, ($ItemId - $GroupIdOffset), $OrderId) : ""). "
  "; # if is group, print children of group in ul inside of this li if ($IsGroup) { printItems($Info["Children"], $Type, $SchemaId, $ItemId, $GroupIdOffset); } print "
"; } print "

"; } /** * Get the rename and delete buttons for MetadataGroup items * put here so printItems() isn't too cluttered * @return string html buttons to print */ function getGroupButtons(int $SchemaId, int $GroupId, int $OrderId): string { $RenameButton = new HtmlButton("Rename"); $RenameButton->setIcon("Pencil.svg"); $RenameButton->setSize(HtmlButton::SIZE_SMALL); $RenameButton->setLink("index.php?P=RenameMetadataFieldGroup" . "&SchemaId=" . $SchemaId . "&GroupId=" . $GroupId); $DeleteButton = new HtmlButton("Delete"); $DeleteButton->setIcon("Cross.svg"); $DeleteButton->setSize(HtmlButton::SIZE_SMALL); $DeleteButton->addSemanticClass("btn-danger"); $DeleteButton->setValue("DeleteGroup," . $GroupId . "," . $OrderId); $DeleteButton->setTitle("Delete this metadata field group. " . "The metadata field it contains will take its place."); return "" . $RenameButton->getHtml() . " " . $DeleteButton->getHtml() . ""; } /** * Filter callback used to filter fields from display. * @param array $Item item to test for exclusion * @return bool TRUE if the item should be included or FALSE otherwise */ function fieldOrderFilter($Item): bool { $Id = $Item["Id"]; if ($Item["Type"] == TYPE_FIELD) { $Field = MetadataField::getField($Id); if (!$Field->enabled()) { return false; } } return true; } /** * Print an option list containing metadata schemas. * @param MetadataSchema $SchemaInUse Metadata schema in use. */ function PrintSchemaOptionList(MetadataSchema $SchemaInUse): void { $Options = []; # get the metadata schema options foreach (MetadataSchema::GetAllSchemas() as $Schema) { $Options[$Schema->Id()] = $Schema->ResourceName() . " Schema"; } $OptList = new HtmlOptionList("SC", $Options, $SchemaInUse->Id()); $OptList->SubmitOnChange(true); $OptList->PrintHtml(); } # ----- SETUP ---------------------------------------------------------------- $AddButton = new HtmlButton("Add"); $AddButton->setIcon("Plus.svg"); $AddButton->setSize(HtmlButton::SIZE_SMALL); $AddButton->makeSubmitButton(); $SaveButton = new HtmlButton("Save Changes"); $SaveButton->setIcon("Disk.svg"); $SaveButton->makeSubmitButton(); if (!isset($H_Schema)) { throw new \Exception("Variable \$H_Schema not set."); } if (!isset($H_DisplayOrder)) { throw new \Exception("Variable \$H_DisplayOrder not set."); } if (!isset($H_GroupIdOffset)) { throw new \Exception("Variable \$H_GroupIdOffset not set."); } if (!isset($H_EditOrder)) { throw new \Exception("Variable \$H_EditOrder not set."); } $SafeSchemaId = defaulthtmlentities($H_Schema->Id()); # ----- DISPLAY -------------------------------------------------------------- ?>
Changes to field and group ordering saved

Tip: drag metadata fields and groups to reorder them.

The Display Order settings control the ordering on the item display page for that schema (e.g. Full Record for Resources), if that page supports it. The Editing Order settings control the order of fields on the Edit Resource pages.

Collection Administrators may also choose to group like metadata fields together, and have them appear in their own box on the Full Record or Edit Resource pages. To group a set of metadata fields together, type the name of the grouping in the Add Group box, select whether the group belongs in the Display Order (on the Full Record) or Edit Order (on the Edit Resources page), and click the ``Add`` button. The name of the group will appear in the list in bold, and fields can be moved into the group. The name given to these groupings will only appear on the Full Record page (Display Order) if the "Show Group Names In Full Record Page" option is checked in System Configuration. However, on the Edit Resources page (Edit Order) the name does display and the set of fields is collapsible.

## Display Order

Group: getHtml() ?>
Id(), $H_GroupIdOffset ); ?>

## Edit Order

Group: getHtml() ?>
Id(), $H_GroupIdOffset ); ?>
getHtml() ?>