Skip to content

Commit

Permalink
Merge pull request #15 from oveleon/develop
Browse files Browse the repository at this point in the history
Replaced Patchwork/UTF8 by Symfony/String
  • Loading branch information
zoglo authored Feb 14, 2022
2 parents 2e634ac + c0b0e97 commit ea90a1b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

---

> Working with **Contao 4.9** and up to **Contao 4.12** (PHP ^7.4 and PHP 8)
> Working with **Contao 4.9** and up to **Contao 4.13** (PHP ^7.4 and PHP 8)
---

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"php": "^7.4 || ^8.0",
"ext-json":"*",
"contao/core-bundle": "^4.9",
"symfony/http-foundation":"4.4.* || ^5.2"
"symfony/http-foundation":"4.4.* || ^5.2",
"symfony/string": "^5.4"
},
"conflict": {
"contao/core": "*",
Expand Down
9 changes: 9 additions & 0 deletions src/Resources/contao/classes/Glossary.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Contao\PageModel;
use Contao\StringUtil;
use Contao\System;
use function Symfony\Component\String\u;

/**
* Provide methods regarding glossaries.
Expand Down Expand Up @@ -385,4 +386,12 @@ protected function getLink($objItem, string $strUrl, string $strBase = ''): stri
// Link to the default page
return sprintf(preg_replace('/%(?!s)/', '%%', $strUrl), ($objItem->alias ?: $objItem->id));
}

/**
* Returns a transliterated string
*/
public static function transliterateAscii(string $string): string
{
return (string) u($string)->ascii();
}
}
3 changes: 1 addition & 2 deletions src/Resources/contao/dca/tl_glossary_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use Oveleon\ContaoGlossaryBundle\Glossary;
use Oveleon\ContaoGlossaryBundle\GlossaryItemModel;
use Oveleon\ContaoGlossaryBundle\GlossaryModel;
use Patchwork\Utf8;
use Symfony\Component\HttpFoundation\Session\SessionInterface;

System::loadLanguageFile('tl_content');
Expand Down Expand Up @@ -531,7 +530,7 @@ public function checkPermission(): void
*/
public function setGlossaryItemGroup(DataContainer $dc): void
{
$newGroup = Utf8::strtoupper(mb_substr($dc->activeRecord->keyword, 0, 1, 'UTF-8'));
$newGroup = mb_strtoupper(mb_substr($dc->activeRecord->keyword, 0, 1, 'UTF-8'));

if ($dc->activeRecord->letter !== $newGroup)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Resources/contao/modules/ModuleGlossary.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
use Contao\FilesModel;
use Contao\FrontendTemplate;
use Contao\FrontendUser;
use Contao\Module;
use Contao\StringUtil;
use Contao\System;
use Patchwork\Utf8;

/**
* Parent class for glossary modules.
Expand All @@ -30,7 +30,7 @@
* @author Fabian Ekert <https://github.com/eki89>
* @author Sebastian Zoglowek <https://github.com/zoglo>
*/
abstract class ModuleGlossary extends \Module
abstract class ModuleGlossary extends Module
{
/**
* Sort out protected glossaries.
Expand Down Expand Up @@ -117,7 +117,7 @@ protected function parseGlossaryGroups($objGlossaryItems, FrontendTemplate &$obj
foreach ($objAvailableGlossaryItems as $item)
{
// Transliterate letters to valid Ascii
$itemGroup = $blnTransliteration ? Utf8::toAscii($item->letter) : $item->letter;
$itemGroup = $blnTransliteration ? Glossary::transliterateAscii($item->letter) : $item->letter;

$availableGroups[$itemGroup] = [
'item' => $this->generateGroupAnchorLink($itemGroup, $blnSingleGroup),
Expand Down Expand Up @@ -163,7 +163,7 @@ protected function parseGlossaryGroups($objGlossaryItems, FrontendTemplate &$obj
foreach ($objGlossaryItems as $objGlossaryItem)
{
// Transliterate letters to valid Ascii
$itemGroup = $blnTransliteration ? Utf8::toAscii($objGlossaryItem->letter) : $objGlossaryItem->letter;
$itemGroup = $blnTransliteration ? Glossary::transliterateAscii($objGlossaryItem->letter) : $objGlossaryItem->letter;

$arrGlossaryGroups[$itemGroup]['id'] = 'group'.$this->id.'_'.$itemGroup;
$arrGlossaryGroups[$itemGroup]['items'][] = $this->parseGlossaryItem($objGlossaryItem);
Expand Down
3 changes: 1 addition & 2 deletions src/Resources/contao/modules/ModuleGlossaryList.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Contao\Input;
use Contao\StringUtil;
use Contao\System;
use Patchwork\Utf8;

/**
* Front end module "glossary list".
Expand Down Expand Up @@ -56,7 +55,7 @@ public function generate()
if ($request && System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest($request))
{
$objTemplate = new BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### '.Utf8::strtoupper($GLOBALS['TL_LANG']['FMD']['glossary'][0]).' ###';
$objTemplate->wildcard = '### '. mb_strtoupper($GLOBALS['TL_LANG']['FMD']['glossary'][0], 'UTF-8') .' ###';
$objTemplate->title = $this->headline;
$objTemplate->id = $this->id;
$objTemplate->link = $this->name;
Expand Down
3 changes: 1 addition & 2 deletions src/Resources/contao/modules/ModuleGlossaryReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use Contao\PageModel;
use Contao\StringUtil;
use Contao\System;
use Patchwork\Utf8;

/**
* Front end module "glossary reader".
Expand Down Expand Up @@ -56,7 +55,7 @@ public function generate()
if ($request && System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest($request))
{
$objTemplate = new BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### '.Utf8::strtoupper($GLOBALS['TL_LANG']['FMD']['glossaryreader'][0]).' ###';
$objTemplate->wildcard = '### '. mb_strtoupper($GLOBALS['TL_LANG']['FMD']['glossaryreader'][0], 'UTF-8') .' ###';
$objTemplate->title = $this->headline;
$objTemplate->id = $this->id;
$objTemplate->link = $this->name;
Expand Down

0 comments on commit ea90a1b

Please sign in to comment.