From 896299bc4d9a458883fe2ee8ee677f965ca9050f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sat, 19 Oct 2019 23:20:19 +0200 Subject: [PATCH] Allow to specify homepage banner via ENV. Otherwise the content of the file config/banner.md is used. --- .env | 4 ++++ config/banner.md | 3 +++ config/services.yaml | 2 +- src/Controller/HomepageController.php | 29 ++++++++++++++++++++++++++- 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 config/banner.md diff --git a/.env b/.env index 87be6efe..0876a707 100644 --- a/.env +++ b/.env @@ -43,4 +43,8 @@ FIXER_API_KEY=CHANGEME # In that case all URL contains the index.php front controller in URL NO_URL_REWRITE_AVAILABLE=false +# Override value if you want to show to show a given text on homepage. +# When this is empty the content of config/banner.md is used as banner +BANNER="" + ### End custom vars \ No newline at end of file diff --git a/config/banner.md b/config/banner.md new file mode 100644 index 00000000..74b1d526 --- /dev/null +++ b/config/banner.md @@ -0,0 +1,3 @@ +Welcome to Part-DB. + +If you want to change this banner, edit `config/banner.md` file or set the `BANNER` environment variable. \ No newline at end of file diff --git a/config/services.yaml b/config/services.yaml index 4dc13d96..d652dbcc 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -8,7 +8,7 @@ parameters: locale: 'en' # Set the default language to use her timezone: 'Europe/Berlin' partdb_title: 'Part-DB' # The title shown inside of Part-DB (e.g. in the navbar and on homepage) - banner: '' # The info text shown in the homepage + banner: '%env(trim:string:BANNER)%' # The info text shown in the homepage, if empty config/banner.md is used use_gravatar: true # Set to false, if no Gravatar images should be used for user profiles. default_currency: 'EUR' # The currency that should be used media_directory: 'public/media/' # The folder where uploaded attachment files are saved diff --git a/src/Controller/HomepageController.php b/src/Controller/HomepageController.php index 0fa28651..a3cafc64 100644 --- a/src/Controller/HomepageController.php +++ b/src/Controller/HomepageController.php @@ -31,18 +31,45 @@ namespace App\Controller; use App\Services\GitVersionInfo; +use SebastianBergmann\CodeCoverage\Node\File; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\Cache\CacheItem; +use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Routing\Annotation\Route; +use Symfony\Contracts\Cache\CacheInterface; class HomepageController extends AbstractController { + protected $cache; + protected $kernel; + + public function __construct(CacheInterface $cache, KernelInterface $kernel) + { + $this->cache = $cache; + $this->kernel = $kernel; + } + + public function getBanner() : string + { + $banner = $this->getParameter('banner'); + if (empty($banner)) { + $banner_path = $this->kernel->getProjectDir() + . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'banner.md'; + + return file_get_contents($banner_path); + } + + return $banner; + } + /** * @Route("/", name="homepage") */ public function homepage(GitVersionInfo $versionInfo) { return $this->render('homepage.html.twig', [ - 'banner' => $this->getParameter('banner'), + 'banner' => $this->getBanner(), 'git_branch' => $versionInfo->getGitBranchName(), 'git_commit' => $versionInfo->getGitCommitHash() ]);