View source
<?php
namespace Drupal\webform_revisions;
use Drupal\webform\WebformSubmissionStorage;
use Drupal\webform\WebformInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\webform_revisions\Controller\WebformRevisionsController;
class WebformRevisionsSubmissionStorage extends WebformSubmissionStorage {
public function getColumns(WebformInterface $webform = NULL, EntityInterface $source_entity = NULL, AccountInterface $account = NULL, $include_elements = TRUE) {
$view_any = $webform && $webform
->access('submission_view_any') ? TRUE : FALSE;
$columns = [];
$columns['serial'] = [
'title' => $this
->t('#'),
];
$columns['sid'] = [
'title' => $this
->t('SID'),
];
$columns['label'] = [
'title' => $this
->t('Submission title'),
'sort' => FALSE,
];
$columns['uuid'] = [
'title' => $this
->t('UUID'),
];
$columns['in_draft'] = [
'title' => $this
->t('In draft'),
];
if (empty($account)) {
$columns['sticky'] = [
'title' => $this
->t('Starred'),
];
$columns['locked'] = [
'title' => $this
->t('Locked'),
];
$columns['notes'] = [
'title' => $this
->t('Notes'),
];
}
$columns['created'] = [
'title' => $this
->t('Created'),
];
$columns['completed'] = [
'title' => $this
->t('Completed'),
];
$columns['changed'] = [
'title' => $this
->t('Changed'),
];
if ($view_any && empty($source_entity)) {
$columns['entity'] = [
'title' => $this
->t('Submitted to'),
'sort' => FALSE,
];
}
if (empty($account)) {
$columns['uid'] = [
'title' => $this
->t('User'),
];
}
if ($view_any && \Drupal::moduleHandler()
->moduleExists('language')) {
$columns['langcode'] = [
'title' => $this
->t('Language'),
];
}
$columns['remote_addr'] = [
'title' => $this
->t('IP address'),
];
if (empty($webform) && empty($source_entity)) {
$columns['webform_id'] = [
'title' => $this
->t('Webform'),
];
$columns['entity'] = [
'title' => $this
->t('Submitted to'),
'sort' => FALSE,
];
}
if ($webform && $include_elements) {
$element_manager = \Drupal::service('plugin.manager.webform.element');
$content_entity_id = $webform
->getContentEntityID();
$revision_ids = $this->database
->query('SELECT revision FROM {config_entity_revisions_revision} WHERE id = :id', [
':id' => $content_entity_id,
])
->fetchCol();
if (!$revision_ids) {
return parent::getColumns($webform, $source_entity, $account, $include_elements);
}
foreach ($revision_ids as $revision_id) {
$revisionController = $revisionsController = WebformRevisionsController::create(\Drupal::getContainer());
$webform = $revisionController
->loadConfigEntityRevision($revision_id, $webform
->id());
$elements = $webform
->getElementsInitializedFlattenedAndHasValue('view');
foreach ($elements as $element) {
$element_plugin = $element_manager
->createInstance($element['#type']);
$element_plugin
->replaceTokens($element, $webform);
$columns += $element_plugin
->getTableColumn($element);
}
}
}
$columns['operations'] = [
'title' => $this
->t('Operations'),
'sort' => FALSE,
];
foreach ($columns as $name => &$column) {
$column['name'] = $name;
$column['format'] = 'value';
}
return $columns;
}
}