You are here

function message_ui_instance_message_create_submit in Message UI 7

Submit handler - create/edit new message via the UI.

1 string reference to 'message_ui_instance_message_create_submit'
message_ui_instance_message_manage in ./message_ui.module
The UI for creating/editing the message.

File

./message_ui.module, line 747
Main file for the message UI module.

Code

function message_ui_instance_message_create_submit($form, &$form_state) {
  $message = $form_state['#entity'];
  field_attach_submit('message', $message, $form, $form_state);

  // Update the tokens.
  $token_actions = empty($form_state['values']['replace_tokens']) ? array() : $form_state['values']['replace_tokens'];
  if (is_object($message) && !empty($message->arguments)) {
    if (!empty($token_actions) && $token_actions != 'no_update') {
      foreach (array_keys($message->arguments) as $token) {

        // Loop through the arguments of the message.
        if ($token_actions == 'update') {

          // Get the hard coded value of the message and him in the message.
          $token_name = str_replace(array(
            '@{',
            '}',
          ), array(
            '[',
            ']',
          ), $token);
          $value = token_replace($token_name, array(
            'message' => $message,
          ));
        }
        else {

          // Hard coded value given from the user.
          $value = $form_state['values'][$token];
        }
        $message->arguments[$token] = $value;
      }
    }
  }
  $wrapper = entity_metadata_wrapper('message', $message);
  $wrapper->user
    ->set(user_load_by_name($form_state['values']['name']));
  $wrapper->timestamp
    ->set(strtotime($form_state['values']['date']));
  $wrapper
    ->save();
  $form_state['redirect'] = 'message/' . $wrapper
    ->getIdentifier();
}