function editor_note_get_formatted_notes in Editor Notes 7
Returns formatted notes table.
Parameters
array $field: The field data about an individual field.
array $notes: Array of notes data returned by editor_note_get_notes().
bool $widget: Determines whether to use function in widget along with controls or display it in formatter as just a table without controls.
string|null $edit_path: Path of the edit form where field is used. Fixes pager on ajax refresh.
Return value
array Returns formatted notes ready for rendering.
See also
5 calls to editor_note_get_formatted_notes()
- editor_note_add_note in ./
editor_note.module - Ajax callback for 'Add note' button in 'editor_note_field_widget_form'.
- editor_note_confirm_edit_form_update in ./
editor_note.pages.inc - Submit callback for 'Update' button in 'editor_note_confirm_edit_form'.
- editor_note_confirm_remove_form_remove in ./
editor_note.pages.inc - Submit callback for 'Remove' button in 'editor_note_confirm_remove_form'.
- editor_note_field_formatter_view in ./
editor_note.module - Implements hook_field_formatter_view().
- editor_note_field_widget_form in ./
editor_note.module - Implements hook_field_widget_form().
File
- ./
editor_note.module, line 1173 - Main functionality for Editor Notes module.
Code
function editor_note_get_formatted_notes(array $field, array $notes, $widget = FALSE, $edit_path = NULL) {
$formatted_notes = array(
'#prefix' => '<div id="formatted_notes_' . $field['field_name'] . '">',
'#suffix' => '</div>',
);
if (!empty($notes)) {
$rows = array();
$counter = 0;
$header = array(
array(
'data' => t('Notes'),
'class' => array(
'field-label',
),
),
array(
'data' => t('Updated by'),
'class' => array(
'field-author',
),
),
array(
'data' => t('Changed'),
'class' => array(
'field-changed',
),
),
array(
'data' => t('Created'),
'class' => array(
'field-created',
),
),
);
if ($widget) {
$header[] = array(
'data' => t('Actions'),
'class' => array(
'field-operations',
),
);
}
$field_info = field_info_field($field['field_name']);
$text_processing = isset($field_info['settings']['text_processing']) ? $field_info['settings']['text_processing'] : EDITOR_NOTE_DEFAULT_TEXT_FORMAT;
foreach ($notes as $note_id => $item) {
$author_name = format_username(user_load($item->uid));
$rows[$counter] = array(
'data' => array(
'note' => array(
/*
* Retain line breaks if 'plain_text' processing is selected in field settings.
* Otherwise just filter potentially dangerous content.
*/
'data' => $text_processing == EDITOR_NOTE_DEFAULT_TEXT_FORMAT ? nl2br(check_plain($item->note)) : check_markup($item->note, $item->text_format),
'class' => array(
'note',
),
),
'author' => array(
'uid' => $item->uid,
'data' => user_access('access user profiles') ? l($author_name, 'user/' . $item->uid) : $author_name,
'class' => array(
'author',
),
),
'changed' => array(
'data' => format_date($item->changed, 'short'),
'class' => array(
'changed',
),
),
'created' => array(
'data' => format_date($item->created, 'short'),
'class' => array(
'created',
),
),
),
'class' => array(
drupal_html_class('note-' . $note_id),
),
);
if ($widget) {
$operations = !editor_note_access_crud_operations($field['field_name'], $note_id) ? '' : theme('item_list', array(
'items' => array(
ctools_modal_text_button(t('edit'), 'editor_note/edit/nojs/' . $field['field_name'] . '/' . $note_id, t('Edit the note'), drupal_html_class('ctools-modal-' . $field['field_name'] . '-edit')),
ctools_modal_text_button(t('remove'), 'editor_note/remove/nojs/' . $field['field_name'] . '/' . $note_id, t('Remove the note'), drupal_html_class('ctools-modal-' . $field['field_name'] . '-remove')),
),
));
$rows[$counter]['data']['operations'] = array(
'data' => $operations,
'class' => array(
'operations',
),
);
}
$counter++;
}
$notes_table = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#attributes' => array(
'class' => array(
'field-notes-table',
),
),
);
if ($field['settings']['pager']['enabled']) {
// An optional integer to distinguish between multiple pagers on one page
// in case if 2 fields are present at the same time.
static $page_element = 0;
// Fixes pager on ajax refresh.
// Otherwise pager links point on /system/ajax after ajax refresh.
// @see https://www.drupal.org/node/1181370#comment-6088864
// for more details.
// @see theme_pager_link()
if ($edit_path) {
$_GET['q'] = $edit_path;
}
if ($field['settings']['pager']['pager_below']) {
$formatted_notes['notes_table'] = $notes_table;
$formatted_notes['notes_table_pager'] = array(
'#theme' => 'pager',
'#element' => $page_element,
);
}
else {
$formatted_notes['notes_table_pager'] = array(
'#theme' => 'pager',
'#element' => $page_element,
);
$formatted_notes['notes_table'] = $notes_table;
}
if (module_exists('field_group')) {
// Remember which tab was active after page reload
// when navigating between pager links.
$settings = array(
'editorNoteContainer' => drupal_html_class('edit-' . $field['field_name']),
);
$formatted_notes['notes_table']['#attached']['js'][] = array(
'data' => $settings,
'type' => 'setting',
);
$formatted_notes['notes_table']['#attached']['js'][] = drupal_get_path('module', 'editor_note') . '/js/editor_note.js';
}
$page_element++;
}
else {
$formatted_notes['notes_table'] = $notes_table;
}
}
// Hook is to allow other modules to alter the formatted notes
// before they are rendered.
drupal_alter('editor_note_format_notes', $formatted_notes);
return $formatted_notes;
}