def add_object_align_init(context, operator):
    """
    Return a matrix using the operator settings and view context.

    :arg context: The context to use.
    :type context: :class:`bpy.types.Context`
    :arg operator: The operator, checked for location and rotation properties.
    :type operator: :class:`bpy.types.Operator`
    :return: the matrix from the context and settings.
    :rtype: :class:`mathutils.Matrix`
    """
    from mathutils import Matrix, Vector, Euler
    properties = operator.properties if operator is not None else None
    space_data = context.space_data
    if space_data and space_data.type != 'VIEW_3D':
        space_data = None
    if operator and properties.is_property_set('location'):
        location = Matrix.Translation(Vector(properties.location))
    else:
        if space_data:
            location = Matrix.Translation(space_data.cursor_location)
        else:
            location = Matrix.Translation(context.scene.cursor_location)
        if operator:
            properties.location = location.to_translation()
    view_align = context.user_preferences.edit.object_align == 'VIEW'
    view_align_force = False
    if operator:
        if properties.is_property_set('view_align'):
            view_align = view_align_force = operator.view_align
        elif properties.is_property_set('rotation'):
            value = properties.rotation[:]
            properties.view_align = view_align
            properties.rotation = value
            del value
        else:
            properties.view_align = view_align
    if operator and (properties.is_property_set('rotation') and not
        view_align_force):
        rotation = Euler(properties.rotation).to_matrix().to_4x4()
    else:
        if view_align and space_data:
            rotation = space_data.region_3d.view_matrix.to_3x3().inverted()
            rotation.resize_4x4()
        else:
            rotation = Matrix()
        if operator:
            properties.rotation = rotation.to_euler()
    return location * rotation
