-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#47: Add twig extensions to allow building of URLs from osid_Id objects.
- Loading branch information
1 parent
7fdc42e
commit 024361b
Showing
4 changed files
with
69 additions
and
24 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace App\Twig; | ||
|
||
use Twig\Extension\AbstractExtension; | ||
use Twig\TwigFilter; | ||
|
||
class NoWrapParentheticals extends AbstractExtension | ||
{ | ||
public function getFilters(): array | ||
{ | ||
return [ | ||
new TwigFilter('noWrapParentheticals', [$this, 'addNoWrapHtml']), | ||
]; | ||
} | ||
|
||
public function addNoWrapHtml(string $input): string | ||
{ | ||
return preg_replace('/\([^\)]+\)/', '<span style="white-space: nowrap">$0</span>', $input); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
// src/Twig/AppExtension.php | ||
namespace App\Twig; | ||
|
||
use App\Service\Osid\IdMap; | ||
use Twig\Extension\AbstractExtension; | ||
use Twig\TwigFunction; | ||
|
||
class OsidIdExtension extends AbstractExtension | ||
{ | ||
|
||
/** | ||
* @var \App\Service\Osid\IdMap | ||
* The IdMap service. | ||
*/ | ||
private $idMap; | ||
|
||
/** | ||
* Create a new instance of this service. | ||
* | ||
* @param \App\Service\Osid\IdMap | ||
* The IdMap service. | ||
*/ | ||
public function __construct(IdMap $idMap) { | ||
$this->idMap = $idMap; | ||
} | ||
|
||
public function getFunctions(): array | ||
{ | ||
return [ | ||
new TwigFunction('osidIdToString', [$this, 'osidIdToString']), | ||
]; | ||
} | ||
|
||
public function osidIdToString(\osid_id_Id $id): string | ||
{ | ||
return $this->idMap->toString($id); | ||
} | ||
} |