add app url (tel:, mailto:, fax:)

This commit is contained in:
Simon Vieille 2021-08-20 11:36:43 +02:00
parent 37a7a3b625
commit e42860ac5b
4 changed files with 28 additions and 1 deletions

View File

@ -334,6 +334,19 @@ class Node implements EntityInterface
return $string->startsWith('http://') || $string->startsWith('https://');
}
public function hasAppUrl(): bool
{
$string = u($this->getUrl());
foreach (['tel:', 'fax:', 'mailto:'] as $prefix) {
if ($string->startsWith($prefix)) {
return true;
}
}
return false;
}
public function getIsVisible(): ?bool
{
return $this->isVisible;

View File

@ -133,7 +133,13 @@ class NodeEventSubscriber extends EntityManagerEventSubscriber
$generatedUrl = $generatedUrl.'-'.$number;
}
if (!u($generatedUrl)->startsWith('https://') && !u($generatedUrl)->startsWith('http://')) {
if (
!u($generatedUrl)->startsWith('https://')
&& !u($generatedUrl)->startsWith('http://')
&& !u($generatedUrl)->startsWith('tel:')
&& !u($generatedUrl)->startsWith('mailto:')
&& !u($generatedUrl)->startsWith('fax:')
) {
$generatedUrl = '/'.$generatedUrl;
$generatedUrl = preg_replace('#/{2,}#', '/', $generatedUrl);
}

View File

@ -87,6 +87,10 @@
<a href="{{ safe_node_url(node) }}" class="btn btn-sm border border-secondary btn-light">
<span class="fa fa-sign-out-alt text-muted"></span>
</a>
{% elseif node.hasAppUrl %}
<a href="{{ node.url }}" class="btn btn-sm border border-secondary btn-light">
<span class="fa fa-sign-out-alt text-muted"></span>
</a>
{% else %}
{% if not node.disableUrl %}
{% if node.parameters|length %}

View File

@ -57,6 +57,10 @@ class SiteRouteLoader extends Loader
continue;
}
if ($node->hasAppUrl()) {
continue;
}
if (null !== $node->getAliasNode()) {
continue;
}