Skip to content

Commit

Permalink
Code Refactoring and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
serge0design committed Mar 11, 2024
1 parent 76e303b commit 7777a8c
Show file tree
Hide file tree
Showing 27 changed files with 740 additions and 694 deletions.
83 changes: 42 additions & 41 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
{
"name": "serge0design/pimcore-custom-twig",
"license": "GPL-3.0-or-later",
"type": "pimcore-bundle",
"keywords": [
"pimcore",
"twig",
"Filter",
"Extension",
"Test"
],
"description": "A collection of twig Extensions/Filters and Tests for Pimcore 11.",
"homepage": "https://github.com/serge0design/pimcore-custom-twig.git",
"authors": [
{
"name": "serge.design - Serge",
"email": "github@serge.design",
"homepage": "https://serge-design.ch",
"role": "Developer"
}
],
"autoload": {
"psr-4": {
"SergeDesign\\PimcoreCustomTwigBundle\\": "src/"
}
},
"extra": {
"pimcore": {
"bundles": [
"SergeDesign\\PimcoreCustomTwigBundle\\PimcoreCustomTwigBundle"
]
}
},
"require": {
"ext-intl": "*",
"ext-mbstring": "*",
"pimcore/pimcore": "^v11.1.0",
"symfony/ux-twig-component": "^2.7",
"twig/extra-bundle": "^3.5",
"twig/string-extra": "^3.5"
},
"require-dev": {}
"name": "serge0design/pimcore-custom-twig",
"license": "GPL-3.0-or-later",
"type": "pimcore-bundle",
"keywords": [
"pimcore",
"twig",
"Filter",
"Extension",
"Test"
],
"description": "A collection of twig Extensions/Filters and Tests for Pimcore 11.",
"homepage": "https://github.com/serge0design/pimcore-custom-twig.git",
"authors": [
{
"name": "serge.design - Serge",
"email": "github@serge.design",
"homepage": "https://serge-design.ch",
"role": "Developer"
}
],
"autoload": {
"psr-4": {
"SergeDesign\\PimcoreCustomTwigBundle\\": "src/"
}
},
"extra": {
"pimcore": {
"bundles": [
"SergeDesign\\PimcoreCustomTwigBundle\\PimcoreCustomTwigBundle"
]
}
},
"require": {
"ext-iconv": "*",
"ext-intl": "*",
"ext-mbstring": "*",
"pimcore/pimcore": "^v11.1.0",
"symfony/ux-twig-component": "^2.7",
"twig/extra-bundle": "^3.5",
"twig/string-extra": "^3.5"
},
"require-dev": {}
}
34 changes: 18 additions & 16 deletions config/twig/extensions.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false
_defaults:
autowire: true
autoconfigure: true
public: false

SergeDesign\PimcoreCustomTwigBundle\Twig\Extension\TwigBootstrapSvgIcon:
tags: [ 'twig.extension' ]
SergeDesign\PimcoreCustomTwigBundle\Twig\Extension\TwigBootstrapSvgIcon:
tags:
- { name: twig.extension }

SergeDesign\PimcoreCustomTwigBundle\Twig\Extension\TwigEditmodeLinkToObject:
tags: [ 'twig.extension' ]
SergeDesign\PimcoreCustomTwigBundle\Twig\Extension\TwigEditmodeLinkToObject:
tags:
- { name: twig.extension }

SergeDesign\PimcoreCustomTwigBundle\Twig\Extension\TwigLanguageSwitcher:
tags: [ 'twig.extension' ]

SergeDesign\PimcoreCustomTwigBundle\Twig\Extension\TwigQrCode:
tags: [ 'twig.extension' ]

SergeDesign\PimcoreCustomTwigBundle\Twig\Extension\TwigSvgFun:
tags: [ 'twig.extension' ]
SergeDesign\PimcoreCustomTwigBundle\Twig\Extension\TwigLanguageSwitcher:
tags:
- { name: twig.extension }

