Mandatory revisions on ligne_comptable + cross-node history page
Every save now forces a new revision, unconditionally: - Form: hide the "Create new revision" checkbox and the log message field (#access = FALSE, not just a default) so submitted values for either can't override them -- Form API discards user input for #access-denied elements and falls back to #default_value. - hook_node_presave(): the same thing enforced for any save that doesn't go through the form (drush scripts, etc.), plus explicitly setting the revision author (current user) and revision timestamp. setNewRevision(TRUE) alone does NOT refresh revision_timestamp -- it carries over the previous revision's value, which would silently mislabel every edit with its predecessor's save time. Verified via a drush test save before/after. - Applies regardless of figli_compta_ledger.skip_validation: that flag is about the répartition-sum check on historical imports, a different concern -- revision history is never exempted. New /lignes/historique page (HistoryController): a single reverse- chronological feed across every ligne_comptable's revisions, gated by the 'view ligne_comptable revisions' permission (granted to all three associate roles). Conceptually a revision of one ligne is a revision of the grand livre as a whole, so this aggregates across nodes rather than reusing Drupal's per-node revision history page. Each row links to that specific revision via core's existing revision-view route. Linked from the /lignes toolbar, shown only when the current user has the permission. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -17,6 +17,7 @@ class DashboardController extends ControllerBase {
|
||||
public function home() {
|
||||
return [
|
||||
'#theme' => 'figli_compta_home',
|
||||
'#can_view_history' => $this->currentUser()->hasPermission('view ligne_comptable revisions'),
|
||||
'#attached' => [
|
||||
'library' => ['figli_compta_ledger/home'],
|
||||
],
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\figli_compta_ledger\Controller;
|
||||
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
* Grand livre history: a single reverse-chronological feed across every
|
||||
* ligne_comptable's revisions, rather than Drupal's default per-node
|
||||
* history page -- a revision of one ligne is, conceptually, a revision of
|
||||
* the grand livre as a whole.
|
||||
*/
|
||||
class HistoryController extends ControllerBase {
|
||||
|
||||
/**
|
||||
* Lists every ligne_comptable revision, most recent change first.
|
||||
*/
|
||||
public function history() {
|
||||
$node_storage = $this->entityTypeManager()->getStorage('node');
|
||||
$date_formatter = \Drupal::service('date.formatter');
|
||||
|
||||
$revision_ids = $this->entityTypeManager()->getStorage('node')->getQuery()
|
||||
->accessCheck(TRUE)
|
||||
->allRevisions()
|
||||
->condition('type', 'ligne_comptable')
|
||||
->sort('revision_timestamp', 'DESC')
|
||||
->pager(50)
|
||||
->execute();
|
||||
|
||||
$rows = [];
|
||||
foreach ($revision_ids as $vid => $nid) {
|
||||
$revision = $node_storage->loadRevision($vid);
|
||||
if (!$revision) {
|
||||
continue;
|
||||
}
|
||||
$author = $revision->getRevisionUser();
|
||||
$rows[] = [
|
||||
$date_formatter->format($revision->getRevisionCreationTime(), 'short'),
|
||||
$author ? $author->getDisplayName() : $this->t('Utilisateur supprimé'),
|
||||
$revision->hasField('field_date_ligne') ? $revision->get('field_date_ligne')->value : '',
|
||||
$revision->label(),
|
||||
$revision->hasField('field_montant_ht') && !$revision->get('field_montant_ht')->isEmpty()
|
||||
? $revision->get('field_montant_ht')->value . ' €'
|
||||
: '',
|
||||
[
|
||||
'data' => [
|
||||
'#type' => 'link',
|
||||
'#title' => $this->t('Voir cette version'),
|
||||
'#url' => Url::fromRoute('entity.node.revision', [
|
||||
'node' => $nid,
|
||||
'node_revision' => $vid,
|
||||
]),
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'table' => [
|
||||
'#type' => 'table',
|
||||
'#header' => [
|
||||
$this->t('Modifié le'),
|
||||
$this->t('Par'),
|
||||
$this->t('Date de la ligne'),
|
||||
$this->t('Ligne'),
|
||||
$this->t('Montant HT'),
|
||||
$this->t('Version'),
|
||||
],
|
||||
'#rows' => $rows,
|
||||
'#empty' => $this->t('Aucune révision.'),
|
||||
'#attributes' => ['class' => ['figli-historique-table']],
|
||||
],
|
||||
'pager' => [
|
||||
'#type' => 'pager',
|
||||
],
|
||||
'#cache' => [
|
||||
'contexts' => ['user.permissions'],
|
||||
'tags' => ['node_list:ligne_comptable'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user