Notwithstanding any law to the contrary, law enforcement officers of cities and incorporated towns shall not be prohibited from engaging in political activities except when on duty, when in uniform, or when acting in an official capacity, nor shall they be denied the right to refrain from engaging in political activities.