Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
aae408c264 | |||
ea9002dff1 | |||
d1b63112b1 | |||
81ffc7b3d1 |
16
CHANGELOG.md
16
CHANGELOG.md
@ -4,7 +4,21 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased](https://git.d3data.de/D3Public/oxid_twig_extensions/compare/1.0.0.0...rel_1.x)
|
## [Unreleased](https://git.d3data.de/D3Public/oxid_twig_extensions/compare/1.3.0.0...rel_1.x)
|
||||||
|
|
||||||
|
## [1.3.0.0](https://git.d3data.de/D3Public/oxid_twig_extensions/compare/1.2.0.0...1.3.0.0) - 2024-06-11
|
||||||
|
### Added
|
||||||
|
- isObject check
|
||||||
|
|
||||||
|
## [1.2.0.0](https://git.d3data.de/D3Public/oxid_twig_extensions/compare/1.1.0.0...1.2.0.0) - 2024-06-07
|
||||||
|
### Added
|
||||||
|
- Twig as dependency
|
||||||
|
- text, array, pcre functionality
|
||||||
|
|
||||||
|
## [1.1.0.0](https://git.d3data.de/D3Public/oxid_twig_extensions/compare/1.0.0.0...1.1.0.0) - 2024-05-07
|
||||||
|
### Added
|
||||||
|
- module settings access
|
||||||
|
- shop settings access
|
||||||
|
|
||||||
## [1.0.0.0](https://git.d3data.de/D3Public/oxid_twig_extensions/releases/tag/1.0.0.0) - 2023-01-10
|
## [1.0.0.0](https://git.d3data.de/D3Public/oxid_twig_extensions/releases/tag/1.0.0.0) - 2023-01-10
|
||||||
### Added
|
### Added
|
||||||
|
@ -6,12 +6,19 @@
|
|||||||
additional extensions that can be used in the shop's Twig templates:
|
additional extensions that can be used in the shop's Twig templates:
|
||||||
|
|
||||||
- method_exists - Checks whether the method of an object exists.
|
- method_exists - Checks whether the method of an object exists.
|
||||||
|
|
||||||
```
|
```
|
||||||
{% if method_exists(entity, 'getCreatedBy') %}
|
{% if method_exists(entity, 'getCreatedBy') %}
|
||||||
({{ entity.createdBy.name }})
|
({{ entity.createdBy.name }})
|
||||||
{% endif %}
|
{% endif %}
|
||||||
```
|
```
|
||||||
|
- getModuleSettingsService - get the module settings service
|
||||||
|
```
|
||||||
|
{{ getModuleSettingsService().getString('myModuleSetting', 'myModuleId') }}
|
||||||
|
```
|
||||||
|
- getShopConfiguration - get the shop configuration
|
||||||
|
```
|
||||||
|
{{ getShopConfiguration().getShopId() }}
|
||||||
|
```
|
||||||
|
|
||||||
## Table of content
|
## 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:
|
zusätzliche Erweiterungen, die in den Twig-Templates des Shops verwendet werden können:
|
||||||
|
|
||||||
- method_exists - PrĂĽft, ob die Methode eines Objekts existiert.
|
- method_exists - PrĂĽft, ob die Methode eines Objekts existiert.
|
||||||
|
|
||||||
```
|
```
|
||||||
{% if method_exists(entity, 'getCreatedBy') %}
|
{% if method_exists(entity, 'getCreatedBy') %}
|
||||||
({{ entity.createdBy.name }})
|
({{ entity.createdBy.name }})
|
||||||
{% endif %}
|
{% endif %}
|
||||||
```
|
```
|
||||||
|
- getModuleSettingsService - liefert den Moduleinstellungsservice
|
||||||
|
```
|
||||||
|
{{ getModuleSettingsService().getString('myModuleSetting', 'myModuleId') }}
|
||||||
|
```
|
||||||
|
- getShopConfiguration - liefert die Shopkonfiguration
|
||||||
|
```
|
||||||
|
{{ getShopConfiguration().getShopId() }}
|
||||||
|
```
|
||||||
|
|
||||||
## Inhaltsverzeichnis
|
## 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.
|
Ă–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
|
```bash
|
||||||
php composer require d3/oxid-twig-extensions:^1.0
|
php composer require d3/oxid-twig-extensions:^1.0
|
||||||
```
|
```
|
||||||
|
@ -25,7 +25,9 @@
|
|||||||
"GPL-3.0-or-later"
|
"GPL-3.0-or-later"
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"oxid-esales/oxideshop-ce": "^7.0.0"
|
"oxid-esales/oxideshop-ce": "^7.0.0",
|
||||||
|
"twig/twig": "^3.6",
|
||||||
|
"jasny/twig-extensions": "^1.3.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
@ -4,3 +4,25 @@ services:
|
|||||||
|
|
||||||
D3\OxidTwigExtensions\MethodExistsExtension:
|
D3\OxidTwigExtensions\MethodExistsExtension:
|
||||||
tags: ['twig.extension']
|
tags: ['twig.extension']
|
||||||
|
|
||||||
|
D3\OxidTwigExtensions\ModuleSettingsServiceExtension:
|
||||||
|
tags: ['twig.extension']
|
||||||
|
|
||||||
|
D3\OxidTwigExtensions\ShopConfigurationExtension:
|
||||||
|
tags: ['twig.extension']
|
||||||
|
|
||||||
|
D3\OxidTwigExtensions\IsObjectExtension:
|
||||||
|
tags: ['twig.extension']
|
||||||
|
|
||||||
|
# requires intl extension
|
||||||
|
# Jasny\Twig\DateExtension:
|
||||||
|
# tags: ['twig.extension']
|
||||||
|
|
||||||
|
Jasny\Twig\PcreExtension:
|
||||||
|
tags: ['twig.extension']
|
||||||
|
|
||||||
|
Jasny\Twig\TextExtension:
|
||||||
|
tags: [ 'twig.extension' ]
|
||||||
|
|
||||||
|
Jasny\Twig\ArrayExtension:
|
||||||
|
tags: [ 'twig.extension' ]
|
41
src/IsObjectExtension.php
Normal file
41
src/IsObjectExtension.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?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 InvalidArgumentException;
|
||||||
|
use Twig\Extension\AbstractExtension;
|
||||||
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
|
class isObjectExtension extends AbstractExtension
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return TwigFunction[]
|
||||||
|
*/
|
||||||
|
public function getFunctions(): array
|
||||||
|
{
|
||||||
|
return [new TwigFunction('is_object', [$this, 'twig_method_exists'], ['is_safe' => ['html']])];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param object $entity
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function twig_method_exists($entity): bool
|
||||||
|
{
|
||||||
|
return is_object($entity);
|
||||||
|
}
|
||||||
|
}
|
50
src/ModuleSettingsServiceExtension.php
Normal file
50
src/ModuleSettingsServiceExtension.php
Normal file
@ -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
Normal file
46
src/ShopConfigurationExtension.php
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user