Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit 905478e

Browse files
committed
Unique name as incremental id
1 parent 36dd9d2 commit 905478e

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

Datatable/AbstractDatatable.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ abstract class AbstractDatatable implements DatatableInterface
129129
protected $language;
130130

131131
/**
132-
* The unique name for this instance.
132+
* The unique id for this instance.
133133
*
134-
* @var string
134+
* @var int
135135
*/
136-
protected $uniqueName;
136+
protected $uniqueId;
137137

138138
/**
139139
* The PropertyAccessor.
@@ -142,6 +142,15 @@ abstract class AbstractDatatable implements DatatableInterface
142142
*/
143143
protected $accessor;
144144

145+
//-------------------------------------------------
146+
147+
/**
148+
* Used to generate unique names.
149+
*
150+
* @var array
151+
*/
152+
protected static $uniqueCounter = array();
153+
145154
//-------------------------------------------------
146155
// Ctor.
147156
//-------------------------------------------------
@@ -167,7 +176,12 @@ public function __construct(
167176
Twig_Environment $twig
168177
) {
169178
$this->validateName();
170-
$this->uniqueName = uniqid($this->getName().'-');
179+
180+
if (isset(self::$uniqueCounter[$this->getName()])) {
181+
$this->uniqueId = ++self::$uniqueCounter[$this->getName()];
182+
} else {
183+
$this->uniqueId = self::$uniqueCounter[$this->getName()] = 1;
184+
}
171185

172186
$this->authorizationChecker = $authorizationChecker;
173187
$this->securityToken = $securityToken;
@@ -290,12 +304,20 @@ public function getOptionsArrayFromEntities($entities, $keyFrom = 'id', $valueFr
290304
return $options;
291305
}
292306

307+
/**
308+
* {@inheritdoc}
309+
*/
310+
public function getUniqueId()
311+
{
312+
return $this->uniqueId;
313+
}
314+
293315
/**
294316
* {@inheritdoc}
295317
*/
296318
public function getUniqueName()
297319
{
298-
return $this->uniqueName;
320+
return $this->getName().($this->getUniqueId() > 1 ? '-'.$this->getUniqueId() : '');
299321
}
300322

301323
//-------------------------------------------------

Datatable/DatatableInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ public function getEntity();
126126
*/
127127
public function getName();
128128

129+
/**
130+
* Returns the unique id of this datatable view.
131+
*
132+
* @return int
133+
*/
134+
public function getUniqueId();
135+
129136
/**
130137
* Returns the unique name of this datatable view.
131138
*

0 commit comments

Comments
 (0)