Skip to content

Commit

Permalink
Only start the session if needed to find data in FORM_DATA (see #1471).
Browse files Browse the repository at this point in the history
Description
-----------

-

Commits
-------

b96c8da Only start the session if needed to find data in FORM_DATA
4e6d7cc Fix the coding style and the unit tests.
  • Loading branch information
Toflar authored and leofeyer committed Apr 11, 2018
1 parent 88d55fc commit c8b298c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Resources/contao/library/Contao/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,14 @@ public static function findPost($strKey)
return $_POST[$strKey];
}

$request = System::getContainer()->get('request_stack')->getMasterRequest();

// Return if the session has not been started before
if ($request === null || !$request->hasPreviousSession())
{
return null;
}

if (isset($_SESSION['FORM_DATA'][$strKey]))
{
return ($strKey == 'FORM_SUBMIT') ? preg_replace('/^auto_/i', '', $_SESSION['FORM_DATA'][$strKey]) : $_SESSION['FORM_DATA'][$strKey];
Expand Down
8 changes: 8 additions & 0 deletions tests/Contao/WidgetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
namespace Contao\CoreBundle\Tests\Contao;

use Contao\Input;
use Contao\System;
use Contao\Widget;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpFoundation\RequestStack;

/**
* @group contao3
Expand Down Expand Up @@ -44,6 +47,11 @@ public function setUp(): void
parent::setUp();

\define('TL_MODE', 'FE');

$container = new ContainerBuilder();
$container->set('request_stack', new RequestStack());

System::setContainer($container);
}

/**
Expand Down

0 comments on commit c8b298c

Please sign in to comment.