Skip to content

Commit

Permalink
added fa_at to input group
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Wagner committed May 2, 2018
1 parent 64ab560 commit 8596b01
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 89 deletions.
6 changes: 3 additions & 3 deletions src/Choice/TemplateChoice.php
Expand Up @@ -19,7 +19,7 @@ class TemplateChoice extends AbstractChoice
protected function collect()
{
$choices = [];
$config = System::getContainer()->getParameter('huh.filter');
$config = System::getContainer()->getParameter('huh.filter');

if (isset($config['filter']['template_prefixes'])) {
$choices = System::getContainer()->get('huh.utils.choice.twig_template')->setContext($config['filter']['template_prefixes'])->getCachedChoices();
Expand All @@ -28,11 +28,11 @@ protected function collect()
if (isset($config['filter']['templates'])) {
foreach ($config['filter']['templates'] as $template) {
// remove duplicates returned by `huh.utils.choice.twig_template`
if (false !== ($idx = array_search($template['template'], $choices))) {
if (false !== ($idx = array_search($template['template'], $choices, true))) {
unset($choices[$idx]);
}

$choices[$template['name']] = $template['template'] . ' (Yaml)';
$choices[$template['name']] = $template['template'].' (Yaml)';
}
}

Expand Down
41 changes: 19 additions & 22 deletions src/Config/FilterConfig.php
Expand Up @@ -389,6 +389,25 @@ public function addContextualValue($elementId, $values)
$this->queryBuilder->addContextualValue($elementId, $values);
}

public function getFilterTemplateByName(string $name)
{
$config = System::getContainer()->getParameter('huh.filter');

if (!isset($config['filter']['templates'])) {
return System::getContainer()->get('huh.utils.template')->getTemplate($name);
}

$templates = $config['filter']['templates'];

foreach ($templates as $template) {
if ($template['name'] === $name) {
return $template['template'];
}
}

return System::getContainer()->get('huh.utils.template')->getTemplate($name);
}

/**
* Get the redirect url based on current filter action.
*
Expand Down Expand Up @@ -450,26 +469,4 @@ protected function mapFormsToData()

$this->builder->setData($data);
}

/**
* {@inheritdoc}
*/
public function getFilterTemplateByName(string $name)
{
$config = System::getContainer()->getParameter('huh.filter');

if (!isset($config['filter']['templates'])) {
return System::getContainer()->get('huh.utils.template')->getTemplate($name);
}

$templates = $config['filter']['templates'];

foreach ($templates as $template) {
if ($template['name'] == $name) {
return $template['template'];
}
}

return System::getContainer()->get('huh.utils.template')->getTemplate($name);
}
}
8 changes: 4 additions & 4 deletions src/Manager/FilterManager.php
Expand Up @@ -38,12 +38,12 @@ class FilterManager
* Constructor.
*
* @param ContaoFrameworkInterface $framework
* @param FilterSession $session
* @param FilterSession $session
*/
public function __construct(ContaoFrameworkInterface $framework, FilterSession $session)
{
$this->framework = $framework;
$this->session = $session;
$this->session = $session;
}

/**
Expand Down Expand Up @@ -74,13 +74,13 @@ public function getQueryBuilder(int $id)
*/
public function getSessionKey(array $filter)
{
return 'huh.filter.session.' . $filter['name'] ?: $filter['id'];
return 'huh.filter.session.'.$filter['name'] ?: $filter['id'];
}

/**
* Find filter by id.
*
* @param int $id
* @param int $id
* @param bool $cache Disable for a fresh filter/querybuilder instance
*
* @return FilterConfig|null The config or null if not found
Expand Down
16 changes: 7 additions & 9 deletions src/Module/ModuleFilter.php
Expand Up @@ -12,8 +12,6 @@
use HeimrichHannot\FilterBundle\Config\FilterConfig;
use HeimrichHannot\FilterBundle\Manager\FilterManager;
use Patchwork\Utf8;
use Urodoz\Truncate\Bridge\Twig\TruncateExtension;
use Urodoz\Truncate\TruncateService;

class ModuleFilter extends \Contao\Module
{
Expand All @@ -27,12 +25,12 @@ class ModuleFilter extends \Contao\Module
public function generate()
{
if (TL_MODE === 'BE') {
$objTemplate = new \BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### ' . Utf8::strtoupper($GLOBALS['TL_LANG']['FMD'][$this->type][0]) . ' ###';
$objTemplate->title = $this->headline;
$objTemplate->id = $this->id;
$objTemplate->link = $this->name;
$objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id;
$objTemplate = new \BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### '.Utf8::strtoupper($GLOBALS['TL_LANG']['FMD'][$this->type][0]).' ###';
$objTemplate->title = $this->headline;
$objTemplate->id = $this->id;
$objTemplate->link = $this->name;
$objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id='.$this->id;

return $objTemplate->parse();
}
Expand Down Expand Up @@ -75,7 +73,7 @@ protected function compile()
$this->config->getFilterTemplateByName($filter['template']),
[
'filter' => $this->config,
'form' => $form->createView(),
'form' => $form->createView(),
]
);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Resources/translations/messages.de.yml
Expand Up @@ -21,6 +21,8 @@ huh.filter.label.reset: Zurücksetzen
huh.filter.input_group_text.fa_clock_o: '<span class="fa fa-clock-o"></span>'
huh.filter.input_group_text.fa_calendar: '<span class="fa fa-calendar"></span>'
huh.filter.input_group_text.fa_envelope: '<span class="fa fa-envelope"></span>'
huh.filter.input_group_text.fa_at: '<span class="fa fa-at"></span>'
huh.filter.input_group_text.button.fa_at: '<button class="btn btn-outline-secondary" type="button"><i class="fa fa-at"></i></button>'
huh.filter.input_group_text.button.fa_clock_o: '<button class="btn btn-outline-secondary" type="button"><i class="fa fa-clock-o"></i></button>'
huh.filter.input_group_text.button.fa_calendar: '<button class="btn btn-outline-secondary" type="button"><i class="fa fa-calendar"></i></button>'
huh.filter.input_group_text.button.fa_envelope: '<button class="btn btn-outline-secondary" type="button"><i class="fa fa-envelope"></i></button>'
huh.filter.input_group_text.button.fa_envelope: '<button class="btn btn-outline-secondary" type="button"><i class="fa fa-envelope"></i></button>'
4 changes: 3 additions & 1 deletion src/Resources/translations/messages.en.yml
Expand Up @@ -18,4 +18,6 @@ huh.filter.label.reset: Reset
# input group append/prepend text
huh.filter.input_group_text.fa_clock_o: '<span class="fa fa-clock-o"></span>'
huh.filter.input_group_text.fa_calendar: '<span class="fa fa-calendar"></span>'
huh.filter.input_group_text.fa_envelope: '<span class="fa fa-envelope"></span>'
huh.filter.input_group_text.fa_envelope: '<span class="fa fa-envelope"></span>'
huh.filter.input_group_text.fa_at: '<span class="fa fa-at"></span>'

36 changes: 18 additions & 18 deletions tests/Choice/TemplateChoiceTest.php
Expand Up @@ -57,7 +57,7 @@ public function setUp(): void

$containerBuilder = new \Contao\ManagerPlugin\Config\ContainerBuilder($this->mockPluginLoader($this->never()), []);

$config = $plugin->getExtensionConfig('huh_filter', [[]], $containerBuilder);
$config = $plugin->getExtensionConfig('huh_filter', [[]], $containerBuilder);
$this->config['filter'] = $config['huh']['filter'];
}

Expand All @@ -72,7 +72,7 @@ public function testCanBeInstantiated()
System::setContainer($this->container);

$framework = $this->mockContaoFramework();
$instance = new TemplateChoice($framework);
$instance = new TemplateChoice($framework);

$this->assertInstanceOf('HeimrichHannot\FilterBundle\Choice\TemplateChoice', $instance);
}
Expand All @@ -88,8 +88,8 @@ public function testCollectWithoutTypes()
System::setContainer($this->container);

$framework = $this->mockContaoFramework();
$instance = new TemplateChoice($framework);
$choices = $instance->getChoices();
$instance = new TemplateChoice($framework);
$choices = $instance->getChoices();

System::setContainer($this->container);

Expand Down Expand Up @@ -121,7 +121,7 @@ public function testCollectWithExistingTypesWithoutContext()
System::setContainer($this->container);

$instance = new TemplateChoice($framework);
$choices = $instance->getChoices();
$choices = $instance->getChoices();

$this->assertNotEmpty($choices);
$this->assertArrayHasKey('form_div_layout', $choices);
Expand All @@ -147,7 +147,7 @@ public function testCollectWithExistingTypesWithoutContext()
*/
public function testCollectWithExistingTypeWithMissingClassWithoutContext()
{
$config = $this->config;
$config = $this->config;
$config['filter']['types'][0]['class'] = '_NonExistingNamespace\NonExistingClass';

$this->container->set('kernel', $this->kernel);
Expand All @@ -156,8 +156,8 @@ public function testCollectWithExistingTypeWithMissingClassWithoutContext()
System::setContainer($this->container);

$framework = $this->mockContaoFramework();
$instance = new TypeChoice($framework);
$choices = $instance->getChoices();
$instance = new TypeChoice($framework);
$choices = $instance->getChoices();

$this->assertNotEmpty($choices);
$this->assertArrayNotHasKey('text', $choices);
Expand All @@ -174,7 +174,7 @@ public function testCollectWithExistingTypesWithDataContainerContext()
System::setContainer($this->container);

$framework = $this->mockContaoFramework();
$instance = new TypeChoice($framework);
$instance = new TypeChoice($framework);

$dataContainerMock = $this->createMock(DataContainer::class);

Expand All @@ -191,11 +191,19 @@ public function testCollectWithExistingTypesWithDataContainerContext()
$this->assertSame('visible', $choices['other'][0]);
}

/**
* @return string
*/
protected function getFixturesDir(): string
{
return __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Fixtures';
}

/**
* Mocks the plugin loader.
*
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $expects
* @param array $plugins
* @param array $plugins
*
* @return PluginLoader|\PHPUnit_Framework_MockObject_MockObject
*/
Expand All @@ -207,12 +215,4 @@ private function mockPluginLoader(\PHPUnit_Framework_MockObject_Matcher_InvokedC

return $pluginLoader;
}

/**
* @return string
*/
protected function getFixturesDir(): string
{
return __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Fixtures';
}
}

0 comments on commit 8596b01

Please sign in to comment.