'Return a folder hierarchy containing datatypes.'

def build_datatypes_folder(self, folder_id, datatypes, label='Datatypes'):

    if datatypes:
        datatype_id = 0
        folder_id += 1
        datatypes_root_folder = Folder(id=folder_id, key='root', label='root', parent=None)
        folder_id += 1
        folder = Folder(id=folder_id, key='datatypes', label=label, parent=datatypes_root_folder)
        datatypes_root_folder.folders.append(folder)
        datatype_id += 1
        datatype = Datatype(id=datatype_id, extension='extension', type='type', mimetype='mimetype', subclass='subclass')
        folder.datatypes.append(datatype)
        for datatypes_dict in datatypes:
            converters = datatypes_dict.get('converters', None)
            if converters:
                num_converters = len(converters)
            else:
                num_converters = 0
            display_app_containers = datatypes_dict.get('display_app_containers', None)
            if display_app_containers:
                num_display_app_containers = len(display_app_containers)
            else:
                num_display_app_containers = 0
            datatype_id += 1
            try:
                extension = datatypes_dict.get('extension', '')
                type = datatypes_dict.get('dtype', '')
                mimetype = datatypes_dict.get('mimetype', '')
                subclass = datatypes_dict.get('subclass', '')
                converters = num_converters
                display_app_containers = num_display_app_containers
            except Exception as e:
                extension = str(e)
                type = 'unknown'
                mimetype = 'unknown'
                subclass = 'unknown'
                converters = 'unknown'
                display_app_containers = 'unknown'
            datatype = Datatype(id=datatype_id, extension=extension, type=type, mimetype=mimetype, subclass=subclass, converters=converters, display_app_containers=display_app_containers)
            folder.datatypes.append(datatype)
    else:
        datatypes_root_folder = None
    return (folder_id, datatypes_root_folder)
