Skip to content

Commit

Permalink
fixed translation, text concat issue, readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Patzer committed Apr 10, 2018
1 parent 5bbc852 commit 9d08b50
Show file tree
Hide file tree
Showing 84 changed files with 3,094 additions and 3,238 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -17,7 +17,7 @@ Replace `categories` with the name of your custom field. Remove `onchange` handl
Select fallback can be used on small devices, if too many options, display/hide, using `@media` breakpoints.

```
{% if(form.categories|default()) %}
{% if(form.categories is defined) %}
<div class="disable-hidden-inputs {{ ('form-group' ~ ' ' ~ form.categories.vars.id ~ ' ' ~ form.categories.vars.name ~ ' ' ~ form.categories.vars.attr.class)|trim }}">
{{ form_label(form.categories) }}
{% do form.categories.setRendered %}
Expand Down
7 changes: 3 additions & 4 deletions src/Choice/ElementChoice.php
Expand Up @@ -33,7 +33,7 @@ protected function collect()
$context['types'] = isset($context['types']) && is_array($context['types']) ? $context['types'] : [];

/**
* @var $adapter FilterConfigElementModel
* @var FilterConfigElementModel
*/
$adapter = $this->framework->getAdapter(FilterConfigElementModel::class);

Expand All @@ -45,9 +45,8 @@ protected function collect()
return $choices;
}

foreach ($elements as $element)
{
$choices[$element->id] = $element->name . ' [' . $element->type . ']';
foreach ($elements as $element) {
$choices[$element->id] = $element->name.' ['.$element->type.']';
}

return $choices;
Expand Down
26 changes: 13 additions & 13 deletions src/Choice/FieldOptionsChoice.php
Expand Up @@ -31,7 +31,7 @@ protected function collect()
}

$element = $context['element'];
$filter = $context['filter'];
$filter = $context['filter'];

$options = [];

Expand All @@ -48,7 +48,7 @@ protected function collect()
return $choices;
}

if (true === (bool)$element->customOptions) {
if (true === (bool) $element->customOptions) {
$options = $this->getCustomOptions($element, $filter);
} elseif (isset($GLOBALS['TL_DCA'][$filter['dataContainer']]['fields'][$element->field])) {
$options = $this->getDcaOptions($element, $filter,
Expand Down Expand Up @@ -77,7 +77,7 @@ protected function collect()
* Get custom options.
*
* @param FilterConfigElementModel $element
* @param array $filter
* @param array $filter
*
* @return array
*/
Expand All @@ -96,15 +96,15 @@ protected function getCustomOptions(FilterConfigElementModel $element, array $fi
* Get contao dca widget options.
*
* @param FilterConfigElementModel $element
* @param array $filter
* @param array $dca
* @param array $filter
* @param array $dca
*
* @return array
*/
protected function getDcaOptions(FilterConfigElementModel $element, array $filter, array $dca)
{
$options = [];
$dca = $GLOBALS['TL_DCA'][$filter['dataContainer']]['fields'][$element->field];
$dca = $GLOBALS['TL_DCA'][$filter['dataContainer']]['fields'][$element->field];

if (isset($dca['eval']['isCategoryField']) && $dca['eval']['isCategoryField']) {
$options = $this->getCategoryWidgetOptions($element, $filter, $dca);
Expand Down Expand Up @@ -134,8 +134,8 @@ protected function getDcaOptions(FilterConfigElementModel $element, array $filte
* Get default contao widget options.
*
* @param FilterConfigElementModel $element
* @param array $filter
* @param array $dca
* @param array $filter
* @param array $dca
*
* @return array
*/
Expand Down Expand Up @@ -173,8 +173,8 @@ protected function getWidgetOptions(FilterConfigElementModel $element, array $fi
* Get tag widget options.
*
* @param FilterConfigElementModel $element
* @param array $filter
* @param array $dca
* @param array $filter
* @param array $dca
*
* @return array
*/
Expand All @@ -187,7 +187,7 @@ protected function getTagWidgetOptions(FilterConfigElementModel $element, array
}

/**
* @var $tagsManager \Codefog\TagsBundle\Manager\ManagerInterface
* @var \Codefog\TagsBundle\Manager\ManagerInterface
*/
$tagsManager = System::getContainer()->get('codefog_tags.manager_registry')->get(
$dca['eval']['tagsManager']
Expand All @@ -211,8 +211,8 @@ protected function getTagWidgetOptions(FilterConfigElementModel $element, array
* Get category widget options.
*
* @param FilterConfigElementModel $element
* @param array $filter
* @param array $dca
* @param array $filter
* @param array $dca
*
* @return array
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Choice/TypeChoice.php
Expand Up @@ -40,7 +40,7 @@ protected function collect()
}

if ($groupChoices) {
$group = $type['type'];
$group = $type['type'];
$choices[$group][] = $type['name'];
continue;
}
Expand Down
91 changes: 46 additions & 45 deletions src/Config/FilterConfig.php
Expand Up @@ -11,13 +11,13 @@
use Contao\CoreBundle\Framework\ContaoFrameworkInterface;
use Contao\InsertTags;
use Contao\System;
use HeimrichHannot\FilterBundle\Session\FilterSession;
use HeimrichHannot\FilterBundle\Filter\AbstractType;
use HeimrichHannot\FilterBundle\Form\Extension\FormButtonExtension;
use HeimrichHannot\FilterBundle\Form\Extension\FormTypeExtension;
use HeimrichHannot\FilterBundle\Form\FilterType;
use HeimrichHannot\FilterBundle\Model\FilterConfigElementModel;
use HeimrichHannot\FilterBundle\QueryBuilder\FilterQueryBuilder;
use HeimrichHannot\FilterBundle\Session\FilterSession;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Forms;
Expand Down Expand Up @@ -70,27 +70,27 @@ class FilterConfig
* Constructor.
*
* @param ContaoFrameworkInterface $framework
* @param FilterSession $session
* @param FilterSession $session
*/
public function __construct(ContaoFrameworkInterface $framework, FilterSession $session, FilterQueryBuilder $queryBuilder)
{
$this->framework = $framework;
$this->session = $session;
$this->framework = $framework;
$this->session = $session;
$this->queryBuilder = $queryBuilder;
}

/**
* Init the filter based on its model.
*
* @param string $sessionKey
* @param array $filter
* @param string $sessionKey
* @param array $filter
* @param \Contao\Model\Collection|FilterConfigElementModel[]|null $elements
*/
public function init(string $sessionKey, array $filter, $elements = null)
{
$this->sessionKey = $sessionKey;
$this->filter = $filter;
$this->elements = $elements;
$this->filter = $filter;
$this->elements = $elements;
}

/**
Expand Down Expand Up @@ -122,7 +122,7 @@ public function buildForm(array $data = [])
$options['attr']['class'] = implode(' ', $cssClass);
}

if (isset($this->filter['renderEmpty']) && true === (bool)$this->filter['renderEmpty']) {
if (isset($this->filter['renderEmpty']) && true === (bool) $this->filter['renderEmpty']) {
$data = [];
}

Expand Down Expand Up @@ -151,8 +151,8 @@ public function initQueryBuilder()
}

$config = $types[$element->type];
$class = $config['class'];
$skip = $this->queryBuilder->getSkip();
$class = $config['class'];
$skip = $this->queryBuilder->getSkip();

if (!class_exists($class) || isset($skip[$element->id])) {
continue;
Expand All @@ -171,6 +171,7 @@ public function initQueryBuilder()

/**
* @param mixed $request The request to handle
*
* @return RedirectResponse|null
*/
public function handleForm($request = null): ?RedirectResponse
Expand Down Expand Up @@ -203,12 +204,12 @@ public function handleForm($request = null): ?RedirectResponse
}

// form id must match
if ((int)$form->get(FilterType::FILTER_ID_NAME)->getData() !== $this->getId()) {
if ((int) $form->get(FilterType::FILTER_ID_NAME)->getData() !== $this->getId()) {
return null;
}

$data = $form->getData();
$url = System::getContainer()->get('huh.utils.url')->removeQueryString([$form->getName()], $url ?: null);
$url = System::getContainer()->get('huh.utils.url')->removeQueryString([$form->getName()], $url ?: null);

// do not save filter id in session
$this->setData($data);
Expand All @@ -226,32 +227,6 @@ public function handleForm($request = null): ?RedirectResponse
return null;
}

/**
* Get the redirect url based on current filter action.
*
* @return string
*/
protected function getUrl()
{
$filter = $this->getFilter();

if (!isset($filter['action'])) {
return '';
}

/**
* @var InsertTags
*/
$insertTagAdapter = $this->framework->createInstance(InsertTags::class);

// while unit testing, the mock object cant be instantiated
if (null === $insertTagAdapter) {
$insertTagAdapter = $this->framework->getAdapter(InsertTags::class);
}

return '/' . urldecode($insertTagAdapter->replace($filter['action']));
}

/**
* @return int|null
*/
Expand All @@ -271,8 +246,8 @@ public function getFilter()
/**
* Get a specific element by its value.
*
* @param mixed $value The to search within $key
* @param string $key The array key
* @param mixed $value The to search within $key
* @param string $key The array key
*
* @return FilterConfigElementModel|null
*/
Expand All @@ -287,7 +262,7 @@ public function getElementByValue($value, $key = 'id')
}

foreach ($this->getElements() as $element) {
if (null === $element->{$key} || (string)$element->{$key} !== (string)$value) {
if (null === $element->{$key} || (string) $element->{$key} !== (string) $value) {
continue;
}

Expand Down Expand Up @@ -414,21 +389,47 @@ public function addContextualValue($elementId, $values)
$this->queryBuilder->addContextualValue($elementId, $values);
}

/**
* Get the redirect url based on current filter action.
*
* @return string
*/
protected function getUrl()
{
$filter = $this->getFilter();

if (!isset($filter['action'])) {
return '';
}

/**
* @var InsertTags
*/
$insertTagAdapter = $this->framework->createInstance(InsertTags::class);

// while unit testing, the mock object cant be instantiated
if (null === $insertTagAdapter) {
$insertTagAdapter = $this->framework->getAdapter(InsertTags::class);
}

return '/'.urldecode($insertTagAdapter->replace($filter['action']));
}

/**
* Maps the data of the current forms and update builder data.
*/
protected function mapFormsToData()
{
$data = [];
$forms = $this->builder->getForm();
$data = [];
$forms = $this->builder->getForm();
$propertyAccessor = PropertyAccess::createPropertyAccessor();

/*
* @var FormInterface
*/
foreach ($forms as $form) {
$propertyPath = $form->getPropertyPath();
$config = $form->getConfig();
$config = $form->getConfig();

// Write-back is disabled if the form is not synchronized (transformation failed),
// if the form was not submitted and if the form is disabled (modification not allowed)
Expand Down
10 changes: 5 additions & 5 deletions src/ContaoManager/Plugin.php
Expand Up @@ -36,8 +36,8 @@ public function getBundles(ParserInterface $parser)
/**
* Allows a plugin to override extension configuration.
*
* @param string $extensionName
* @param array $extensionConfigs
* @param string $extensionName
* @param array $extensionConfigs
* @param ContainerBuilder $container
*
* @return
Expand All @@ -58,7 +58,7 @@ public function getExtensionConfig($extensionName, array $extensionConfigs, Cont
'huh_filter',
$extensionName,
$extensionConfigs,
__DIR__ . '/../Resources/config/config.yml'
__DIR__.'/../Resources/config/config.yml'
);
}

Expand All @@ -68,7 +68,7 @@ public function getExtensionConfig($extensionName, array $extensionConfigs, Cont
public function getRouteCollection(LoaderResolverInterface $resolver, KernelInterface $kernel): ?RouteCollection
{
return $resolver
->resolve(__DIR__ . '/../Resources/config/routing.yml')
->load(__DIR__ . '/../Resources/config/routing.yml');
->resolve(__DIR__.'/../Resources/config/routing.yml')
->load(__DIR__.'/../Resources/config/routing.yml');
}
}

0 comments on commit 9d08b50

Please sign in to comment.