Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
n/a
0 / 0
n/a
0 / 0
n/a
0 / 0
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2
3declare(strict_types=1);
4
5namespace Drupal\display_builder\Entity;
6
7use Drupal\display_builder\Plugin\Field\FieldType\HistoryStep;
8
9/**
10 * History interface.
11 *
12 * When you implement Undo and Redo, you want to keep track of the history
13 * of this state at different points in time.
14 *
15 * Inspired from https://redux.js.org/usage/implementing-undo-history
16 */
17interface HistoryInterface {
18
19  /**
20   * Get current step.
21   *
22   * @return \Drupal\display_builder\Plugin\Field\FieldType\HistoryStep|null
23   *   The current data.
24   */
25  public function getCurrent(): ?HistoryStep;
26
27  /**
28   * Get the state of the current step.
29   *
30   * @return array
31   *   The current state.
32   */
33  public function getCurrentState(): array;
34
35  /**
36   * Set a new present.
37   *
38   * @param array $state
39   *   The state to set.
40   * @param string|\Stringable $log_message
41   *   (Optional) The log message.
42   * @param bool $check_hash
43   *   (Optional) Should check hash to avoid duplicates. Default to TRUE.
44   * @param bool $index
45   *   (Optional) When TRUE the raw $state is normalized through SourceTree
46   *   before storing. Set to FALSE when the data was already produced by
47   *   SourceTree::getTree() to skip redundant normalization. Default to TRUE.
48   */
49  public function setNewPresent(array $state, string|\Stringable $log_message = '', bool $check_hash = TRUE, bool $index = TRUE): void;
50
51  /**
52   * Get the past steps.
53   *
54   * @return array
55   *   The past steps.
56   */
57  public function getPast(): array;
58
59  /**
60   * Get the future steps.
61   *
62   * @return array
63   *   The future steps.
64   */
65  public function getFuture(): array;
66
67  /**
68   * Move history to the last past state.
69   */
70  public function undo(): void;
71
72  /**
73   * Move history to the first future state.
74   */
75  public function redo(): void;
76
77  /**
78   * Reset history to the current state.
79   */
80  public function clear(): void;
81
82}