def METHOD_NAME(self) -> None:
    global_stack = self._application.getMachineManager().activeMachine
    # Updates the has_materials metadata flag after switching gcode flavor
    if not global_stack:
        return
    definition = global_stack.getDefinition()
    if definition.getProperty("machine_gcode_flavor", "value") != "UltiGCode" or parseBool(definition.getMetaDataEntry("has_materials", False)):
        # In other words: only continue for the UM2 (extended), but not for the UM2+
        return
    machine_manager = self._application.getMachineManager()
    has_materials = global_stack.getProperty("machine_gcode_flavor", "value") != "UltiGCode"
    if has_materials:
        global_stack.setMetaDataEntry("has_materials", True)
    else:
        # The metadata entry is stored in an ini, and ini files are parsed as strings only.
        # Because any non-empty string evaluates to a boolean True, we have to remove the entry to make it False.
        if "has_materials" in global_stack.getMetaData():
            global_stack.removeMetaDataEntry("has_materials")
    self._updateHasMaterialsInContainerTree()
    # set materials
    machine_node = ContainerTree.getInstance().machines[global_stack.definition.getId()]
    for position, extruder in enumerate(global_stack.extruderList):
        #Find out what material we need to default to.
        approximate_diameter = round(extruder.getProperty("material_diameter", "value"))
        material_node = machine_node.variants[extruder.variant.getName()].preferredMaterial(approximate_diameter)
        machine_manager.setMaterial(str(position), material_node)
    self._application.globalContainerStackChanged.emit()