SergeDesign\PimcoreCustomTwigBundle\Twig\Extension\TwigQrCode:
arguments:
$translator: '@Pimcore\Translation\Translator'
tags:
- { name: twig.extension }
22 changes: 12 additions & 10 deletions config/twig/testing.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false
_defaults:
autowire: true
autoconfigure: true
public: false

SergeDesign\PimcoreCustomTwigBundle\Twig\Test\TwigTests:
tags: [ 'twig.extension' ]
SergeDesign\PimcoreCustomTwigBundle\Twig\Test\TwigTests:
tags:
- { name: twig.extension }

SergeDesign\PimcoreCustomTwigBundle\Twig\Test\TwigBundleChecker:
tags: [ 'twig.extension' ]
arguments:
- '@service_container'
SergeDesign\PimcoreCustomTwigBundle\Twig\Test\TwigBundleChecker:
tags:
- { name: twig.extension }
arguments:
$bundles: '%kernel.bundles%'

72 changes: 62 additions & 10 deletions docs/twig-filters.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
## Twig Filter Examples

twigFilterArrayFlip:
test array

```
{% set array = ['apple', 'banana', 'cherry'] %}
```

twigFilterArrayFlip:<br>
Exchanges all keys with their associated values in an array

```
Expand All @@ -9,7 +15,7 @@ Exchanges all keys with their associated values in an array
{% endfor %}
```

twigFilterArrayReverse:
twigFilterArrayReverse:<br>
Return an array with elements in reverse order

```
Expand All @@ -18,7 +24,7 @@ Return an array with elements in reverse order
{% endfor %}
```

twigFilterArrayShuffle
twigFilterArrayShuffle <br>
Return an array with elements in shuffled order

```
Expand All @@ -27,8 +33,8 @@ Return an array with elements in shuffled order
{% endfor %}
```

twigFilterPassedTimeToNow
usable for logins, orders, blogs, etc
twigFilterPassedTimeToNow<br>
usable for logins, orders, blogs, etc. <br>
Outputs something like: Last Loggin ( 1day ago )

```
Expand All @@ -42,6 +48,16 @@ twigFilterFileGetContents
{{ svgImagePath|twigFilterFileGetContents }}
```

Formatting currency output

```
{% set productPrice = 1234.56 %} {# Example price #}
{% set currencySymbol = 'CHF' %} {# Currency code #}
{% set locale = 'de_CH' %} {# Locale for formatting #}
{# Using the twigFilterFormatPrice filter to format the price #}
{{ productPrice|twigFilterFormatPrice(currencySymbol, 2, locale) }}
```

#### Image

twigFilterImgThumbnail
Expand All @@ -63,6 +79,20 @@ Output inline Code: style="background-image: url('..');
{{ pimcoreImage|twigFilterCssBgImg('thumbnailName') }}
```

Usage:

```
{% set pimcoreImage = pimcore_image("pimcoreImage") %}
{% if editmode %}
{{ pimcoreImage|raw }}
{% else %}
{% set pimcoreImage = pimcoreImage.image %}
{{ pimcoreImage|twigFilterImgThumbnail('thumbnailName', 'cssClass', 'altText', {"data-attr": "value"}) }}
{{ pimcoreImage|twigFilterImgThumbConfig('cssClass', 'altText', 100, 100, 100, 'png') }}
{{ pimcoreImage|twigFilterCssBgImg('contentimages') }}
{% endif %}
```

#### String

twigFilterGetMd5
Expand All @@ -80,7 +110,15 @@ twigFilterGetUniqid
twigFilterStringNormalizer

```
{{ "String"|twigFilterStringNormalizer }}
{% set string = '~¨^?\'"/-+.,;() &äöüÄÖÜßÉéÈèÊêEeËëÀàÁáÅåaÂâÃãªÆæCcÇçCcÍíÌìÎîÏïÓóÒòÔôºÕõŒOoØøÚúÙùÛûUuUuŠšSsŽžÑñ¡¿Ÿÿ_:' %}
{{ string|twigFilterStringNormalizer }}
```

twigFilterNormalizeFolderName

```
{% set string = '~¨^?\'"/-+.,;() &äöüÄÖÜßÉéÈèÊêEeËëÀàÁáÅåaÂâÃãªÆæCcÇçCcÍíÌìÎîÏïÓóÒòÔôºÕõŒOoØøÚúÙùÛûUuUuŠšSsŽžÑñ¡¿Ÿÿ_:' %}
{{ string|twigFilterNormalizeFolderName }}
```

twigFilterStrToLower
Expand All @@ -89,6 +127,18 @@ twigFilterStrToLower
{{ "String"|twigFilterStrToLower }}
```

