'Add component declarations to the mobile form
@return: a dict with component declarations for the resource'

def components(self):

    resource = self.resource
    tablename = resource.tablename
    pkey = resource._id.name
    options = self.config.get('options')
    components = {}
    aliases = (options.get('components') if options else None)
    if aliases:
        hooks = current.s3db.get_components(tablename, names=aliases)
        for (alias, hook) in hooks.items():
            if (hook.linktable or (hook.pkey != pkey)):
                continue
            components[alias] = {'resource': hook.tablename, 'joinby': hook.fkey, 'multiple': hook.multiple}
    ftable = current.s3db.s3_field
    ttable = current.s3db.s3_table
    join = ttable.on((ttable.id == ftable.table_id))
    query = (((ftable.component_key == True) & (ftable.master == tablename)) & (ftable.deleted == False))
    rows = current.db(query).select(ftable.name, ftable.component_alias, ftable.settings, ttable.name, join=join)
    for row in rows:
        component_key = row.s3_field
        settings = component_key.settings
        if ((not settings) or (settings.get('mobile_component') is not False)):
            alias = component_key.component_alias
            multiple = settings.get('multiple', True)
            components[alias] = {'resource': row.s3_table.name, 'joinby': component_key.name, 'multiple': multiple}
    return components
