Skip to content

Commit f29b802

Browse files
committed
Merge pull request #221 from symfony2admingenerator/feat-credentials
Use credentials back instead of groups
2 parents 1ca35d9 + e940adf commit f29b802

File tree

69 files changed

+1070
-973
lines changed

Some content is hidden

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

69 files changed

+1070
-973
lines changed

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ php:
44
- 5.3
55
- 5.4
66
- 5.5
7-
8-
env:
9-
- SYMFONY_VERSION=origin/2.6
7+
- 5.6
8+
- 7.0
109

1110
before_script:
1211
- composer self-update

Builder/Admin/BaseBuilder.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,11 @@ public function setColumnClass($columnClass)
213213
}
214214

215215
/**
216+
* @param Column $column
216217
* @param string $optionName
218+
* @param string $default
219+
*
220+
* @return string
217221
*/
218222
protected function getFieldOption(Column $column, $optionName, $default = null)
219223
{
@@ -405,6 +409,13 @@ protected function setUserActionConfiguration(Action $action)
405409
$action->setProperty($option, $value);
406410
}
407411
}
412+
413+
if ('generic' == $action->getType()) {
414+
// Let's try to get credentials from builder for consistency
415+
if ($credentials = $this->generator->getFromYaml(sprintf('builders.%s.params.credentials', $action->getName()))) {
416+
$action->setCredentials($credentials);
417+
}
418+
}
408419
}
409420

410421
protected function addAction(Action $action)

Builder/Admin/ListBuilder.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,21 @@ protected function addFilterColumn(Column $column)
7171
$this->filterColumns[$column->getName()] = $column;
7272
}
7373