twigFilterStrToUpper

```
{{ "string"|twigFilterStrToUpper }}
```

twigFilterStrCapitalize

```
{{ "string"|twigFilterStrCapitalize }}
```

twigFilterTruncate

```
Expand All @@ -106,7 +156,7 @@ twigFilterWordwrap
twigFilterHrefUrl

```
{{ "https://url.com/"|twigFilterHrefUrl }}
{{ "https://url.com/"|twigFilterHrefUrl('css_class', "_blank") }}
```

twigFilterHrefEmail
Expand All @@ -127,11 +177,13 @@ twigFilterHrefWhatsApp
{{ href|twigFilterHrefWhatsApp }}
```

twigFilterHrefSocialMedia
based on Bootstrap Icons: https://icons.getbootstrap.com/
twigFilterHrefSocialMedia <br>
based on Bootstrap Icons: https://icons.getbootstrap.com/<br>
r.i.p. twitter

```
{{ href|twigFilterHrefSocialMedia }}
{% set social = "https://twitter.com" %}
{{ social|twigFilterHrefSocialMedia('twitter') }}
```

#### Time
Expand Down
20 changes: 10 additions & 10 deletions docs/twig-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Check if item is of MIME-Type image/svg+xml
```

twigTestIsArray\
Check if item is array
Check if item is an array

```
{% if item is twigTestIsArray %}
Expand All @@ -19,7 +19,7 @@ Check if item is array
```

twigTestIsBoolean\
Check if item is bool
Check if item is of bool

```
{% if item is twigTestIsBoolean %}
Expand All @@ -46,7 +46,7 @@ Check if item is countable
```

twigTestIsDir\
Check if item is directory
Check if item is a directory

```
{% if item is twigTestIsDir %}
Expand All @@ -55,7 +55,7 @@ Check if item is directory
```

twigTestIsFloat\
Check if item is float
Check if item is of float

```
{% if item is twigTestIsFloat %}
Expand All @@ -64,7 +64,7 @@ Check if item is float
```

twigTestIsInt\
Check if is int
Check if is of int

```
{% if item is twigTestIsInt %}
Expand All @@ -73,7 +73,7 @@ Check if is int
```

twigTestIsNumeric\
Check if is numeric
Check if is of numeric

```
{% if item is twigTestIsNumeric %}
Expand All @@ -82,7 +82,7 @@ Check if is numeric
```

twigTestIsNull\
Check if item is null
Check if item is of null

```
{% if item is twigTestIsNull %}
Expand All @@ -91,7 +91,7 @@ Check if item is null
```

twigTestIsObject\
Check if item is object
Check if item is an object

```
{% if item is twigTestIsObject %}
Expand All @@ -100,7 +100,7 @@ Check if item is object
```

twigTestIsResource\
Check if item is resource
Check if item is a resource

```
{% if item is twigTestIsResource %}
Expand All @@ -118,7 +118,7 @@ Check if item is scalar
```

twigTestIsString\
Check if item is string
Check if item is a string

```
{% if item is twigTestIsString %}
Expand Down

0 comments on commit 7777a8c

Please sign in to comment.