public function is_editable() {
        global $USER;

        if (!$this->is_visible()) {
            return false;
        }

        if ($this->is_signup_field() && (empty($this->userid) || isguestuser($this->userid))) {
            // Allow editing the field on the signup page.
            return true;
        }

        $systemcontext = context_system::instance();

        if ($this->userid == $USER->id && has_capability('moodle/user:editownprofile', $systemcontext)) {
            return true;
        }

        if (has_capability('moodle/user:update', $systemcontext)) {
            return true;
        }

        return false;
    }