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

Commit d10594c

Browse files
Merge remote-tracking branch 'stwe/master' into patch-5
2 parents ac79065 + 13d208f commit d10594c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1620
-411
lines changed

.travis.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ cache:
99
matrix:
1010
fast_finish: true
1111
include:
12-
- php: 5.5
13-
- php: 5.6
14-
- php: 7.0
12+
- php: 7.1
13+
env: DEPENDENCIES=beta
1514
- php: hhvm
1615
allow_failures:
1716
- php: hhvm
@@ -21,10 +20,10 @@ env:
2120

2221
before_install:
2322
- composer self-update
23+
- if [ "$DEPENDENCIES" = "beta" ]; then composer config minimum-stability beta; fi;
2424
- if [ "$SYMFONY_VERSION" != "" ]; then composer require --dev --no-update symfony/framework-bundle=$SYMFONY_VERSION; fi
2525
- if [ "$DEPENDENCIES" = "dev" ]; then perl -pi -e 's/^}$/,"minimum-stability":"dev"}/' composer.json; fi;
26-
- if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." ]]; then composer require --dev "phpunit/phpunit=4.8.*"; fi
27-
- if [[ ${TRAVIS_PHP_VERSION:0:2} == "7." ]]; then composer require --dev "phpunit/phpunit=5.7.*"; fi
26+
- composer require --dev "phpunit/phpunit=5.7.*"
2827

