Hi, Is it possible to allow anonymous users to write a new message only to users with a specific role? And if it's possible, how can I add a custom field to display in the "create new message" page only for anonymous users?
For example if the user is anonymous he should be able to write only to users that have the "support" role, but if an anonymous user wants to write a message to the support he must specify his e-mail address.

Thank you!

Comments

saurabh.dhariwal’s picture

You can set this configuration from Private message settings: admin/config/messaging/privatemsg/block

You require that anonymous user can send only message to support role this functionality can achieve with for alter with below code.

 global $user;
        $form['privatemsg']['recipient']['#default_value'] = 
                ""; // set your role here
        $form['recipient']['#default_value'] = ""; // set your role here

        // Check if a default value is configured for the to field.
        if (!empty($form['privatemsg']['recipient']['#default_value'])) {
                // Display a visible markup element.
                $form['privatemsg']['recipient_display'] = array(
                 '#value' => t('To: @recipients', 
                                                array('@recipients' => 
                                                          $form['privatemsg']['recipient']['#default_value'])),
                  '#weight' => -10,
                );

                // Convert the recipient field to a value type and force the default                                 value.
                $form['privatemsg']['recipient']['#type'] = 'value';
                $form['privatemsg']['recipient']['#value'] =
                        $form['privatemsg']['recipient']['#default_value'];
        }

        // Check if a default value is configured for the to field.
        if (!empty($form['recipient']['#default_value'])) {
                // Display a visible markup element.
                $form['recipient_display'] = array(
                  '#value' => t('To: @recipients', 
                                                        array('@recipients' => $form['recipient']['#default_value'])),
                  '#weight' => -10,
                );

                // Convert the recipient field to a value type and force the default value.
                $form['recipient']['#type'] = 'value';
                $form['recipient']['#value'] = $form['recipient']['#default_value'];
        }

Hope this helps!

Thanks!

ivnish’s picture

Status: Active » Closed (outdated)