Completed
Pull Request — wip-lisem (#51)
by
unknown
05:11 queued 02:34
created

CoreAdmin::configure()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 17
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 9.4285
cc 3
eloc 6
nc 4
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Blast Project package.
5
 *
6
 * Copyright (C) 2015-2017 Libre Informatique
7
 *
8
 * This file is licenced under the GNU LGPL v3.
9
 * For the full copyright and license information, please view the LICENSE.md
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Blast\CoreBundle\Admin;
14
15
use Sonata\AdminBundle\Datagrid\DatagridMapper;
16
use Sonata\AdminBundle\Datagrid\ListMapper;
17
use Sonata\AdminBundle\Form\FormMapper;
18
use Sonata\AdminBundle\Mapper\BaseMapper;
19
use Sonata\AdminBundle\Show\ShowMapper;
20
use Sonata\AdminBundle\Route\RouteCollection;
21
use Sonata\AdminBundle\Admin\AbstractAdmin as SonataAdmin;
22
use Sonata\DoctrineORMAdminBundle\Admin\FieldDescription;
23
use Blast\CoreBundle\Tools\Reflection\ClassAnalyzer;
24
use Blast\CoreBundle\Admin\Traits\CollectionsManager;
25
use Blast\CoreBundle\Admin\Traits\Mapper;
26
use Blast\CoreBundle\Admin\Traits\Templates;
27
use Blast\CoreBundle\Admin\Traits\PreEvents;
28
use Blast\CoreBundle\Admin\Traits\ManyToManyManager;
29
use Blast\CoreBundle\Admin\Traits\Actions;
30
use Blast\CoreBundle\Admin\Traits\ListActions;
31
use Blast\CoreBundle\CodeGenerator\CodeGeneratorRegistry;
32
use Blast\CoreBundle\Translator\LibrinfoLabelTranslatorStrategy;
33
use Symfony\Component\PropertyAccess\PropertyAccess;
34
35
abstract class CoreAdmin extends SonataAdmin implements \JsonSerializable
36
{
37
    use CollectionsManager,
38
        ManyToManyManager,
39
        Mapper,
40
        Templates,
41
        PreEvents,
42
        Actions,
43
        ListActions
44
    ;
45
46
    protected $extraTemplates = [];
47
48
        
49
    public function configure()
50
    {
51
        parent::configure();
52
        
53
        /* Default Translation Strategy if not set as admin service tags */
54
        /* @todo : find if it is a good idea or not */
55
        if (!($this->getLabelTranslatorStrategy() instanceof LibrinfoLabelTranslatorStrategy)) {
56
            $this->setLabelTranslatorStrategy(new LibrinfoLabelTranslatorStrategy());
57
        }
58
        /* Should always be */
59
        if ($this->getLabelTranslatorStrategy() instanceof LibrinfoLabelTranslatorStrategy) {
60
            $this->getLabelTranslatorStrategy()->setPrefix($this->getClassnameLabel(), true);
61
        }
62
63
        /* @todo: apply TranslatorStrategy to form_tab and form_group and show_tab and
64
           ... warning it may impact code as it used in some postConfigureFormFields */
65
    }
66
    
67
    /**
68
     * Configure routes for list actions.
69
     *
70
     * @param RouteCollection $collection
71
     */
72
    protected function configureRoutes(RouteCollection $collection)
73
    {
74
        parent::configureRoutes($collection);
75
        $collection->add('duplicate', $this->getRouterIdParameter() . '/duplicate');
76
        $collection->add('generateEntityCode');
77
    }
78
79 View Code Duplication
    public function getBaseRouteName()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80
    {
81
        $configuredBaseRoute = $this->getBaseRouteMapping();
82
83
        if (count($configuredBaseRoute) > 0) {
84
            $this->cachedBaseRouteName = null;
0 ignored issues
show
Bug introduced by
The property cachedBaseRouteName cannot be accessed from this context as it is declared private in class Sonata\AdminBundle\Admin\AbstractAdmin.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
85
            if (isset($configuredBaseRoute['name']) && $this->baseRouteName === null) {
86
                $this->baseRouteName = $configuredBaseRoute['name'];
87
            }
88
        }
89
90
        return parent::getBaseRouteName();
91
    }
92
93 View Code Duplication
    public function getBaseRoutePattern()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
94
    {
95
        $configuredBaseRoute = $this->getBaseRouteMapping();
96
97
        if (count($configuredBaseRoute) > 0) {
98
            $this->cachedBaseRoutePattern = null;
0 ignored issues
show
Bug introduced by
The property cachedBaseRoutePattern cannot be accessed from this context as it is declared private in class Sonata\AdminBundle\Admin\AbstractAdmin.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
99
            if (isset($configuredBaseRoute['pattern']) && $this->baseRoutePattern === null) {
100
                $this->baseRoutePattern = $configuredBaseRoute['pattern'];
101
            }
102
        }
103
104
        return parent::getBaseRoutePattern();
105
    }
106
107
    public function getFormTheme()
108
    {
109
        return array_merge($this->formTheme, $this->getFormThemeMapping());
110
    }
111
112
    /**
113
     * @param DatagridMapper $mapper
114
     */
115
    protected function configureDatagridFilters(DatagridMapper $mapper)
116
    {
117
        if (!$this->configureMapper($mapper)) {
118
            $this->fallbackConfiguration($mapper, __FUNCTION__);
119
        }
120
    }
121
122
    /**
123
     * @param ListMapper $mapper
124
     */
125
    protected function configureListFields(ListMapper $mapper)
126
    {
127
        if (!$this->configureMapper($mapper)) {
128
            $this->fallbackConfiguration($mapper, __FUNCTION__);
129
        }
130
    }
131
132
    /**
133
     * @param FormMapper $mapper
134
     */
135
    protected function configureFormFields(FormMapper $mapper)
136
    {
137
        if (!$this->configureMapper($mapper)) {
138
            $this->fallbackConfiguration($mapper, __FUNCTION__);
139
        }
140
    }
141
142
    /**
143
     * @param ShowMapper $mapper
144
     */
145
    protected function configureShowFields(ShowMapper $mapper)
146
    {
147
        if (!$this->configureMapper($mapper)) {
148
            $this->fallbackConfiguration($mapper, __FUNCTION__);
149
        }
150
    }
151
152
    /**
153
     * @param BaseMapper $mapper
154
     */
155
    protected function fixShowRoutes(BaseMapper $mapper)
0 ignored issues
show
Unused Code introduced by
The parameter $mapper is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
156
    {
157
        foreach (['getShow', 'getList'] as $fct) {
158
            foreach ($this->$fct()->getElements() as $field) {
159
                if ($field instanceof FieldDescription) {
160
                    $options = $field->getOptions();
161
                    if ($options['route']['name'] != 'edit') {
162
                        continue;
163
                    }
164
165
                    $options['route']['name'] = 'show';
166
                    $field->setOptions($options);
167
                }
168
            }
169
        }
170
171
        return $this;
172
    }
173
174
    protected function getCurrentComposition()
175
    {
176
        // traits of the current Entity
177
        $classes = ClassAnalyzer::getTraits($this->getClass());
178
        // inheritance of the current Entity
179
        foreach (array_reverse([$this->getClass()] + class_parents($this->getClass())) as $class) {
180
            $classes[] = $class;
181
        }
182
        // inheritance of the current Admin
183
        foreach (array_reverse([$this->getOriginalClass()] + $this->getParentClasses()) as $admin) {
184
            $classes[] = $admin;
185
        }
186
187
        return $classes;
188
    }
189
190
    private function fallbackConfiguration(BaseMapper $mapper, $function)
191
    {
192
        // fallback
193
        $rm = new \ReflectionMethod($this->getParentClass(), $function);
194
        if ($rm->class == $this->getParentClass()) {
195
            $this->configureFields($function, $mapper, $this->getParentClass());
196
        }
197
    }
198
199
    /**
200
     * Returns the level of depth of an array.
201
     *
202
     * @param array $array
203
     * @param int   $level : do not use, just used for recursivity
204
     *
205
     * @return int : depth
206
     */
207
    private static function arrayDepth($array, $level = 0)
208
    {
209
        if (!$array) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $array of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
210
            return $level;
211
        }
212
213
        if (!is_array($array)) {
214
            return $level;
215
        }
216
217
        ++$level;
218
        foreach ($array as $key => $value) {
219
            if (is_array($value)) {
220
                $level = $level < self::arrayDepth($value, $level) ? self::arrayDepth($value, $level) : $level;
221
            }
222
        }
223
224
        return $level;
225
    }
226
227
    protected function getOriginalClass()
228
    {
229
        return get_called_class();
230
    }
231
232
    protected function getParentClasses()
233
    {
234
        return class_parents($this->getOriginalClass());
235
    }
236
237
    protected function getParentClass()
238
    {
239
        return get_parent_class($this->getOriginalClass());
240
    }
241
242
    protected function getGrandParentClass()
243
    {
244
        return get_parent_class(get_parent_class($this->getOriginalClass()));
245
    }
246
247
    /**
248
     * @param string $view     'list', 'show', 'form', etc
249
     * @param string $template template name
250
     */
251
    public function addExtraTemplate($view, $template)
252
    {
253
        if (empty($this->extraTemplates[$view])) {
254
            $this->extraTemplates[$view] = [];
255
        }
256
        if (!in_array($template, $this->extraTemplates[$view])) {
257
            $this->extraTemplates[$view][] = $template;
258
        }
259
    }
260
261
    /**
262
     * @param string $view 'list', 'show', 'form', etc
263
     *
264
     * @return array array of template names
265
     */
266
    public function getExtraTemplates($view)
267
    {
268
        if (empty($this->extraTemplates[$view])) {
269
            $this->extraTemplates[$view] = [];
270
        }
271
272
        return $this->extraTemplates[$view];
273
    }
274
275
    /**
276
     * @param string $view 'list', 'show', 'form', etc
277
     * @param array  $link link (array keys should be: 'label', 'url', 'class', 'title')
278
     */
279
    public function addHelperLink($view, $link)
280
    {
281
        if (empty($this->helperLinks[$view])) {
282
            $this->helperLinks[$view] = [];
283
        }
284
285
        // Do not add links without URL
286
        if (empty($link['url'])) {
287
            return;
288
        }
289
290
        // Do not add two links with the same URL
291
        foreach ($this->helperLinks[$view] as $l) {
292
            if ($l['url'] == $link['url']) {
293
                return;
294
            }
295
        }
296
297
        $this->helperLinks[$view][] = $link;
298
    }
299
300
    /**
301
     * @param string $view 'list', 'show', 'form', etc
302
     *
303
     * @return array array of links (each link is an array with keys 'label', 'url', 'class' and 'title')
304
     */
305
    public function getHelperLinks($view)
306
    {
307
        if (empty($this->helperLinks[$view])) {
308
            $this->helperLinks[$view] = [];
309
        }
310
311
        return $this->helperLinks[$view];
312
    }
313
314
    /**
315
     * Checks if a Bundle is installed.
316
     *
317
     * @param string $bundle Bundle name or class FQN
318
     */
319
    public function bundleExists($bundle)
320
    {
321
        $kernelBundles = $this->getConfigurationPool()->getContainer()->getParameter('kernel.bundles');
322
        if (array_key_exists($bundle, $kernelBundles)) {
323
            return true;
324
        }
325
        if (in_array($bundle, $kernelBundles)) {
326
            return true;
327
        }
328
329
        return false;
330
    }
331
332
    /**
333
     * Rename a form tab after form fields have been configured.
334
     *
335
     * TODO: groups of the renamed tab are still prefixed with the old tab name
336
     *
337
     * @param type $tabName    the name of the tab to be renamed
338
     * @param type $newTabName the new name for the tab
339
     */
340 View Code Duplication
    public function renameFormTab($tabName, $newTabName, $keepOrder = true)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
341
    {
342
        $tabs = $this->getFormTabs();
343
344
        if (!$tabs) {
345
            return;
346
        }
347
348
        if (!isset($tabs[$tabName])) {
349
            throw new \Exception(sprintf('Tab %s does not exist.', $tabName));
350
        }
351
        if (isset($tabs[$newTabName])) {
352
            return;
353
        }
354
355
        if ($keepOrder) {
356
            $keys = array_keys($tabs);
357
            $keys[array_search($tabName, $keys)] = $newTabName;
358
            $tabs = array_combine($keys, $tabs);
359
        } else {
360
            $tabs[$newTabName] = $tabs[$tabName];
361
            unset($tabs[$tabName]);
362
        }
363
364
        $this->setFormTabs($tabs);
0 ignored issues
show
Bug introduced by
It seems like $tabs defined by $this->getFormTabs() on line 342 can also be of type boolean; however, Sonata\AdminBundle\Admin...actAdmin::setFormTabs() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
365
    }
366
367
    /**
368
     * Rename a show tab after show fields have been configured.
369
     *
370
     * TODO: groups of the renamed tab are still prefixed with the old tab name
371
     *
372
     * @param type $tabName    the name of the tab to be renamed
373
     * @param type $newTabName the new name for the tab
374
     */
375 View Code Duplication
    public function renameShowTab($tabName, $newTabName, $keepOrder = true)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
376
    {
377
        $tabs = $this->getShowTabs();
378
379
        if (!$tabs) {
380
            return;
381
        }
382
383
        if (!isset($tabs[$tabName])) {
384
            throw new \Exception(sprintf('Tab %s does not exist.', $tabName));
385
        }
386
        if (isset($tabs[$newTabName])) {
387
            return;
388
        }
389
390
        if ($keepOrder) {
391
            $keys = array_keys($tabs);
392
            $keys[array_search($tabName, $keys)] = $newTabName;
393
            $tabs = array_combine($keys, $tabs);
394
        } else {
395
            $tabs[$newTabName] = $tabs[$tabName];
396
            unset($tabs[$tabName]);
397
        }
398
399
        $this->setShowTabs($tabs);
0 ignored issues
show
Bug introduced by
It seems like $tabs defined by $this->getShowTabs() on line 377 can also be of type boolean; however, Sonata\AdminBundle\Admin...actAdmin::setShowTabs() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
400
    }
401
402
    /**
403
     * Rename a form group.
404
     *
405
     * @param string $group        the old group name
406
     * @param string $tab          the tab the group belongs to
407
     * @param string $newGroupName the new group name
408
     *
409
     * @return self
410
     */
411
    public function renameFormGroup($group, $tab, $newGroupName)
412
    {
413
        $groups = $this->getFormGroups();
414
415
        // When the default tab is used, the tabname is not prepended to the index in the group array
416
        if ($tab !== 'default') {
417
            $group = $tab . '.' . $group;
418
        }
419
        $newGroup = ($tab !== 'default') ? $tab . '.' . $newGroupName : $newGroupName;
420
421
        if (isset($groups[$newGroup])) {
422
            throw new \Exception(sprintf('%s form group already exists.', $newGroup));
423
        }
424
        if (!array_key_exists($group, $groups)) {
425
            throw new \Exception(sprintf('form group « %s » doesn\'t exist.', $group));
426
        }
427
428
        $groups[$newGroup] = $groups[$group];
429
        $groups[$newGroup]['name'] = $newGroupName;
430
        unset($groups[$group]);
431
432
        $tabs = $this->getFormTabs();
433
        $key = array_search($group, $tabs[$tab]['groups']);
434
435
        if (false !== $key) {
436
            $tabs[$tab]['groups'][$key] = $newGroup;
437
        }
438
439
        $this->setFormTabs($tabs);
0 ignored issues
show
Bug introduced by
It seems like $tabs defined by $this->getFormTabs() on line 432 can also be of type boolean; however, Sonata\AdminBundle\Admin...actAdmin::setFormTabs() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
440
        $this->setFormGroups($groups);
0 ignored issues
show
Bug introduced by
It seems like $groups defined by $this->getFormGroups() on line 413 can also be of type boolean; however, Sonata\AdminBundle\Admin...tAdmin::setFormGroups() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
441
442
        return $this;
443
    }
444
445
    /**
446
     * Removes tab in current form Mapper.
447
     *
448
     * @param string|array $tabNames name or array of names of tabs to be removed
449
     * @param FormMapper   $mapper   Sonata Admin form mapper
450
     */
451
    public function removeTab($tabNames, $mapper)
452
    {
453
        $currentTabs = $this->getFormTabs();
454
        foreach ($currentTabs as $k => $item) {
0 ignored issues
show
Bug introduced by
The expression $currentTabs of type array|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
455
            if (is_array($tabNames) && in_array($item['name'], $tabNames) || !is_array($tabNames) && $item['name'] === $tabNames) {
456
                foreach ($item['groups'] as $groupName) {
457
                    $this->removeAllFieldsFromFormGroup($groupName, $mapper);
458
                }
459
                unset($currentTabs[$k]);
460
            }
461
        }
462
        $this->setFormTabs($currentTabs);
0 ignored issues
show
Bug introduced by
It seems like $currentTabs defined by $this->getFormTabs() on line 453 can also be of type boolean; however, Sonata\AdminBundle\Admin...actAdmin::setFormTabs() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
463
    }
464
465
    /**
466
     * Removes all fields from form groups and remove them from mapper.
467
     *
468
     * @param string     $groupName Name of the group to remove
469
     * @param FormMapper $mapper    Sonata Admin form mapper
470
     */
471
    public function removeAllFieldsFromFormGroup($groupName, $mapper)
472
    {
473
        $formGroups = $this->getFormGroups();
474
        foreach ($formGroups as $name => $formGroup) {
0 ignored issues
show
Bug introduced by
The expression $formGroups of type array|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
475
            if ($name === $groupName) {
476
                foreach ($formGroups[$name]['fields'] as $key => $field) {
477
                    $mapper->remove($key);
478
                }
479
            }
480
        }
481
    }
482
483
    public function jsonSerialize()
484
    {
485
        $propertiesToShow = [
486
            'baseRouteName',
487
            'baseRoutePattern',
488
            'extraTemplates',
489
            'listFieldDescriptions',
490
            'showFieldDescriptions',
491
            'formFieldDescriptions',
492
            'filterFieldDescriptions',
493
            'maxPerPage',
494
            'maxPageLinks',
495
            'classnameLabel',
496
            'translationDomain',
497
            'formOptions',
498
            'datagridValues',
499
            'perPageOptions',
500
            'pagerType',
501
            'code',
502
            'label',
503
            'routes',
504
            'subject',
505
            'children',
506
            'parent',
507
            'baseCodeRoute',
508
            'uniqid',
509
            'extensions',
510
            'class',
511
            'subClasses',
512
            'list',
513
            'show',
514
            'form',
515
            'filter',
516
            'formGroups',
517
            'formTabs',
518
            'showGroups',
519
            'showTabs',
520
            'managedCollections',
521
            'helperLinks',
522
            'titles',
523
        ];
524
525
        $properties = [];
526
        foreach ($this as $key => $value) {
0 ignored issues
show
Bug introduced by
The expression $this of type this<Blast\CoreBundle\Admin\CoreAdmin> is not traversable.
Loading history...
527
            if (in_array($key, $propertiesToShow)) {
528
                $properties[$key] = $value;
529
            }
530
        }
531
532
        return $properties;
533
    }
534
535
    /**
536
     * {@inheritdoc}
537
     */
538
    public function prePersist($object)
539
    {
540
        parent::prePersist($object);
541
542
        $hasCodeGenerator = CodeGeneratorRegistry::hasGeneratorForClass(get_class($object));
543
        if ($hasCodeGenerator) {
544
            $accessor = PropertyAccess::createPropertyAccessor();
545
            foreach (CodeGeneratorRegistry::getCodeGenerators(get_class($object)) as $name => $generator) {
546
                $accessor->setValue($object, $name, $generator->generate($object));
547
            }
548
        }
549
    }
550
}
551