2928
install: composer update --prefer-dist --no-interaction $COMPOSER_FLAGS
3029

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Version 1.1.1
2+
3+
* Bugfix: DateRangeFilter overwrites other filter (#803)
4+
5+
# Version 1.1.0
6+
7+
* Dropped support for PHP 5 and PHP 7.0. (#850)
8+
* Feature: Unique name to allow a datatable multiple times on the same page
9+
* Feature: Added the RowGroup extension (#769)
10+
* Bugfix: fixed Basque, Polish, Hebrew, Latvian and Russian translations (#760, #844, #846)
11+
* Other bugfixes

Controller/DatatableController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class DatatableController extends Controller
3939
*
4040
* @param Request $request
4141
*
42-
* @Route("/sg/datatables/edit/field", name="sg_datatables_edit")
42+
* @Route("/datatables/edit/field", name="sg_datatables_edit")
4343
* @Method("POST")
4444
*
4545
* @return Response

Datatable/AbstractDatatable.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,29 @@ abstract class AbstractDatatable implements DatatableInterface
128128
*/
129129
protected $language;
130130

131+
/**
132+
* The unique id for this instance.
133+
*
134+
* @var int
135+
*/
136+
protected $uniqueId;
137+
131138
/**
132139
* The PropertyAccessor.
133140
*
134141
* @var PropertyAccessor
135142
*/
136143
protected $accessor;
137144

145+
//-------------------------------------------------
146+
147+
/**
148+
* Used to generate unique names.
149+
*
150+
* @var array
151+
*/
152+
protected static $uniqueCounter = array();
153+
138154
//-------------------------------------------------
139155
// Ctor.
140156
//-------------------------------------------------
@@ -161,6 +177,12 @@ public function __construct(
161177
) {
162178
$this->validateName();
163179

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+
}
185+
164186
$this->authorizationChecker = $authorizationChecker;
165187
$this->securityToken = $securityToken;
166188
$this->translator = $translator;
@@ -282,6 +304,22 @@ public function getOptionsArrayFromEntities($entities, $keyFrom = 'id', $valueFr
282304
return $options;
283305
}
284306

307+
/**
308+
* {@inheritdoc}
309+
*/
310+
public function getUniqueId()
311+
{
312+
return $this->uniqueId;
313+
}
314+
315+
/**
316+
* {@inheritdoc}
317+
*/
318+
public function getUniqueName()
319+
{
320+
return $this->getName().($this->getUniqueId() > 1 ? '-'.$this->getUniqueId() : '');
321+
}
322+
285323
//-------------------------------------------------
286324
// Private
287325
//-------------------------------------------------

Datatable/Action/Action.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class Action
9494
* HTML attributes (except 'href' and 'value').
9595
* Default: null
9696
*
97-
* @var null|array
97+
* @var null|array|Closure
9898
*/
9999
protected $attributes;
100100

@@ -179,7 +179,7 @@ public function configureOptions(OptionsResolver $resolver)
179179
$resolver->setAllowedTypes('label', array('null', 'string'));
180180
$resolver->setAllowedTypes('confirm', 'bool');
181181
$resolver->setAllowedTypes('confirm_message', array('null', 'string'));
182-
$resolver->setAllowedTypes('attributes', array('null', 'array'));
182+
$resolver->setAllowedTypes('attributes', array('null', 'array', 'Closure'));
183183
$resolver->setAllowedTypes('button', 'bool');
184184
$resolver->setAllowedTypes('button_value', array('null', 'string'));
185185
$resolver->setAllowedTypes('button_value_prefix', 'bool');
@@ -341,7 +341,7 @@ public function setConfirmMessage($confirmMessage)
341341
/**
342342
* Get attributes.
343343
*
344-
* @return null|array
344+
* @return null|array|Closure
345345
*/
346346
public function getAttributes()
347347
{
@@ -351,7 +351,7 @@ public function getAttributes()
351351
/**
352352
* Set attributes.
353353
*
354-
* @param null|array $attributes
354+
* @param null|array|Closure $attributes
355355
*
356356
* @return $this
357357
* @throws Exception

Datatable/Column/AbstractColumn.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ public function isSelectColumn()
412412
*/
413413
public function getOptionsTemplate()
414414
{
415-
return 'SgDatatablesBundle:column:column.html.twig';
415+
return '@SgDatatables/column/column.html.twig';
416416
}
417417

418418
/**

Datatable/Column/ActionColumn.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,14 @@ public function addDataToOutputArray(array &$row)
8181
public function renderSingleField(array &$row)
8282
{
8383
$parameters = array();
84+
$attributes = array();
8485
$values = array();
8586

8687
/** @var Action $action */
8788
foreach ($this->actions as $actionKey => $action) {
8889
$routeParameters = $action->getRouteParameters();
8990
if (is_array($routeParameters)) {
90-
foreach ($routeParameters as $key => $value) {
91+
foreach ($routeParameters as $key => $value) {
9192
if (isset($row[$value])) {
9293
$parameters[$actionKey][$key] = $row[$value];
9394
} else {
@@ -107,6 +108,15 @@ public function renderSingleField(array &$row)
107108
$parameters[$actionKey] = array();
108109
}
109110

111+
$actionAttributes = $action->getAttributes();
112+
if (is_array($actionAttributes)) {
113+
$attributes[$actionKey] = $actionAttributes;
114+
} elseif ($actionAttributes instanceof Closure) {
115+
$attributes[$actionKey] = call_user_func($actionAttributes, $row);
116+
} else {
117+
$attributes[$actionKey] = array();
118+
}
119+
110120
if ($action->isButton()) {
111121
if (null !== $action->getButtonValue()) {
112122
if (isset($row[$action->getButtonValue()])) {
@@ -133,6 +143,7 @@ public function renderSingleField(array &$row)
133143
array(
134144
'actions' => $this->actions,
135145
'route_parameters' => $parameters,
146+
'attributes' => $attributes,
136147
'values' => $values,
137148
'render_if_actions' => $row['sg_datatables_actions'][$this->index],
138149
'start_html_container' => $this->startHtml,
@@ -154,7 +165,7 @@ public function renderToMany(array &$row)
154165
*/
155166
public function getCellContentTemplate()
156167
{
157-
return 'SgDatatablesBundle:render:action.html.twig';
168+
return '@SgDatatables/render/action.html.twig';
158169
}
159170

160171
/**

Datatable/Column/BooleanColumn.php

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,17 @@ public function renderSingleField(array &$row)
8888
{
8989
$path = Helper::getDataPropertyPath($this->data);
9090

91-
if (true === $this->isEditableContentRequired($row)) {
92-
$content = $this->renderTemplate($this->accessor->getValue($row, $path), $row[$this->editable->getPk()]);
93-
} else {
94-
$content = $this->renderTemplate($this->accessor->getValue($row, $path));
95-
}
91+
if ($this->accessor->isReadable($row, $path)) {
92+
93+
if (true === $this->isEditableContentRequired($row)) {
94+
$content = $this->renderTemplate($this->accessor->getValue($row, $path), $row[$this->editable->getPk()]);
95+
} else {
96+
$content = $this->renderTemplate($this->accessor->getValue($row, $path));
97+
}
9698

97-
$this->accessor->setValue($row, $path, $content);
99+
$this->accessor->setValue($row, $path, $content);
100+
101+
}
98102

99103
return $this;
100104
}
@@ -107,27 +111,31 @@ public function renderToMany(array &$row)
107111
$value = null;
108112
$path = Helper::getDataPropertyPath($this->data, $value);
109113

110-
$entries = $this->accessor->getValue($row, $path);
111-
112-
if (count($entries) > 0) {
113-
foreach ($entries as $key => $entry) {
114-
$currentPath = $path.'['.$key.']'.$value;
115-
$currentObjectPath = Helper::getPropertyPathObjectNotation($path, $key, $value);
116-
117-
if (true === $this->isEditableContentRequired($row)) {
118-
$content = $this->renderTemplate(
119-
$this->accessor->getValue($row, $currentPath),
120-
$row[$this->editable->getPk()],
121-
$currentObjectPath
122-
);
123-
} else {
124-
$content = $this->renderTemplate($this->accessor->getValue($row, $currentPath));
125-
}
114+
if ($this->accessor->isReadable($row, $path)) {
126115

127-
$this->accessor->setValue($row, $currentPath, $content);
116+
$entries = $this->accessor->getValue($row, $path);
117+
118+
if (count($entries) > 0) {
119+
foreach ($entries as $key => $entry) {
120+
$currentPath = $path . '[' . $key . ']' . $value;
121+
$currentObjectPath = Helper::getPropertyPathObjectNotation($path, $key, $value);
122+
123+
if (true === $this->isEditableContentRequired($row)) {
124+
$content = $this->renderTemplate(
125+
$this->accessor->getValue($row, $currentPath),
126+
$row[$this->editable->getPk()],
127+
$currentObjectPath
128+
);
129+
} else {
130+
$content = $this->renderTemplate($this->accessor->getValue($row, $currentPath));
131+
}
132+
133+
$this->accessor->setValue($row, $currentPath, $content);
134+
}
135+
} else {
136+
// no placeholder - leave this blank
128137
}
129-
} else {
130-
// no placeholder - leave this blank
138+
131139
}
132140

133141
return $this;
@@ -138,7 +146,7 @@ public function renderToMany(array &$row)
138146
*/
139147
public function getCellContentTemplate()
140148
{
141-
return 'SgDatatablesBundle:render:boolean.html.twig';
149+
return '@SgDatatables/render/boolean.html.twig';
142150
}
143151

144152
/**
@@ -148,7 +156,7 @@ public function renderPostCreateDatatableJsContent()
148156
{
149157
if ($this->editable instanceof EditableInterface) {
150158
return $this->twig->render(
151-
'SgDatatablesBundle:column:column_post_create_dt.js.twig',
159+
'@SgDatatables/column/column_post_create_dt.js.twig',
152160
array(
153161
'column_class_editable_selector' => $this->getColumnClassEditableSelector(),
154162
'editable_options' => $this->editable,
@@ -336,7 +344,7 @@ public function setFalseLabel($falseLabel)
336344
private function renderTemplate($data, $pk = null, $path = null)
337345
{
338346
$renderVars = array(
339-
'data' => $data,
347+
'data' => $this->isCustomDql() && in_array($data, array(0, 1, '0', '1'), true) ? boolval($data) : $data,
340348
'default_content' => $this->getDefaultContent(),
341349
'true_label' => $this->trueLabel,
342350
'true_icon' => $this->trueIcon,

0 commit comments

Comments
 (0)