code: def get_fields_with_visibility(self, visibility="edit", mode="add"):
          
          fields = self.get_sorted_fields()
  
          out = []
  
          for field in fields:
              v = field.widget.isVisible(
                  self.context, mode, default='invisible', field=field)
  
              if self.is_field_visible(field) is False:
                  v = "hidden"
  
              visibility_guard = True
              # visibility_guard is a widget field defined in the schema in order
              # to know the visibility of the widget when the field is related to
              # a dynamically changing content such as workflows. For instance
              # those fields related to the workflow will be displayed only if
              # the workflow is enabled, otherwise they should not be shown.
              if 'visibility_guard' in dir(field.widget):
                  visibility_guard = eval(field.widget.visibility_guard)
              if v == visibility and visibility_guard:
                  out.append(field)
  
          return out
docs: Return the fields with visibility