public function EditorNoteHelperService::generateTable in Editor Notes 8
Returns formatted notes table.
Parameters
\Drupal\Core\Field\FieldDefinitionInterface $field: Field definition object.
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
editor_note_get_notes()
1 call to EditorNoteHelperService::generateTable()
- EditorNoteHelperService::getWidgetAjaxReplaceCommand in src/
EditorNoteHelperService.php - Returns ajax replace command for refreshing field widget.
File
- src/
EditorNoteHelperService.php, line 227
Class
- EditorNoteHelperService
- Class EditorNoteHelperService.
Namespace
Drupal\editor_noteCode
public function generateTable(FieldDefinitionInterface $field, array $notes, $widget = FALSE, $edit_path = NULL) {
$formatted_notes = [
'#prefix' => '<div id="formatted_notes_' . $field
->getName() . '">',
'#suffix' => '</div>',
];
if (!empty($notes)) {
$rows = [];
$counter = 0;
$headers = $this
->generateHeaders($widget);
foreach ($notes as $note_id => $item) {
$rows[$counter] = $this
->generateRow($item, $widget, $field
->getName(), $note_id);
$counter++;
}
$notes_table = [
'#theme' => 'table',
'#header' => $headers,
'#rows' => $rows,
'#attributes' => [
'class' => [
'field-notes-table',
],
],
];
if (FALSE) {
// @todo: Implement it.
// 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'] = [
'#theme' => 'pager',
'#element' => $page_element,
];
}
else {
$formatted_notes['notes_table_pager'] = [
'#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 = [
'editorNoteContainer' => drupal_html_class('edit_link-' . $field['field_name']),
];
$formatted_notes['notes_table']['#attached']['js'][] = [
'data' => $settings,
'type' => 'setting',
];
$formatted_notes['notes_table']['#attached']['js'][] = drupal_get_path('module', 'editor_note') . '/js/editor_note.js';
}
$page_element++;
// Not fully implemented pagination flow.
// @see https://www.drupal.org/project/editor_note/issues/3087584
// if (!empty($settings) && $settings['pager_enabled']) {
// if ($settings['pager_below']) {
// $formatted_notes = [
// 'notes_table' => $notes_table,
// 'notes_pager' => [
// '#type' => 'pager',
// ],
// ];
// }
// else {
// $formatted_notes = [
// 'notes_pager' => [
// '#type' => 'pager',
// ],
// 'notes_table' => $notes_table,
// ];
// }
// $formatted_notes['notes_table']['#attached']['library'][] = 'editor_note/editor_note';
// }
}
else {
$formatted_notes['notes_table'] = $notes_table;
}
}
// Hook is to allow other modules to alter the formatted notes
// before they are rendered.
$this->moduleHandler
->alter('editor_note_format_notes', $formatted_notes);
return $formatted_notes;
}