HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Pre-populating recipients for Private Messages
For composing new messages, is it possible to pre-populate the "To" field with a couple of existing users?
0
Comments
After a little digging, I've found a solution for anyone who are facing the same requirement.
Override the
New Message
view by copying theapplication/conversations/views/messages/add.php
file to your theme.add a
value
property to theTo
textBox with the usernames (separated by commas, no spaces) that you want to pre-populate the recipients field with:echo wrap($this->Form->textBox('To', ['MultiLine' => true, 'class' => 'MultiComplete', 'value' => 'username1,username2']), 'div', ['class' => 'TextBoxWrapper']);
That's it! Hope this helps someone out someday.
Always great to see that someone finds his solutions himself.
I was curious if there is a way to do this without extra effort, but the code doesn't allow multiple recipients.
If you already have a custom theme you might be interested to see a solution that doesn't require a view override. Though view overrides are quite comfortable at first sight, they need much more attention during updates.
Moreover your solution isn't flexible: you always have to hardcode the list of users.
If you want to, create a themehooks file and add this code:
Then you will be able to do something like
example.com/message/add/user1/subject?to[]=user2&to[]=user3&to[]=user4
. You can certainly doexample.com/message/add?to[]=user11&to[]=user12
, too.Thanks @R_J.
I'm trying your method (which is a lot better for sure) and have created a themehooks file. However it doesn't seem to be working. I might have done it wrong (sorry this is my first vanillaforums implementation).
I've created the file
class.themehooks.php
to the root of my theme folder (/themes/mytheme/class.themehooks.php
). As instructed in the theme hooks docs, I've declared aMyThemeNameThemeHooks
class using the documented example. The hook doesn't seem to be working as the Respond button that's supposed to be created in the Discussion pages isn't there (discussionController_afterDiscussionTitle_handler
).Did I miss any step? Can you please help?
If you add a themehooks file to an existing theme, I think you have to manually delete the theme-related files in the /cache folder.
Vanilla caches the info about a theme. You can check this by looking at
/cache/theme/name-of-your-theme.php
. This files holds an info about possible themehook files and if there is no file/class referenced here,a) the cached file needs to be deleted so that the theme info gets updated
b) or if a) wasn't successful, your file is malformed, due to the place where it is saved, the name you have chosen for that file or the PHP class name that is defined inside the file.
@R_J Thank you that worked.
Do you know how I can set the placeholder attribute value of a field in the themehooks file? I looked in the forms class file and tried setData and setModel but no go.
Attributes are passed with an array when you create a new form element:
$sender->Form->textBox('YourTextBox', ['placeholder' => t('Some text, made translatable by using the t() function')]);
But it sounds as if you would like to add a placeholder to an existing form element. I do not know how that can be achieved.