Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

How to display profileextender plugin fields ?

I added new fields with profileextender addon but I do not see how to display thoses fields in discussions.

Comments

  • Only works for the profile .... which is why it's called Profile Extender. It adds fields such as school , or occupation and shows up in the user profile.

  • But here there is a handler to display the fields in discussion
    So it might be possible here.

  • migswdmigswd New
    edited September 2017

    I found this way.

        /**
         * Add 'Flag' link for discussions.
         */
        public function discussionController_afterDiscussionMeta_handler($Sender, $Args) {
    
            // Get user-specific data
            $ProfileFields = Gdn::userModel()->getMeta($Sender->Discussion->InsertUserID, 'Profile.%', 'Profile.');
            // TEST : echo $Sender->Discussion->InsertUserID;
    
            //echo ' <dt class="ProfileExtend Profile'.'societe'.'">'.'Société : '.'</dt> ';
            //echo ' <dd class="ProfileExtend Profile'.'societe'.'">'.$ProfileFields['societe'].'</dd>'.'<br>';
            echo '<span class="ProfileExtend Profilesociete">'.$ProfileFields['societe'].'</span>';
            echo '<span class="ProfileExtend Profileregion">'.$ProfileFields['region'].'</span>';
            echo '<span class="ProfileExtend ProfileMandats">'.$ProfileFields['Mandats'].'</span>';
            echo '<span class="ProfileExtend Profilspecialites">'.$ProfileFields['specialites'].'</span>';
        }
    

    Now I just need the same but for the comments in the discussion.
    I need to find the userid for a comment.

    What is the handler I should use ? This one ?
    public function discussionController_insideCommentMeta_handler($Sender, $Args) {

  • If you know the name of the field, it is relatively easy:

        public function discussionController_authorInfo_handler($sender, $args) {
            // Get all fields, if you need more than one:
            $allFields = Gdn::userModel()->getMeta( // From table UserMeta...
                $args['Author']->UserID, // ... for this UserID...
                'Profile.%', // ... get all fields beginning with "Profile."...
                'Profile.' // ...and strip the beginning "Profile." from the result
            );
            echo '<span class="MItem SomeDescriptiveClassName">'.$allFields['PhoneNumber'].'</span>';
            echo '<span class="MItem SomeDescriptiveClassName">'.$allFields['Whatever'].'</span>';
    
    
            // Alternative, if you need only one field:
            $someField = Gdn::userModel()->getMeta(
                $args['Author']->UserID,
                'Profile.Whatever',
                'Profile.',
                'This is a default value if the field is not set for this user'
            );
            echo '<span class="MItem SomeDescriptiveClassName">'.$someField['Whatever'].'</span>';
        }
    

    You can find the name of the field in the config. As you can see in the following example, it is not necesseraly equal to the label that you have used in the ProfileExtender settings!

    $Configuration['ProfileExtender']['Fields']['PhoneNumber']['FormType'] = 'TextBox';
    $Configuration['ProfileExtender']['Fields']['PhoneNumber']['Label'] = 'Phone Number';
    $Configuration['ProfileExtender']['Fields']['PhoneNumber']['Options'] = '';
    $Configuration['ProfileExtender']['Fields']['PhoneNumber']['Required'] = '1';
    $Configuration['ProfileExtender']['Fields']['PhoneNumber']['OnRegister'] = '1';
    $Configuration['ProfileExtender']['Fields']['PhoneNumber']['OnProfile'] = false;
    
  • And if you want to show that info not only in discussions but also on the recent discussion list, you should better start with public function base_authorInfo_handler($sender, $args) {

  • Sorry, I haven't seen that you already found a way.

  • Thank you so much R_J !! Works great !!! :)

Sign In or Register to comment.