From 8fb75a9e2d0f45d00cda15dcac2e869d25102d96 Mon Sep 17 00:00:00 2001 From: gylaandrij Date: Wed, 17 Oct 2018 12:11:54 +0300 Subject: [PATCH] refactors --- .gitignore | 1 + src/Configuration/EmbeddedListViewConfigPass.php | 4 ++-- src/Configuration/ExcludeFieldsConfigPass.php | 15 +++++++++++++-- src/Configuration/ListFormFiltersConfigPass.php | 12 ++++++------ src/Configuration/ShortFormTypeConfigPass.php | 12 +++++++----- src/Configuration/ShowViewConfigPass.php | 15 ++++++++++++--- .../Compiler/TwigPathPass.php | 4 ++-- src/EasyAdminExtensionBundle.php | 4 ++-- src/EventListener/PostQueryBuilderSubscriber.php | 8 ++++---- src/Form/Transformer/RestoreRolesTransformer.php | 4 ++-- src/Form/Type/EasyAdminEmbeddedListType.php | 15 ++++++++++++--- src/Form/Type/Security/AdminRolesType.php | 14 +++++++++++--- src/Helper/EditableRolesHelper.php | 2 +- src/Helper/EmbeddedListHelper.php | 6 +++--- src/Helper/ListFormFiltersHelper.php | 7 ++++--- src/Helper/MenuHelper.php | 14 ++++++++++++-- src/Resources/public/js/autocomplete-create.js | 6 ++++-- src/Resources/public/js/easyadmin-extension.js | 2 +- src/Twig/AdminAuthorizationExtension.php | 16 ++++++++++++---- src/Twig/EmbeddedListExtension.php | 11 ++++++++++- src/Twig/ListFormFiltersExtension.php | 11 ++++++++++- 21 files changed, 131 insertions(+), 52 deletions(-) diff --git a/.gitignore b/.gitignore index 7445b090..714016fd 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /composer.lock /docker-compose.yml /phpunit.xml +.idea \ No newline at end of file diff --git a/src/Configuration/EmbeddedListViewConfigPass.php b/src/Configuration/EmbeddedListViewConfigPass.php index d9cbaf30..44145307 100644 --- a/src/Configuration/EmbeddedListViewConfigPass.php +++ b/src/Configuration/EmbeddedListViewConfigPass.php @@ -56,11 +56,11 @@ private function processSortingConfig(array $backendConfig) $backendConfig['entities'][$entityName]['embeddedList']['sort'] = $entityConfig['list']['sort']; } elseif (isset($entityConfig['embeddedList']['sort'])) { $sortConfig = $entityConfig['embeddedList']['sort']; - if (!is_string($sortConfig) && !is_array($sortConfig)) { + if (!\is_string($sortConfig) && !\is_array($sortConfig)) { throw new \InvalidArgumentException(sprintf('The "sort" option of the "embeddedList" view of the "%s" entity contains an invalid value (it can only be a string or an array).', $entityName)); } - if (is_string($sortConfig)) { + if (\is_string($sortConfig)) { $sortConfig = array('field' => $sortConfig, 'direction' => 'DESC'); } else { $sortConfig = array('field' => $sortConfig[0], 'direction' => strtoupper($sortConfig[1])); diff --git a/src/Configuration/ExcludeFieldsConfigPass.php b/src/Configuration/ExcludeFieldsConfigPass.php index a3457566..96b688e3 100644 --- a/src/Configuration/ExcludeFieldsConfigPass.php +++ b/src/Configuration/ExcludeFieldsConfigPass.php @@ -23,6 +23,9 @@ class ExcludeFieldsConfigPass implements ConfigPassInterface * @param mixed[] $backendConfig * * @return mixed[] + * + * @throws ConflictingConfigurationException + * @throws \ReflectionException */ public function process(array $backendConfig): array { @@ -59,7 +62,10 @@ public function process(array $backendConfig): array } /** + * @param string $propertyName * @param string[] $excludedFields + * + * @return bool */ private function shouldSkipField(string $propertyName, array $excludedFields): bool { @@ -67,7 +73,7 @@ private function shouldSkipField(string $propertyName, array $excludedFields): b return true; } - return in_array($propertyName, $excludedFields, true); + return \in_array($propertyName, $excludedFields, true); } /** @@ -76,10 +82,12 @@ private function shouldSkipField(string $propertyName, array $excludedFields): b * @param mixed[] $entityConfig * @param string $entityName * @param string $section + * + * @throws ConflictingConfigurationException */ private function ensureFieldConfigurationIsValid(array $entityConfig, string $entityName, string $section) { - if (!isset($entityConfig[$section]['fields']) || !count($entityConfig[$section]['fields'])) { + if (!isset($entityConfig[$section]['fields']) || !\count($entityConfig[$section]['fields'])) { return; } @@ -93,8 +101,11 @@ private function ensureFieldConfigurationIsValid(array $entityConfig, string $en /** * @param mixed[] $entityConfig + * @param string $entityName * * @return string[] + * + * @throws \ReflectionException */ private function getPropertyNamesForEntity(array $entityConfig, string $entityName): array { diff --git a/src/Configuration/ListFormFiltersConfigPass.php b/src/Configuration/ListFormFiltersConfigPass.php index da2d4501..751d6275 100644 --- a/src/Configuration/ListFormFiltersConfigPass.php +++ b/src/Configuration/ListFormFiltersConfigPass.php @@ -41,7 +41,7 @@ public function process(array $backendConfig): array foreach ($entityConfig['list']['form_filters'] as $i => $formFilter) { // Detects invalid config node - if (!is_string($formFilter) && !is_array($formFilter)) { + if (!\is_string($formFilter) && !\is_array($formFilter)) { throw new \RuntimeException( sprintf( 'The values of the "form_filters" option for the list view of the "%s" entity can only be strings or arrays.', @@ -51,7 +51,7 @@ public function process(array $backendConfig): array } // Key mapping - if (is_string($formFilter)) { + if (\is_string($formFilter)) { $filterConfig = array('property' => $formFilter); } else { if (!array_key_exists('property', $formFilter)) { @@ -138,10 +138,10 @@ private function configureFieldFilter(string $entityClass, array $fieldMapping, } // Merge default type options when defined - if (isset($defaultFilterConfigTypeOptions)) { + if (null !== $defaultFilterConfigTypeOptions) { $filterConfig['type_options'] = array_merge( $defaultFilterConfigTypeOptions, - isset($filterConfig['type_options']) ? $filterConfig['type_options'] : array() + $filterConfig['type_options'] ?? array() ); } } @@ -157,7 +157,7 @@ private function configureAssociationFilter(string $entityClass, array $associat 'multiple' => true, 'attr' => array('data-widget' => 'select2'), ), - isset($filterConfig['type_options']) ? $filterConfig['type_options'] : array() + $filterConfig['type_options'] ?? array() ); } } @@ -182,7 +182,7 @@ private function getChoiceList(string $entityClass, string $property, array &$fi } $callableParams = array(); - if (is_string($filterConfig['type_options']['choices_static_callback'])) { + if (\is_string($filterConfig['type_options']['choices_static_callback'])) { $callable = array($entityClass, $filterConfig['type_options']['choices_static_callback']); } else { $callable = array($entityClass, $filterConfig['type_options']['choices_static_callback'][0]); diff --git a/src/Configuration/ShortFormTypeConfigPass.php b/src/Configuration/ShortFormTypeConfigPass.php index ba9486f0..345eb051 100644 --- a/src/Configuration/ShortFormTypeConfigPass.php +++ b/src/Configuration/ShortFormTypeConfigPass.php @@ -2,6 +2,8 @@ namespace AlterPHP\EasyAdminExtensionBundle\Configuration; +use AlterPHP\EasyAdminExtensionBundle\Form\Type\EasyAdminEmbeddedListType; +use AlterPHP\EasyAdminExtensionBundle\Form\Type\Security\AdminRolesType; use EasyCorp\Bundle\EasyAdminBundle\Configuration\ConfigPassInterface; /** @@ -17,8 +19,8 @@ class ShortFormTypeConfigPass implements ConfigPassInterface private static $configWithFormKeys = array('form', 'edit', 'new'); private static $nativeShortFormTypes = array( - 'embedded_list' => 'AlterPHP\EasyAdminExtensionBundle\Form\Type\EasyAdminEmbeddedListType', - 'admin_roles' => 'AlterPHP\EasyAdminExtensionBundle\Form\Type\Security\AdminRolesType', + 'embedded_list' => EasyAdminEmbeddedListType::class, + 'admin_roles' => AdminRolesType::class, ); public function __construct(array $customFormTypes = array()) @@ -37,7 +39,7 @@ protected function replaceShortNameTypes(array $backendConfig) { if ( !isset($backendConfig['entities']) - || !is_array($backendConfig['entities']) + || !\is_array($backendConfig['entities']) ) { return $backendConfig; } @@ -57,14 +59,14 @@ protected function replaceShortFormTypesInEntityConfig(array $entity) if ( isset($entity[$configWithFormKey]) && isset($entity[$configWithFormKey]['fields']) - && is_array($entity[$configWithFormKey]['fields']) + && \is_array($entity[$configWithFormKey]['fields']) ) { foreach ($entity[$configWithFormKey]['fields'] as $name => $field) { if (!isset($field['type'])) { continue; } - if (in_array($field['type'], array_keys($shortFormTypes))) { + if (array_key_exists($field['type'], $shortFormTypes)) { $entity[$configWithFormKey]['fields'][$name]['type'] = $shortFormTypes[$field['type']]; } } diff --git a/src/Configuration/ShowViewConfigPass.php b/src/Configuration/ShowViewConfigPass.php index 8c50451e..d2ebc953 100644 --- a/src/Configuration/ShowViewConfigPass.php +++ b/src/Configuration/ShowViewConfigPass.php @@ -2,6 +2,7 @@ namespace AlterPHP\EasyAdminExtensionBundle\Configuration; +use AlterPHP\EasyAdminExtensionBundle\Helper\EmbeddedListHelper; use EasyCorp\Bundle\EasyAdminBundle\Configuration\ConfigPassInterface; /** @@ -12,6 +13,9 @@ */ class ShowViewConfigPass implements ConfigPassInterface { + /** + * @var EmbeddedListHelper + */ private $embeddedListHelper; private static $mapTypeToTemplates = array( @@ -20,7 +24,12 @@ class ShowViewConfigPass implements ConfigPassInterface 'embedded_list' => '@EasyAdminExtension/default/field_embedded_list.html.twig', ); - public function __construct($embeddedListHelper) + /** + * ShowViewConfigPass constructor. + * + * @param EmbeddedListHelper $embeddedListHelper + */ + public function __construct(EmbeddedListHelper $embeddedListHelper) { $this->embeddedListHelper = $embeddedListHelper; } @@ -43,7 +52,7 @@ private function processCustomShowTypes(array $backendConfig) { foreach ($backendConfig['entities'] as $entityName => $entityConfig) { foreach ($entityConfig['show']['fields'] as $fieldName => $fieldMetadata) { - if (in_array($fieldMetadata['type'], array_keys(static::$mapTypeToTemplates))) { + if (array_key_exists($fieldMetadata['type'], static::$mapTypeToTemplates)) { $template = $this->isFieldTemplateDefined($fieldMetadata) ? $fieldMetadata['template'] : static::$mapTypeToTemplates[$fieldMetadata['type']]; @@ -64,7 +73,7 @@ private function processCustomShowTypes(array $backendConfig) private function isFieldTemplateDefined(array $fieldMetadata) { return isset($fieldMetadata['template']) - && '@EasyAdmin/default/label_undefined.html.twig' != $fieldMetadata['template']; + && '@EasyAdmin/default/label_undefined.html.twig' !== $fieldMetadata['template']; } private function processTemplateOptions(string $type, array $fieldMetadata) diff --git a/src/DependencyInjection/Compiler/TwigPathPass.php b/src/DependencyInjection/Compiler/TwigPathPass.php index 6e53d3de..c4f1e49c 100644 --- a/src/DependencyInjection/Compiler/TwigPathPass.php +++ b/src/DependencyInjection/Compiler/TwigPathPass.php @@ -17,7 +17,7 @@ public function process(ContainerBuilder $container) // Replaces native EasyAdmin templates $easyAdminExtensionBundleRefl = new \ReflectionClass(EasyAdminExtensionBundle::class); if ($easyAdminExtensionBundleRefl->isUserDefined()) { - $easyAdminExtensionBundlePath = dirname((string) $easyAdminExtensionBundleRefl->getFileName()); + $easyAdminExtensionBundlePath = \dirname((string) $easyAdminExtensionBundleRefl->getFileName()); $easyAdminExtensionTwigPath = $easyAdminExtensionBundlePath.'/Resources/views'; $twigLoaderFilesystemDefinition->addMethodCall( 'prependPath', @@ -27,7 +27,7 @@ public function process(ContainerBuilder $container) $nativeEasyAdminBundleRefl = new \ReflectionClass(EasyAdminBundle::class); if ($nativeEasyAdminBundleRefl->isUserDefined()) { - $nativeEasyAdminBundlePath = dirname((string) $nativeEasyAdminBundleRefl->getFileName()); + $nativeEasyAdminBundlePath = \dirname((string) $nativeEasyAdminBundleRefl->getFileName()); $nativeEasyAdminTwigPath = $nativeEasyAdminBundlePath.'/Resources/views'; // Defines a namespace from native EasyAdmin templates $twigLoaderFilesystemDefinition->addMethodCall( diff --git a/src/EasyAdminExtensionBundle.php b/src/EasyAdminExtensionBundle.php index 021f099d..ca3ffc59 100644 --- a/src/EasyAdminExtensionBundle.php +++ b/src/EasyAdminExtensionBundle.php @@ -32,13 +32,13 @@ private function addRegisterMappingsPass(ContainerBuilder $container) $easyAdminExtensionBundleRefl = new \ReflectionClass($this); if ($easyAdminExtensionBundleRefl->isUserDefined()) { - $easyAdminExtensionBundlePath = dirname((string) $easyAdminExtensionBundleRefl->getFileName()); + $easyAdminExtensionBundlePath = \dirname((string) $easyAdminExtensionBundleRefl->getFileName()); $easyAdminExtensionDoctrineMapping = $easyAdminExtensionBundlePath.'/Resources/config/doctrine-mapping'; $mappings = array( realpath($easyAdminExtensionDoctrineMapping) => 'AlterPHP\EasyAdminExtensionBundle\Model', ); - if (class_exists('Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass')) { + if (class_exists(DoctrineOrmMappingsPass::class)) { $container->addCompilerPass(DoctrineOrmMappingsPass::createXmlMappingDriver($mappings)); } } diff --git a/src/EventListener/PostQueryBuilderSubscriber.php b/src/EventListener/PostQueryBuilderSubscriber.php index ea5da944..256b46d9 100644 --- a/src/EventListener/PostQueryBuilderSubscriber.php +++ b/src/EventListener/PostQueryBuilderSubscriber.php @@ -63,7 +63,7 @@ protected function applyRequestFilters(QueryBuilder $queryBuilder, array $filter { foreach ($filters as $field => $value) { // Empty string and numeric keys is considered as "not applied filter" - if (is_int($field) || '' === $value) { + if (\is_int($field) || '' === $value) { continue; } // Add root entity alias if none provided @@ -90,7 +90,7 @@ protected function applyFormFilters(QueryBuilder $queryBuilder, array $filters = foreach ($filters as $field => $value) { $value = $this->filterEasyadminAutocompleteValue($value); // Empty string and numeric keys is considered as "not applied filter" - if (is_int($field) || '' === $value) { + if (\is_int($field) || '' === $value) { continue; } // Add root entity alias if none provided @@ -108,7 +108,7 @@ protected function applyFormFilters(QueryBuilder $queryBuilder, array $filters = private function filterEasyadminAutocompleteValue($value) { - if (!is_array($value) || !isset($value['autocomplete']) || 1 !== count($value)) { + if (!\is_array($value) || !isset($value['autocomplete']) || 1 !== \count($value)) { return $value; } @@ -126,7 +126,7 @@ private function filterEasyadminAutocompleteValue($value) protected function filterQueryBuilder(QueryBuilder $queryBuilder, string $field, string $parameter, $value) { // For multiple value, use an IN clause, equality otherwise - if (is_array($value)) { + if (\is_array($value)) { $filterDqlPart = $field.' IN (:'.$parameter.')'; } elseif ('_NULL' === $value) { $parameter = null; diff --git a/src/Form/Transformer/RestoreRolesTransformer.php b/src/Form/Transformer/RestoreRolesTransformer.php index a31a284c..ffa610c7 100644 --- a/src/Form/Transformer/RestoreRolesTransformer.php +++ b/src/Form/Transformer/RestoreRolesTransformer.php @@ -17,12 +17,12 @@ class RestoreRolesTransformer implements DataTransformerInterface /** * @var array|null */ - protected $originalRoles = null; + protected $originalRoles; /** * @var EditableRolesHelper|null */ - protected $rolesBuilder = null; + protected $rolesBuilder; /** * @param EditableRolesHelper $rolesBuilder diff --git a/src/Form/Type/EasyAdminEmbeddedListType.php b/src/Form/Type/EasyAdminEmbeddedListType.php index 01a114ae..04c7e8fd 100644 --- a/src/Form/Type/EasyAdminEmbeddedListType.php +++ b/src/Form/Type/EasyAdminEmbeddedListType.php @@ -2,6 +2,7 @@ namespace AlterPHP\EasyAdminExtensionBundle\Form\Type; +use AlterPHP\EasyAdminExtensionBundle\Helper\EmbeddedListHelper; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; @@ -10,9 +11,17 @@ class EasyAdminEmbeddedListType extends AbstractType { + /** + * @var EmbeddedListHelper + */ private $embeddedListHelper; - public function __construct($embeddedListHelper) + /** + * EasyAdminEmbeddedListType constructor. + * + * @param EmbeddedListHelper $embeddedListHelper + */ + public function __construct(EmbeddedListHelper $embeddedListHelper) { $this->embeddedListHelper = $embeddedListHelper; } @@ -36,11 +45,11 @@ public function buildView(FormView $view, FormInterface $form, array $options) $embeddedListFilters = $options['filters']; // Guess entity FQCN from parent metadata - $entityFqcn = $this->embeddedListHelper->getEntityFqcnFromParent(get_class($parentData), $form->getName()); + $entityFqcn = $this->embeddedListHelper->getEntityFqcnFromParent(\get_class($parentData), $form->getName()); if (null !== $entityFqcn) { $view->vars['entity_fqcn'] = $entityFqcn; // Guess embeddedList entity if not set - if (!isset($embeddedListEntity)) { + if (null === $embeddedListEntity) { $embeddedListEntity = $this->embeddedListHelper->guessEntityEntry($entityFqcn); } } diff --git a/src/Form/Type/Security/AdminRolesType.php b/src/Form/Type/Security/AdminRolesType.php index 098613e1..efa93bb9 100644 --- a/src/Form/Type/Security/AdminRolesType.php +++ b/src/Form/Type/Security/AdminRolesType.php @@ -3,6 +3,7 @@ namespace AlterPHP\EasyAdminExtensionBundle\Form\Type\Security; use AlterPHP\EasyAdminExtensionBundle\Form\Transformer\RestoreRolesTransformer; +use AlterPHP\EasyAdminExtensionBundle\Helper\EditableRolesHelper; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; @@ -22,9 +23,17 @@ */ class AdminRolesType extends AbstractType { + /** + * @var EditableRolesHelper + */ private $rolesBuilder; - public function __construct($editableRolesBuilder) + /** + * AdminRolesType constructor. + * + * @param $editableRolesBuilder + */ + public function __construct(EditableRolesHelper $editableRolesBuilder) { $this->rolesBuilder = $editableRolesBuilder; } @@ -75,9 +84,8 @@ public function configureOptions(OptionsResolver $resolver) if (!empty($parentChoices)) { return array(); } - $roles = $this->rolesBuilder->getRoles(); - return $roles; + return $this->rolesBuilder->getRoles(); }, 'multiple' => true, 'data_class' => null, diff --git a/src/Helper/EditableRolesHelper.php b/src/Helper/EditableRolesHelper.php index 1e43b704..02e53a74 100644 --- a/src/Helper/EditableRolesHelper.php +++ b/src/Helper/EditableRolesHelper.php @@ -53,7 +53,7 @@ public function getRoles() } $roles = array_map(function ($rolesGroup) { - if (is_array($rolesGroup)) { + if (\is_array($rolesGroup)) { $rolesGroup = array_combine($rolesGroup, $rolesGroup); } diff --git a/src/Helper/EmbeddedListHelper.php b/src/Helper/EmbeddedListHelper.php index a762beee..34175940 100644 --- a/src/Helper/EmbeddedListHelper.php +++ b/src/Helper/EmbeddedListHelper.php @@ -85,7 +85,7 @@ function ($entityConfig) use ($entityFqcn) { ); } - if (1 < count($matchingEntityConfigs)) { + if (1 < \count($matchingEntityConfigs)) { throw new \RuntimeException( sprintf('More than 1 entity defined in EasyAdmin configuration matches %s FQCN.', $entityFqcn) ); @@ -113,12 +113,12 @@ public function guessDefaultFilter(string $entityFqcn, string $parentEntityPrope } $entityAssociations = $entityClassMetadata->getAssociationMappings(); - $parentEntityFqcn = get_class($parentEntity); + $parentEntityFqcn = \get_class($parentEntity); foreach ($entityAssociations as $assoc) { // If association matches embeddedList relation if ($parentEntityFqcn === $assoc['targetEntity'] && $parentEntityProperty === $assoc['inversedBy']) { // OneToMany association - if (isset($assoc['joinColumns']) && 1 === count($assoc['joinColumns'])) { + if (isset($assoc['joinColumns']) && 1 === \count($assoc['joinColumns'])) { $assocFieldPart = 'entity.'.$assoc['fieldName']; $assocIdentifierValue = PropertyAccess::createPropertyAccessor()->getValue( $parentEntity, $assoc['joinColumns'][0]['referencedColumnName'] diff --git a/src/Helper/ListFormFiltersHelper.php b/src/Helper/ListFormFiltersHelper.php index f16ebff1..1854f942 100644 --- a/src/Helper/ListFormFiltersHelper.php +++ b/src/Helper/ListFormFiltersHelper.php @@ -29,7 +29,8 @@ class ListFormFiltersHelper private $listFiltersForm; /** - * @param FormFactory $formFactory + * @param FormFactory $formFactory + * @param RequestStack $requestStack */ public function __construct(FormFactory $formFactory, RequestStack $requestStack) { @@ -39,13 +40,13 @@ public function __construct(FormFactory $formFactory, RequestStack $requestStack public function getListFiltersForm(array $formFilters): FormInterface { - if (!isset($this->listFiltersForm)) { + if (null === $this->listFiltersForm) { $formBuilder = $this->formFactory->createNamedBuilder('form_filters'); foreach ($formFilters as $name => $config) { $formBuilder->add( $name, - isset($config['type']) ? $config['type'] : null, + $config['type'] ?? null, array_merge( array('required' => false), $config['type_options'] diff --git a/src/Helper/MenuHelper.php b/src/Helper/MenuHelper.php index 0ddac99c..0cc5d67f 100644 --- a/src/Helper/MenuHelper.php +++ b/src/Helper/MenuHelper.php @@ -2,13 +2,23 @@ namespace AlterPHP\EasyAdminExtensionBundle\Helper; +use AlterPHP\EasyAdminExtensionBundle\Security\AdminAuthorizationChecker; + /** * @author Pierre-Charles Bertineau */ class MenuHelper { + /** + * @var AdminAuthorizationChecker + */ protected $adminAuthorizationChecker; + /** + * MenuHelper constructor. + * + * @param $adminAuthorizationChecker + */ public function __construct($adminAuthorizationChecker) { $this->adminAuthorizationChecker = $adminAuthorizationChecker; @@ -27,7 +37,7 @@ protected function pruneAccessDeniedEntries(array $menuConfig, array $entitiesCo { foreach ($menuConfig as $key => $entry) { if ( - 'entity' == $entry['type'] + 'entity' === $entry['type'] && isset($entry['entity']) && !$this->adminAuthorizationChecker->isEasyAdminGranted( $entitiesConfig[$entry['entity']], @@ -38,7 +48,7 @@ protected function pruneAccessDeniedEntries(array $menuConfig, array $entitiesCo continue; } - if (isset($entry['children']) && is_array($entry['children'])) { + if (isset($entry['children']) && \is_array($entry['children'])) { $menuConfig[$key]['children'] = $this->pruneAccessDeniedEntries($entry['children'], $entitiesConfig); } } diff --git a/src/Resources/public/js/autocomplete-create.js b/src/Resources/public/js/autocomplete-create.js index 60ce213a..e1ca99c4 100644 --- a/src/Resources/public/js/autocomplete-create.js +++ b/src/Resources/public/js/autocomplete-create.js @@ -77,9 +77,11 @@ function initCreateEntityAjaxForm(field_name, select_id) { if (data.hasOwnProperty('option')) { $('#create-entity-modal').modal('hide'); var newOption = new Option(data.option.text, data.option.id, true, true); - $('#'+select_id).append(newOption).trigger('change'); + + var select_id = $('#'+select_id); + select_id.append(newOption).trigger('change'); // manually trigger the `select2:select` event - $('#'+select_id).trigger({ + select_id.trigger({ type: 'select2:select', params: { data: data.option } }); diff --git a/src/Resources/public/js/easyadmin-extension.js b/src/Resources/public/js/easyadmin-extension.js index e355df3c..03d67232 100644 --- a/src/Resources/public/js/easyadmin-extension.js +++ b/src/Resources/public/js/easyadmin-extension.js @@ -4,7 +4,7 @@ function reloadEmbeddedList(identifier, toggleBaseUrl) $(containerPrefix).find('table .toggle input[type="checkbox"]').each(function (idx, el) { $(this).bootstrapToggle(); - }) + }); // Reload sorted/paginated list in the embedded-list container $(containerPrefix) diff --git a/src/Twig/AdminAuthorizationExtension.php b/src/Twig/AdminAuthorizationExtension.php index e594999e..f4cf6ee4 100644 --- a/src/Twig/AdminAuthorizationExtension.php +++ b/src/Twig/AdminAuthorizationExtension.php @@ -2,16 +2,25 @@ namespace AlterPHP\EasyAdminExtensionBundle\Twig; +use AlterPHP\EasyAdminExtensionBundle\Helper\MenuHelper; +use AlterPHP\EasyAdminExtensionBundle\Security\AdminAuthorizationChecker; use Twig\Extension\AbstractExtension; use Twig\TwigFilter; use Twig\TwigFunction; class AdminAuthorizationExtension extends AbstractExtension { + /** + * @var AdminAuthorizationChecker + */ protected $adminAuthorizationChecker; + + /** + * @var MenuHelper + */ protected $menuHelper; - public function __construct($adminAuthorizationChecker, $menuHelper) + public function __construct(AdminAuthorizationChecker $adminAuthorizationChecker, MenuHelper $menuHelper) { $this->adminAuthorizationChecker = $adminAuthorizationChecker; $this->menuHelper = $menuHelper; @@ -41,9 +50,8 @@ public function pruneItemsActions( array $itemActions, array $entityConfig, array $forbiddenActions = [], $subject = null ) { return array_filter($itemActions, function ($action) use ($entityConfig, $forbiddenActions, $subject) { - return !in_array($action, $forbiddenActions) - && $this->isEasyAdminGranted($entityConfig, $action, $subject) - ; + return !\in_array($action, $forbiddenActions) + && $this->isEasyAdminGranted($entityConfig, $action, $subject); }, ARRAY_FILTER_USE_KEY); } diff --git a/src/Twig/EmbeddedListExtension.php b/src/Twig/EmbeddedListExtension.php index 47a3e3a9..1abcf964 100644 --- a/src/Twig/EmbeddedListExtension.php +++ b/src/Twig/EmbeddedListExtension.php @@ -2,14 +2,23 @@ namespace AlterPHP\EasyAdminExtensionBundle\Twig; +use AlterPHP\EasyAdminExtensionBundle\Helper\EmbeddedListHelper; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; class EmbeddedListExtension extends AbstractExtension { + /** + * @var EmbeddedListHelper + */ protected $embeddedListHelper; - public function __construct($embeddedListHelper) + /** + * EmbeddedListExtension constructor. + * + * @param EmbeddedListHelper $embeddedListHelper + */ + public function __construct(EmbeddedListHelper $embeddedListHelper) { $this->embeddedListHelper = $embeddedListHelper; } diff --git a/src/Twig/ListFormFiltersExtension.php b/src/Twig/ListFormFiltersExtension.php index 05b349d3..7d598eef 100644 --- a/src/Twig/ListFormFiltersExtension.php +++ b/src/Twig/ListFormFiltersExtension.php @@ -2,14 +2,23 @@ namespace AlterPHP\EasyAdminExtensionBundle\Twig; +use AlterPHP\EasyAdminExtensionBundle\Helper\ListFormFiltersHelper; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; class ListFormFiltersExtension extends AbstractExtension { + /** + * @var ListFormFiltersHelper + */ protected $listFiltersHelper; - public function __construct($listFiltersHelper) + /** + * ListFormFiltersExtension constructor. + * + * @param ListFormFiltersHelper $listFiltersHelper + */ + public function __construct(ListFormFiltersHelper $listFiltersHelper) { $this->listFiltersHelper = $listFiltersHelper; }