Skip to content

Commit

Permalink
Merge c5f5fe2 into 5d60b75
Browse files Browse the repository at this point in the history
  • Loading branch information
gulaandrij authored Oct 18, 2018
2 parents 5d60b75 + c5f5fe2 commit 3b1ea80
Show file tree
Hide file tree
Showing 20 changed files with 128 additions and 51 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/composer.lock
/docker-compose.yml
/phpunit.xml
.idea
4 changes: 2 additions & 2 deletions src/Configuration/EmbeddedListViewConfigPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
Expand Down
15 changes: 13 additions & 2 deletions src/Configuration/ExcludeFieldsConfigPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class ExcludeFieldsConfigPass implements ConfigPassInterface
* @param mixed[] $backendConfig
*
* @return mixed[]
*
* @throws ConflictingConfigurationException
* @throws \ReflectionException
*/
public function process(array $backendConfig): array
{
Expand Down Expand Up @@ -59,15 +62,18 @@ public function process(array $backendConfig): array
}

/**
* @param string $propertyName
* @param string[] $excludedFields
*
* @return bool
*/
private function shouldSkipField(string $propertyName, array $excludedFields): bool
{
if ('id' === $propertyName) {
return true;
}

return in_array($propertyName, $excludedFields, true);
return \in_array($propertyName, $excludedFields, true);
}

/**
Expand All @@ -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;
}

Expand All @@ -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
{
Expand Down
12 changes: 6 additions & 6 deletions src/Configuration/ListFormFiltersConfigPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand All @@ -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)) {
Expand Down Expand Up @@ -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()
);
}
}
Expand All @@ -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()
);
}
}
Expand All @@ -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]);
Expand Down
12 changes: 7 additions & 5 deletions src/Configuration/ShortFormTypeConfigPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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())
Expand All @@ -37,7 +39,7 @@ protected function replaceShortNameTypes(array $backendConfig)
{
if (
!isset($backendConfig['entities'])
|| !is_array($backendConfig['entities'])
|| !\is_array($backendConfig['entities'])
) {
return $backendConfig;
}
Expand All @@ -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']];
}
}
Expand Down
15 changes: 12 additions & 3 deletions src/Configuration/ShowViewConfigPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace AlterPHP\EasyAdminExtensionBundle\Configuration;

use AlterPHP\EasyAdminExtensionBundle\Helper\EmbeddedListHelper;
use EasyCorp\Bundle\EasyAdminBundle\Configuration\ConfigPassInterface;

/**
Expand All @@ -12,6 +13,9 @@
*/
class ShowViewConfigPass implements ConfigPassInterface
{
/**
* @var EmbeddedListHelper
*/
private $embeddedListHelper;

private static $mapTypeToTemplates = array(
Expand All @@ -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;
}
Expand All @@ -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']];
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/Compiler/TwigPathPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/EasyAdminExtensionBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/EventListener/PostQueryBuilderSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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;
}

Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Form/Transformer/RestoreRolesTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions src/Form/Type/EasyAdminEmbeddedListType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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);
}
}
Expand Down
14 changes: 11 additions & 3 deletions src/Form/Type/Security/AdminRolesType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,9 +23,17 @@
*/
class AdminRolesType extends AbstractType
{
/**
* @var EditableRolesHelper
*/
private $rolesBuilder;

public function __construct($editableRolesBuilder)
/**
* AdminRolesType constructor.
*
* @param EditableRolesHelper $editableRolesBuilder
*/
public function __construct(EditableRolesHelper $editableRolesBuilder)
{
$this->rolesBuilder = $editableRolesBuilder;
}
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/Helper/EditableRolesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Loading

0 comments on commit 3b1ea80

Please sign in to comment.