add module settings service extension and shop configuration extension
Dieser Commit ist enthalten in:
Ursprung
555557dcdd
Commit
81ffc7b3d1
@ -6,12 +6,19 @@
|
||||
additional extensions that can be used in the shop's Twig templates:
|
||||
|
||||
- method_exists - Checks whether the method of an object exists.
|
||||
|
||||
```
|
||||
{% if method_exists(entity, 'getCreatedBy') %}
|
||||
({{ entity.createdBy.name }})
|
||||
{% endif %}
|
||||
```
|
||||
- getModuleSettingsService - get the module settings service
|
||||
```
|
||||
{{ getModuleSettingsService().getString('myModuleSetting', 'myModuleId') }}
|
||||
```
|
||||
- getShopConfiguration - get the shop configuration
|
||||
```
|
||||
{{ getShopConfiguration().getShopId() }}
|
||||
```
|
||||
|
||||
## Table of content
|
||||
|
||||
|
10
README.md
10
README.md
@ -6,12 +6,19 @@
|
||||
zusätzliche Erweiterungen, die in den Twig-Templates des Shops verwendet werden können:
|
||||
|
||||
- method_exists - Prüft, ob die Methode eines Objekts existiert.
|
||||
|
||||
```
|
||||
{% if method_exists(entity, 'getCreatedBy') %}
|
||||
({{ entity.createdBy.name }})
|
||||
{% endif %}
|
||||
```
|
||||
- getModuleSettingsService - liefert den Moduleinstellungsservice
|
||||
```
|
||||
{{ getModuleSettingsService().getString('myModuleSetting', 'myModuleId') }}
|
||||
```
|
||||
- getShopConfiguration - liefert die Shopkonfiguration
|
||||
```
|
||||
{{ getShopConfiguration().getShopId() }}
|
||||
```
|
||||
|
||||
## Inhaltsverzeichnis
|
||||
|
||||
@ -27,7 +34,6 @@ Dieses Paket erfordert einen mit Composer installierten OXID eShop in einer in d
|
||||
|
||||
Öffnen Sie eine Kommandozeile und navigieren Sie zum Stammverzeichnis des Shops (Elternverzeichnis von source und vendor). Führen Sie den folgenden Befehl aus. Passen Sie die Pfadangaben an Ihre Installationsumgebung an.
|
||||
|
||||
|
||||
```bash
|
||||
php composer require d3/oxid-twig-extensions:^1.0
|
||||
```
|
||||
|
@ -3,4 +3,10 @@ services:
|
||||
autowire: true
|
||||
|
||||
D3\OxidTwigExtensions\MethodExistsExtension:
|
||||
tags: ['twig.extension']
|
||||
|
||||
D3\OxidTwigExtensions\ModuleSettingsServiceExtension:
|
||||
tags: ['twig.extension']
|
||||
|
||||
D3\OxidTwigExtensions\ShopConfigurationExtension:
|
||||
tags: ['twig.extension']
|
50
src/ModuleSettingsServiceExtension.php
Normale Datei
50
src/ModuleSettingsServiceExtension.php
Normale Datei
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* https://www.d3data.de
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\OxidTwigExtensions;
|
||||
|
||||
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
class ModuleSettingsServiceExtension extends AbstractExtension
|
||||
{
|
||||
/**
|
||||
* @return TwigFunction[]
|
||||
*/
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
new TwigFunction(
|
||||
'getModuleSettingsService',
|
||||
[$this, 'getModuleSettingsService'],
|
||||
['is_safe' => ['html']]
|
||||
)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ModuleSettingServiceInterface
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function getModuleSettingsService(): ModuleSettingServiceInterface
|
||||
{
|
||||
return ContainerFactory::getInstance()->getContainer()->get(ModuleSettingServiceInterface::class);
|
||||
}
|
||||
}
|
46
src/ShopConfigurationExtension.php
Normale Datei
46
src/ShopConfigurationExtension.php
Normale Datei
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* https://www.d3data.de
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\OxidTwigExtensions;
|
||||
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\EshopCommunity\Core\Config;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
class ShopConfigurationExtension extends AbstractExtension
|
||||
{
|
||||
/**
|
||||
* @return TwigFunction[]
|
||||
*/
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
new TwigFunction(
|
||||
'getShopConfiguration',
|
||||
[$this, 'getShopConfiguration'],
|
||||
['is_safe' => ['html']]
|
||||
)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Config
|
||||
*/
|
||||
public function getShopConfiguration(): Config
|
||||
{
|
||||
return Registry::getConfig();
|
||||
}
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren