Drupal Privatemsg Prepopulate получателейPhp

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Drupal Privatemsg Prepopulate получателей

Сообщение Anonymous »

Я предварительно заполняю получателей в модуле Privatemsg, но не могу выяснить, где я ошибаюсь. В формате ...
55 => chris
(uid => username) < /p>

Вот мой код модуля ... < /p >

function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'privatemsg_new') {
global $user;
if (in_array('Venue Manager', $user->roles) || in_array('Couples Page Manager', $user->roles)) {
$form['recipient']['#title'] = 'Choose which of your Couples you would like to message.';
$form['recipient']['#type'] = 'select';
$form['recipient']['#size'] = 1;
$options = couples_page_messages_recipients();
$form['recipient']['#options'] = $options;
array_unshift($form['actions']['submit']['#validate'], 'couples_page_messages_validate');
}
if (in_array('Couples Page Manager', $user->roles)) {
$form['recipient']['#title'] = 'Send a message to your venue.';
}
}
}

function MYMODULE_recipients() {
global $user;
$options = array();
if (in_array('Manager', $user->roles)) {
$result = db_query('SELECT `entity_id` FROM `field_data_field_parent_user` WHERE `field_parent_user_target_id` = :uid', array(':uid' => $user->uid));
if (is_array($result) || is_object($result)) {
foreach ($result as $record) {
$child = user_load($record->entity_id);
$childlist[$child->name] = $child->name;
}
}
}
if (in_array('Page Manager', $user->roles)) {
$result = db_query('SELECT `field_parent_user_target_id` FROM `field_data_field_parent_user` WHERE `entity_id` = :uid', array(':uid' => $user->uid));
if (is_array($result) || is_object($result)) {
foreach ($result as $record) {
$child = user_load($record->field_parent_user_target_id);
$childlist[$child->name] = $child->name;
}
}
}
return $childlist;
}

function MYMODULE_validate($form, &$form_state) {
$recipients = $form_state['values']['recipient'];
$usernames = array();
foreach ($recipients as $recipient) {
$user = user_load((int) $recipient);
$usernames[] = $user->name;
}
$form_state['values']['recipient'] = implode(', ', $usernames);
}
< /code>

Форма загружается ОК, вы выбираете пользователя из выпадающих вниз, заполняете сообщение и нажмите «Отправить», а затем показывает следующая ошибка ... < /p>


Предупреждение: неверный аргумент, предоставленный для Foreach () в
mymodule_validate () (строка 60 из
/example.com/sites/all/modules/custom/mymodule/mymodule.module). Вы
должны включать хотя бы один действительный получатель. >
Если я добавляю dsm ($ form_state) в функцию проверки, я вижу, что .. < /p>

$form['values']['recipient'] = me@example.com
< /code>

Это означает, что получатель успешно проходит через>

Подробнее здесь: https://stackoverflow.com/questions/394 ... recipients
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»