Completed
Pull Request — wip-lisem (#51)
by
unknown
05:34 queued 02:32
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
    public function configure()
49
    {
50
        parent::configure();
51
52
        /* Default Translation Strategy if not set as admin service tags */
53
        /* @todo : find if it is a good idea or not */
54
        if (!($this->getLabelTranslatorStrategy() instanceof LibrinfoLabelTranslatorStrategy)) {
55
            $this->setLabelTranslatorStrategy(new LibrinfoLabelTranslatorStrategy());
56
        }
57
        /* Should always be */
58
        if ($this->getLabelTranslatorStrategy() instanceof LibrinfoLabelTranslatorStrategy) {
59
            $this->getLabelTranslatorStrategy()->setFix($this->getClassnameLabel(), true);
60
        }
61
62
        /* @todo: apply TranslatorStrategy to form_tab and form_group and show_tab and
63
           ... warning it may impact code as it used in some postConfigureFormFields */
64
    }
65
66
    /**
67
     * Configure routes for list actions.
68
     *
69
     * @param RouteCollection $collection
70
     */
71
    protected function configureRoutes(RouteCollection $collection)
72
    {
73
        parent::configureRoutes($collection);
74
        $collection->add('duplicate', $this->getRouterIdParameter() . '/duplicate');
75
        $collection->add('generateEntityCode');
76
    }
77
78 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...
79
    {
80
        $configuredBaseRoute = $this->getBaseRouteMapping();
81
82
        if (count($configuredBaseRoute) > 0) {
83
            $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...
84
            if (isset($configuredBaseRoute['name']) && $this->baseRouteName === null) {
85
                $this->baseRouteName = $configuredBaseRoute['name'];
86
            }
87
        }
88
89
        return parent::getBaseRouteName();
90
    }
91
92 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...
93
    {
94
        $configuredBaseRoute = $this->getBaseRouteMapping();
95
96
        if (count($configuredBaseRoute) > 0) {
97
            $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...
98
            if (isset($configuredBaseRoute['pattern']) && $this->baseRoutePattern === null) {
99
                $this->baseRoutePattern = $configuredBaseRoute['pattern'];
100
            }
101
        }
102
103
        return parent::getBaseRoutePattern();
104
    }
105
106
    public function getFormTheme()
107
    {
108
        return array_merge($this->formTheme, $this->getFormThemeMapping());
109
    }
110
111
    /**
112
     * @param DatagridMapper $mapper
113
     */
114
    protected function configureDatagridFilters(DatagridMapper $mapper)
115
    {
116
        if (!$this->configureMapper($mapper)) {
117
            $this->fallbackConfiguration($mapper, __FUNCTION__);
118
        }
119
    }
120
121
    /**
122
     * @param ListMapper $mapper
123
     */
124
    protected function configureListFields(ListMapper $mapper)
125
    {
126
        if (!$this->configureMapper($mapper)) {
127
            $this->fallbackConfiguration($mapper, __FUNCTION__);
128
        }
129
    }
130
131
    /**
132
     * @param FormMapper $mapper
133
     */
134
    protected function configureFormFields(FormMapper $mapper)
135
    {
136
        if (!$this->configureMapper($mapper)) {
137
            $this->fallbackConfiguration($mapper, __FUNCTION__);
138
        }
139
    }
140
141
    /**
142
     * @param ShowMapper $mapper
143
     */
144
    protected function configureShowFields(ShowMapper $mapper)
145
    {
146
        if (!$this->configureMapper($mapper)) {
147
            $this->fallbackConfiguration($mapper, __FUNCTION__);
148
        }
149
    }
150
151
    /**
152
     * @param BaseMapper $mapper
153
     */
154
    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...
155
    {
156
        foreach (['getShow', 'getList'] as $fct) {
157
            foreach ($this->$fct()->getElements() as $field) {
158
                if ($field instanceof FieldDescription) {
159
                    $options = $field->getOptions();
160
                    if ($options['route']['name'] != 'edit') {
161
                        continue;
162
                    }
163
164
                    $options['route']['name'] = 'show';
165
                    $field->setOptions($options);
166
                }
167
            }
168
        }
169
170
        return $this;
171
    }
172
173
    protected function getCurrentComposition()
174
    {
175
        // traits of the current Entity
176
        $classes = ClassAnalyzer::getTraits($this->getClass());
177
        // inheritance of the current Entity
178
        foreach (array_reverse([$this->getClass()] + class_parents($this->getClass())) as $class) {
179
            $classes[] = $class;
180
        }
181
        // inheritance of the current Admin
182
        foreach (array_reverse([$this->getOriginalClass()] + $this->getParentClasses()) as $admin) {
183
            $classes[] = $admin;
184
        }
185
186
        return $classes;
187
    }
188
189
    private function fallbackConfiguration(BaseMapper $mapper, $function)
190
    {
191
        // fallback
192
        $rm = new \ReflectionMethod($this->getParentClass(), $function);
193
        if ($rm->class == $this->getParentClass()) {
194
            $this->configureFields($function, $mapper, $this->getParentClass());
195
        }
196
    }
197
198
    /**
199
     * Returns the level of depth of an array.
200
     *
201
     * @param array $array
202
     * @param int   $level : do not use, just used for recursivity
203
     *
204
     * @return int : depth
205
     */
206
    private static function arrayDepth($array, $level = 0)
207
    {
208
        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...
209
            return $level;
210
        }
211
212
        if (!is_array($array)) {
213
            return $level;
214
        }
215
216
        ++$level;
217
        foreach ($array as $key => $value) {
218
            if (is_array($value)) {
219
                $level = $level < self::arrayDepth($value, $level) ? self::arrayDepth($value, $level) : $level;
220
            }
221
        }
222
223
        return $level;
224
    }
