/** * Overrides \RestfulDataProviderDbQuery::view(). * * Adds the message HTML to the resource. */ public function mapDbRowToPublicFields($row) { $request = $this->getRequest(); $return = parent::mapDbRowToPublicFields($row); if (!empty($request['html'])) { $message = message_load($row->mid); $output = $message->view('activity_group'); $return['id'] = $row->mid; $return['html'] = drupal_render($output); } return $return; }
$id = drush_get_option('id', 1); // Count how much messages we have. $query = new EntityFieldQuery(); $max = $query->entityCondition('entity_type', 'message')->propertyCondition('mid', $id, '>=')->count()->execute(); $i = 0; while ($max > $i) { // Collect the messages in batches. $query = new EntityFieldQuery(); $result = $query->entityCondition('entity_type', 'message')->propertyCondition('mid', $id, '>=')->propertyOrderBy('mid', 'DESC')->range(0, $batch)->execute(); if (empty($result['message'])) { return; } foreach (array_keys($result['message']) as $mid) { $i++; // Load the message. $message = message_load($mid); $tokens = array('message:field-node-reference:url', 'message:field-node-reference:title'); $save_message = FALSE; foreach ($tokens as $token) { // Check that the token is not hard coded. if (isset($message->arguments['@{' . $token . '}'])) { continue; } $save_message = TRUE; // Creating a hard coded value for the toekn. $token_options = message_get_property_values($message, 'data', 'token options'); $context = array('message' => $message); $message->arguments['@{' . $token . '}'] = token_replace('[' . $token . ']', $context, $token_options); } if ($save_message) { $param = array('@mid' => $mid, '@tokens' => implode(' ', $tokens));
/** * Return message text of partial 1 (long description). * * @param $id * Message Id. * * @return string * Message string after placeholder replacement. */ protected function getLongText($id) { $message = message_load($id); return $message->getText(LANGUAGE_NONE, array('partials' => TRUE, 'partial delta' => 1)); }
/** * @Given /^I update a "([^"]*)" with title "([^"]*)" with new title "([^"]*)" after "([^"]*)"$/ */ public function iUpdateAWithTitleInTheGroupWithNewTitleAfter($type, $title, $new_title, $time) { // Loading node of current content type and with current title. $query = new \entityFieldQuery(); $result = $query->entityCondition('entity_type', 'node')->entityCondition('bundle', strtolower($type))->propertyCondition('title', $title)->propertyCondition('status', NODE_PUBLISHED)->range(0, 1)->execute(); if (empty($result['node'])) { $params = array('@title' => $title, '@type' => $type); throw new \Exception(format_string("Node @title of @type not found.", $params)); } $nid = key($result['node']); // Loading the previous message for the current node. $query = new \EntityFieldQuery(); $result = $query->entityCondition('entity_type', 'message')->propertyCondition('type', 'c4m_insert__node__' . $type)->fieldCondition('field_node', 'target_id', $nid)->propertyOrderBy('timestamp', 'desc')->range(0, 1)->execute(); if (empty($result['message'])) { throw new \Exception(format_string("Previous message not found.")); } $id = key($result['message']); $message = message_load($id); // Changing timestamp of the previous message to earlier (minus current time). $message->timestamp = strtotime('now - ' . $time); $message->save(); $node = node_load($nid); // Changing the current node title. $node->title = $new_title; node_save($node); }