(Retiré) Utilisez une ID dans un champ utilisateur personnalisé pour faire le lien vers le profil externe d'un utilisateur

Also today I realized that the User Profile page actually displays the custom field as it should, although compared to the user card, now the custom field (Website) is displayed last instead of first…

Capture

1 « J'aime »

I feel like I’ve seen a discussion of this, but I can’t find it now.

I’ve got a custom profile field that holds a user’s website implemented using this tutorial, but allowing for any external site to be entered, rather than just linking to Twitter or something. The problem I have is that about 80% of the users don’t bother to put “http(s)://” in front of the URL they enter. They (rightly) expect that “www.example.com” should just work. So how do I make it just work?

Edited to add: Figured it out. Below is the entire if block of javascript I used to determine whether to attempt to show an external link. The inner if is what determines whether the external URL needs to have “http” added to it, and takes care of doing it.

    if (userFields && userFields[churchURLFieldId]) {
      const rawChurchURL = userFields[churchURLFieldId];
      var url = rawChurchURL;
      if (!/^https?:\/\//i.test(rawChurchURL)) {
        url = 'http://' + rawChurchURL;
      }
      const link = "<a href='"+url+"' target='_blank'>"+userFields[churchNameFieldId];+"</a>";
      return Ember.Object.create({ link, name: churchURL.get('name') });
    } else {
      return null;
    }
1 « J'aime »

Is there a way to edit existing user profile fields rather than adding new one? So that the existing twitter field value can be edited to contain anchor tag

the main post that allows us to add new clickable profile fields using connectors/handlebar outlets etc, those get “added” and so I had to hide the existing profile fields
e.g. I could add a clickable twitter field and so have to hide the existing twitter field
Now the newly added twitter field will be in a separate div rather than belonging to that same ember div which was pre-existing, resulting in weird css

Would using /connectors/user-profile-public-fields/Twitter instead of using /connectors/user-profile-primary/ help here?

This is very nice, i forked it and tried to make it a bit more general as a theme component without the Namati specific stuff. Hope you don’t mind!

Added a separate post as well to make it easier to find for others:

2 « J'aime »

Hi all, just wanted to share that I made a very basic plugin version of this. It just lets you specify which user field to make into a link, and—optionally—a prefix (e.g. https://mysite.com/users/). Just thought I’d share in case anyone would rather install a theme component instead of modify code. It’s based on the code in the original post in this thread.

On a side note, for my particular use case, I don’t want any user to be able to edit it; rather, I plan to update it via the discourse API. In that case, would a “custom field” be better than a “user field”? I see both in the API, but custom_fields are blank.

7 « J'aime »

@wilson29thid accepterais-tu de créer un sujet de #thème pour ce composant ? Ce serait formidable d’avoir cela comme composant de thème installable plutôt que de demander aux gens de copier/coller le code à chaque fois.

5 « J'aime »

Bien sûr - la création d’un sujet ici avec cette balise le rend-elle installable ?

1 « J'aime »

Il est déjà installable via l’URL git. La création d’un sujet aidera simplement les gens à le trouver plus facilement.

1 « J'aime »

Question légèrement différente. Je souhaite ajouter un lien qui s’ouvre dans une nouvelle fenêtre dans la description d’un champ utilisateur sur la page d’inscription. Cette page ne reconnaît pas les liens enveloppés dans [ceci](format).

Je veux que les utilisateurs acceptent avoir lu nos valeurs communautaires avant de s’inscrire, et avoir un lien ici les aidera s’ils les ont manquées. Pour l’instant, je leur ai juste dit de copier/coller le lien complet dans leur navigateur.

Comment cela fonctionne-t-il avec Discourse 3.2 et Ember 5 ?

J’ai mis à jour la version : \u003cscript type=\"text/discourse-plugin\" version=\"1.13.0\"\u003e et j’ai remplacé api.registerConnectorClass par api.renderInOutlet comme suggéré ici mais j’obtiens dans la console du navigateur : [THEME 27] Error: klass is not an Ember component

J’ai remplacé property par computed comme suggéré ici mais j’obtiens dans la console du navigateur : [THEME 27] ReferenceError: computed is not defined

Oh, j’ai oublié l’importation, j’ai donc ajouté le import EmberObject, { computed } from '@ember/object'; manquant après la balise script d’ouverture, mais cela entraîne une SyntaxError : « /discourse/theme-27/discourse/initializers/theme-field-140-common-html-script-3 : ‘import’ et ‘export’ ne peuvent apparaître qu’au niveau supérieur.

1 « J'aime »

Hmm ouais, les techniques suggérées dans le post original sont assez dépassées (ce qui est logique, étant donné qu’il a été écrit en 2016 :sweat_smile:).

De nos jours, ce genre de chose devrait être empaqueté dans un dépôt git et publié en tant que Theme component pour que les gens puissent l’installer et le configurer via les paramètres.

2 « J'aime »

J’ai fini par retravailler le TC de @wilson29thid ici bien qu’il ait toujours un avertissement de dépréciation que je dois corriger à un moment donné.

1 « J'aime »

Cette fonctionnalité de l’OP se trouve désormais dans un nouveau mini composant :