225
226
    protected function getOriginalClass()
227
    {
228
        return get_called_class();
229
    }
230
231
    protected function getParentClasses()
232
    {
233
        return class_parents($this->getOriginalClass());
234
    }
235
236
    protected function getParentClass()
237
    {
238
        return get_parent_class($this->getOriginalClass());
239
    }
240
241
    protected function getGrandParentClass()
242
    {
243
        return get_parent_class(get_parent_class($this->getOriginalClass()));
244
    }
245
246
    /**
247
     * @param string $view     'list', 'show', 'form', etc
248
     * @param string $template template name
249
     */
250
    public function addExtraTemplate($view, $template)
251
    {
252
        if (empty($this->extraTemplates[$view])) {
253
            $this->extraTemplates[$view] = [];
254
        }
255
        if (!in_array($template, $this->extraTemplates[$view])) {
256
            $this->extraTemplates[$view][] = $template;
257
        }
258
    }
259
260
    /**
261
     * @param string $view 'list', 'show', 'form', etc
262
     *
263
     * @return array array of template names
264
     */
265
    public function getExtraTemplates($view)
266
    {
267
        if (empty($this->extraTemplates[$view])) {
268
            $this->extraTemplates[$view] = [];
269
        }
270
271
        return $this->extraTemplates[$view];
272
    }
273
274
    /**
275
     * @param string $view 'list', 'show', 'form', etc
276
     * @param array  $link link (array keys should be: 'label', 'url', 'class', 'title')
277
     */
278
    public function addHelperLink($view, $link)
279
    {
280
        if (empty($this->helperLinks[$view])) {
281
            $this->helperLinks[$view] = [];
282
        }
283
284
        // Do not add links without URL
285
        if (empty($link['url'])) {
286
            return;
287
        }
288
289
        // Do not add two links with the same URL
290
        foreach ($this->helperLinks[$view] as $l) {
291
            if ($l['url'] == $link['url']) {
292
                return;
293
            }
294
        }
295
296
        $this->helperLinks[$view][] = $link;
297
    }
298
299
    /**
300
     * @param string $view 'list', 'show', 'form', etc
301
     *
302
     * @return array array of links (each link is an array with keys 'label', 'url', 'class' and 'title')
303
     */
304
    public function getHelperLinks($view)