74-
public function getFilterColumnGroups()
74+
public function getFilterColumnsCredentials()
7575
{
76-
$groups = array();
76+
$credentials = array();
7777

78-
foreach ($this->getFilterColumns() as $column) {
79-
$columnGroups = $column->getFiltersGroups();
80-
// If one column has no Group constraint, we always
81-
// have to display the filter panel
82-
if (empty($columnGroups)) {
78+
foreach($this->getFilterColumns() as $column) {
79+
if (! $filterCredentials = $column->getFiltersCredentials()) {
80+
// If one column has no Credentials constraint, we always
81+
// have to display the filter panel
8382
return array();
8483
}
85-
$groups = array_merge($groups, $columnGroups);
84+
85+
$credentials[] = $filterCredentials;
8686
}
8787

88-
return $groups;
88+
return $credentials;
8989
}
9090

9191
/**

Builder/BaseBuilder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public function getVariables()
142142
* (non-PHPdoc)
143143
* @see Builder/Admingenerator\GeneratorBundle\Builder.BuilderInterface::hasVariable()
144144
* @param string $key
145+
* @return bool
145146
*/
146147
public function hasVariable($key)
147148
{
@@ -169,7 +170,7 @@ public function getModelClass()
169170
/**
170171
* Set the generator.
171172
*
172-
* @param \Admingenerator\GeneratorBundle\Builder\Generator $generator A generator.
173+
* @param \TwigGenerator\Builder\Generator $generator A generator.
173174
*/
174175
public function setGenerator(GenericBaseGenerator $generator)
175176
{

Builder/Generator.php

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -118,44 +118,50 @@ public function addBuilder(BuilderInterface $builder)
118118
protected function mergeParameters(array $global, array $builder)
119119
{
120120
foreach ($global as $param => &$value) {
121-
if (array_key_exists($param, $builder)) {
122-
if (in_array($param, array('fields', 'actions', 'object_actions', 'batch_actions'))) {
123-
// Grab builder configuration only if defined
124-
if (!is_null($builder[$param])) {
125-
$configurations = array();
126-
foreach ($builder[$param] as $name => $configuration) {
127-
if (is_array($configuration) || is_null($configuration)) {
128-
if (!is_null($value) && array_key_exists($name, $value)) {
129-
$configurations[$name] = $configuration
130-
? $this->mergeConfiguration($value[$name], $configuration) // Override definition
131-
: $value[$name]; // Configuration is null => use global definition
132-
} else {
133-
// New definition (new field, new action) from builder
134-
$configurations[$name] = $configuration;
135-
}
136-
} else {
137-
throw new \InvalidArgumentException(
138-
sprintf('Invalid %s "%s" builder definition for %s', $param, $name, $this->getFromYaml('params.model'))
139-
);
140-
}
141-
}
142-
143-
if (in_array($param, array('actions', 'object_actions', 'batch_actions'))) {
144-
// Actions list comes from builder
145-
$value = $configurations;
146-
} else {
147-
// All fields are still available in a builder
148-
$value = array_merge($value ?:array(), $configurations);
149-
}
150-
}
121+
if (!array_key_exists($param, $builder)) {
122+
continue;
123+
}
124+
125+
if (!in_array($param, array('fields', 'actions', 'object_actions', 'batch_actions'))) {
126+
if (is_array($value)) {
127+
$value = $this->recursiveReplace($value, $builder[$param]);
128+
} else {
129+
$value = $builder[$param];
130+
}
131+
132+
continue;
133+
}
134+
135+
// Grab builder configuration only if defined
136+
if (is_null($builder[$param])) {
137+
continue;
138+
}
139+
140+
$configurations = array();
141+
foreach ($builder[$param] as $name => $configuration) {
142+
if (!is_array($configuration) && !is_null($configuration)) {
143+
throw new \InvalidArgumentException(
144+
sprintf('Invalid %s "%s" builder definition for %s', $param, $name, $this->getFromYaml('params.model'))
145+
);
146+
}
147+
148+
if (!is_null($value) && array_key_exists($name, $value)) {
149+
$configurations[$name] = $configuration
150+
? $this->mergeConfiguration($value[$name], $configuration) // Override definition
151+
: $value[$name]; // Configuration is null => use global definition
151152
} else {
152-
if (is_array($value)) {
153-
$value = $this->recursiveReplace($value, $builder[$param]);
154-
} else {
155-
$value = $builder[$param];
156-
}
153+
// New definition (new field, new action) from builder
154+
$configurations[$name] = $configuration;
157155
}
158156
}
157+
158+
if (in_array($param, array('actions', 'object_actions', 'batch_actions'))) {
159+
// Actions list comes from builder
160+
$value = $configurations;
161+
} else {
162+
// All fields are still available in a builder
163+
$value = array_merge($value ?:array(), $configurations);
164+
}
159165
}
160166

161167
// If builder doesn't have actions/object_actions/batch_actions remove it from merge.
@@ -177,20 +183,21 @@ protected function mergeParameters(array $global, array $builder)
177183
protected function mergeConfiguration(array $global, array $builder)
178184
{
179185
foreach ($global as $name => &$value) {
180-
if (array_key_exists($name, $builder)) {
181-
if (is_null($builder[$name])) {
182-
continue;
183-
}
186+
if (!array_key_exists($name, $builder) || is_null($builder[$name])) {
187+
continue;
188+
}
184189

185-
if (is_array($value)) {
186-
if (!is_array($builder[$name])) {
187-
throw new \InvalidArgumentException('Invalid generator');
188-
}
189-
$value = array_replace($value, $builder[$name]);
190-
} else {
191-
$value = $builder[$name];
192-
}
190+
if (!is_array($value)) {
191+
$value = $builder[$name];
192+
193+
continue;
193194
}
195+
196+
if (!is_array($builder[$name])) {
197+
throw new \InvalidArgumentException('Invalid generator');
198+
}
199+
200+
$value = array_replace($value, $builder[$name]);
194201
}
195202

196203
return array_merge($global, array_diff_key($builder, $global));

0 commit comments

Comments
 (0)