You are here

function editor_note_save in Editor Notes 7

Saves note.

Parameters

string|array $note: The text of the note | note array.

string $entity_type: The type of the entity.

object $entity: The entity object.

string $field_name: The machine field name.

int|string|null $uid: The unique ID of the author.

int|string|null $created: The Unix timestamp of the note creation.

int|string|null $changed: The Unix timestamp of the note update.

3 calls to editor_note_save()
editor_note_add_note in ./editor_note.module
Ajax callback for 'Add note' button in 'editor_note_field_widget_form'.
editor_note_field_insert in ./editor_note.module
Implements hook_field_insert().
editor_note_field_update in ./editor_note.module
Implements hook_field_update().

File

./editor_note.module, line 1014
Main functionality for Editor Notes module.

Code

function editor_note_save($note, $entity_type, $entity, $field_name, $uid = NULL, $created = NULL, $changed = NULL) {
  list($entity_id, $revision_id, $bundle) = entity_extract_ids($entity_type, $entity);
  if (!isset($revision_id)) {
    $revision_id = $entity_id;
  }
  if (!isset($uid)) {
    global $user;
    $uid = $user->uid;
  }
  $field_info = field_info_field($field_name);
  $text_processing = FALSE;
  if (isset($field_info['settings']['text_processing']) && $field_info['settings']['text_processing'] != EDITOR_NOTE_DEFAULT_TEXT_FORMAT) {
    $text_processing = TRUE;
  }
  $editor_note = entity_create('editor_note', array(
    'note' => $text_processing ? $note['value'] : $note,
    'bundle' => $bundle,
    'entity_type' => $entity_type,
    'field_name' => $field_name,
    'entity_id' => $entity_id,
    'revision_id' => $revision_id,
    'uid' => (int) $uid,
    'created' => isset($created) ? $created : REQUEST_TIME,
    'changed' => isset($changed) ? $changed : REQUEST_TIME,
    'text_format' => $text_processing ? $note['format'] : EDITOR_NOTE_DEFAULT_TEXT_FORMAT,
  ));
  entity_save('editor_note', $editor_note);
}