305
    {
306
        if (empty($this->helperLinks[$view])) {
307
            $this->helperLinks[$view] = [];
308
        }
309
310
        return $this->helperLinks[$view];
311
    }
312
313
    /**
314
     * Checks if a Bundle is installed.
315
     *
316
     * @param string $bundle Bundle name or class FQN
317
     */
318
    public function bundleExists($bundle)
319
    {
320
        $kernelBundles = $this->getConfigurationPool()->getContainer()->getParameter('kernel.bundles');
321
        if (array_key_exists($bundle, $kernelBundles)) {
322
            return true;
323
        }
324
        if (in_array($bundle, $kernelBundles)) {
325
            return true;
326
        }
327
328
        return false;
329
    }
330
331
    /**
332
     * Rename a form tab after form fields have been configured.
333
     *
334
     * TODO: groups of the renamed tab are still prefixed with the old tab name
335
     *
336
     * @param type $tabName    the name of the tab to be renamed
337
     * @param type $newTabName the new name for the tab
338
     */
339 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...
340
    {
341
        $tabs = $this->getFormTabs();
342
343
        if (!$tabs) {
344
            return;
345
        }
346
347
        if (!isset($tabs[$tabName])) {
348
            throw new \Exception(sprintf('Tab %s does not exist.', $tabName));
349
        }
350
        if (isset($tabs[$newTabName])) {
351
            return;
352
        }
353
354
        if ($keepOrder) {
355
            $keys = array_keys($tabs);
356
            $keys[array_search($tabName, $keys)] = $newTabName;
357
            $tabs = array_combine($keys, $tabs);
358
        } else {
359
            $tabs[$newTabName] = $tabs[$tabName];
360
            unset($tabs[$tabName]);
361
        }
362
363
        $this->setFormTabs($tabs);
0 ignored issues
show
Bug introduced by
It seems like $tabs defined by $this->getFormTabs() on line 341 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...
364
    }
365
366
    /**
367
     * Rename a show tab after show fields have been configured.
368
     *
369
     * TODO: groups of the renamed tab are still prefixed with the old tab name
370
     *
371
     * @param type $tabName    the name of the tab to be renamed
372
     * @param type $newTabName the new name for the tab
373
     */
374 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...
375
    {
376
        $tabs = $this->getShowTabs();
377
378
        if (!$tabs) {
379
            return;
380
        }
381
382
        if (!isset($tabs[$tabName])) {
383
            throw new \Exception(sprintf('Tab %s does not exist.', $tabName));
384
        }
385
        if (isset($tabs[$newTabName])) {
386
            return;
387
        }
388
389
        if ($keepOrder) {
390
            $keys = array_keys($tabs);
391
            $keys[array_search($tabName, $keys)] = $newTabName;
392
            $tabs = array_combine($keys, $tabs);
393
        } else {
394
            $tabs[$newTabName] = $tabs[$tabName];
395
            unset($tabs[$tabName]);
396
        }
397
398
        $this->setShowTabs($tabs);
0 ignored issues
show
Bug introduced by
It seems like $tabs defined by $this->getShowTabs() on line 376 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...
399
    }
400
401
    /**
402
     * Rename a form group.
403
     *
404
     * @param string $group        the old group name
405
     * @param string $tab          the tab the group belongs to
406
     * @param string $newGroupName the new group name
407
     *
408
     * @return self
409
     */
410
    public function renameFormGroup($group, $tab, $newGroupName)
411
    {
412
        $groups = $this->getFormGroups();
413
414
        // When the default tab is used, the tabname is not prepended to the index in the group array
415
        if ($tab !== 'default') {
416
            $group = $tab . '.' . $group;
417
        }
418
        $newGroup = ($tab !== 'default') ? $tab . '.' . $newGroupName : $newGroupName;
419
420
        if (isset($groups[$newGroup])) {
421
            throw new \Exception(sprintf('%s form group already exists.', $newGroup));
422
        }
423
        if (!array_key_exists($group, $groups)) {
424
            throw new \Exception(sprintf('form group « %s » doesn\'t exist.', $group));
425
        }
426
427
        $groups[$newGroup] = $groups[$group];
428
        $groups[$newGroup]['name'] = $newGroupName;
429
        unset($groups[$group]);
430
431
        $tabs = $this->getFormTabs();
432
        $key = array_search($group, $tabs[$tab]['groups']);
433
434
        if (false !== $key) {
435
            $tabs[$tab]['groups'][$key] = $newGroup;
436
        }
437
438
        $this->setFormTabs($tabs);
0 ignored issues
show
Bug introduced by
It seems like $tabs defined by $this->getFormTabs() on line 431 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...
439
        $this->setFormGroups($groups);
0 ignored issues
show
Bug introduced by
It seems like $groups defined by $this->getFormGroups() on line 412 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...
440
441
        return $this;
442
    }
443
444
    /**
445
     * Removes tab in current form Mapper.
446
     *
447
     * @param string|array $tabNames name or array of names of tabs to be removed
448
     * @param FormMapper   $mapper   Sonata Admin form mapper
449
     */
450
    public function removeTab($tabNames, $mapper)
451
    {
452
        $currentTabs = $this->getFormTabs();
453
        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...
454
            if (is_array($tabNames) && in_array($item['name'], $tabNames) || !is_array($tabNames) && $item['name'] === $tabNames) {
455
                foreach ($item['groups'] as $groupName) {
456
                    $this->removeAllFieldsFromFormGroup($groupName, $mapper);
457
                }
458
                unset($currentTabs[$k]);
459
            }
460
        }
461
        $this->setFormTabs($currentTabs);
0 ignored issues
show
Bug introduced by
It seems like $currentTabs defined by $this->getFormTabs() on line 452 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...
462
    }
463
464
    /**
465
     * Removes all fields from form groups and remove them from mapper.
466
     *
467
     * @param string     $groupName Name of the group to remove
468
     * @param FormMapper $mapper    Sonata Admin form mapper
469
     */
470
    public function removeAllFieldsFromFormGroup($groupName, $mapper)
471
    {
472
        $formGroups = $this->getFormGroups();
473
        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...
474
            if ($name === $groupName) {
475
                foreach ($formGroups[$name]['fields'] as $key => $field) {
476
                    $mapper->remove($key);
477
                }
478
            }
479
        }
480
    }
481
482
    public function jsonSerialize()
483
    {
484
        $propertiesToShow = [
485
            'baseRouteName',
486
            'baseRoutePattern',
487
            'extraTemplates',
488
            'listFieldDescriptions',
489
            'showFieldDescriptions',
490
            'formFieldDescriptions',
491
            'filterFieldDescriptions',
492
            'maxPerPage',
493
            'maxPageLinks',
494
            'classnameLabel',
495
            'translationDomain',
496
            'formOptions',
497
            'datagridValues',
498
            'perPageOptions',
499
            'pagerType',
500
            'code',
501
            'label',
502
            'routes',
503
            'subject',
504
            'children',
505
            'parent',
506
            'baseCodeRoute',
507
            'uniqid',
508
            'extensions',
509
            'class',
510
            'subClasses',
511
            'list',
512
            'show',
513
            'form',
514
            'filter',
515
            'formGroups',
516
            'formTabs',
517
            'showGroups',
518
            'showTabs',
519
            'managedCollections',
520
            'helperLinks',
521
            'titles',
522
        ];
523
524
        $properties = [];
525
        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...
526
            if (in_array($key, $propertiesToShow)) {
527
                $properties[$key] = $value;
528
            }
529
        }
530
531
        return $properties;
532
    }
533
534
    /**
535
     * {@inheritdoc}
536
     */
537
    public function prePersist($object)
538
    {
539
        parent::prePersist($object);
540
541
        $hasCodeGenerator = CodeGeneratorRegistry::hasGeneratorForClass(get_class($object));
542
        if ($hasCodeGenerator) {
543
            $accessor = PropertyAccess::createPropertyAccessor();
544
            foreach (CodeGeneratorRegistry::getCodeGenerators(get_class($object)) as $name => $generator) {
545
                $accessor->setValue($object, $name, $generator->generate($object));
546
            }
547
        }
548
    }
549
}
550