Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Merge pull request #79 from wickedOne/optional-translation
Browse files Browse the repository at this point in the history
made translation opt out
  • Loading branch information
Sam Partington authored May 31, 2017
2 parents 04a0303 + afd52d8 commit a4a7bbc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
40 changes: 20 additions & 20 deletions Model/Breadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,62 +17,62 @@ class Breadcrumbs implements \Iterator, \ArrayAccess, \Countable
*/
private $router;

public function addItem($text, $url = "", array $translationParameters = array())
public function addItem($text, $url = "", array $translationParameters = array(), $translate = true)
{
return $this->addNamespaceItem(self::DEFAULT_NAMESPACE, $text, $url, $translationParameters);
return $this->addNamespaceItem(self::DEFAULT_NAMESPACE, $text, $url, $translationParameters, $translate);
}

public function addNamespaceItem($namespace, $text, $url = "", array $translationParameters = array())
public function addNamespaceItem($namespace, $text, $url = "", array $translationParameters = array(), $translate = true)
{
$b = new SingleBreadcrumb($text, $url, $translationParameters);
$b = new SingleBreadcrumb($text, $url, $translationParameters, $translate);
$this->breadcrumbs[$namespace][] = $b;

return $this;
}

public function prependItem($text, $url = "", array $translationParameters = array())
public function prependItem($text, $url = "", array $translationParameters = array(), $translate = true)
{
return $this->prependNamespaceItem(self::DEFAULT_NAMESPACE, $text, $url, $translationParameters);
return $this->prependNamespaceItem(self::DEFAULT_NAMESPACE, $text, $url, $translationParameters, $translate);
}

public function prependNamespaceItem($namespace, $text, $url = "", array $translationParameters = array())
public function prependNamespaceItem($namespace, $text, $url = "", array $translationParameters = array(), $translate = true)
{
$b = new SingleBreadcrumb($text, $url, $translationParameters);
$b = new SingleBreadcrumb($text, $url, $translationParameters, $translate);
array_unshift($this->breadcrumbs[$namespace], $b);

return $this;
}

public function addRouteItem($text, $route, array $parameters = array(), $referenceType = RouterInterface::ABSOLUTE_PATH, array $translationParameters = array())
public function addRouteItem($text, $route, array $parameters = array(), $referenceType = RouterInterface::ABSOLUTE_PATH, array $translationParameters = array(), $translate = true)
{
return $this->addNamespaceRouteItem(self::DEFAULT_NAMESPACE, $text, $route, $parameters, $referenceType, $translationParameters);
return $this->addNamespaceRouteItem(self::DEFAULT_NAMESPACE, $text, $route, $parameters, $referenceType, $translationParameters, $translate);
}

public function addNamespaceRouteItem($namespace, $text, $route, array $parameters = array(), $referenceType = RouterInterface::ABSOLUTE_PATH, array $translationParameters = array())
public function addNamespaceRouteItem($namespace, $text, $route, array $parameters = array(), $referenceType = RouterInterface::ABSOLUTE_PATH, array $translationParameters = array(), $translate = true)
{
$url = $this->router->generate($route, $parameters, $referenceType);

return $this->addNamespaceItem($namespace, $text, $url, $translationParameters);
return $this->addNamespaceItem($namespace, $text, $url, $translationParameters, $translate);
}

public function prependRouteItem($text, $route, array $parameters = array(), $referenceType = RouterInterface::ABSOLUTE_PATH, array $translationParameters = array())
public function prependRouteItem($text, $route, array $parameters = array(), $referenceType = RouterInterface::ABSOLUTE_PATH, array $translationParameters = array(), $translate = true)
{
return $this->prependNamespaceRouteItem(self::DEFAULT_NAMESPACE, $text, $route, $parameters, $referenceType, $translationParameters);
return $this->prependNamespaceRouteItem(self::DEFAULT_NAMESPACE, $text, $route, $parameters, $referenceType, $translationParameters, $translate);
}

public function prependNamespaceRouteItem($namespace, $text, $route, array $parameters = array(), $referenceType = RouterInterface::ABSOLUTE_PATH, array $translationParameters = array())
public function prependNamespaceRouteItem($namespace, $text, $route, array $parameters = array(), $referenceType = RouterInterface::ABSOLUTE_PATH, array $translationParameters = array(), $translate = true)
{
$url = $this->router->generate($route, $parameters, $referenceType);

return $this->prependNamespaceItem($namespace, $text, $url, $translationParameters);
return $this->prependNamespaceItem($namespace, $text, $url, $translationParameters, $translate);
}

public function addObjectArray(array $objects, $text, $url = "", array $translationParameters = array())
public function addObjectArray(array $objects, $text, $url = "", array $translationParameters = array(), $translate = true)
{
return $this->addNamespaceObjectArray(self::DEFAULT_NAMESPACE, $objects, $text, $url, $translationParameters);
return $this->addNamespaceObjectArray(self::DEFAULT_NAMESPACE, $objects, $text, $url, $translationParameters, $translate);
}

public function addNamespaceObjectArray($namespace, array $objects, $text, $url = "", array $translationParameters = array())
public function addNamespaceObjectArray($namespace, array $objects, $text, $url = "", array $translationParameters = array(), $translate = true)
{
foreach($objects as $object) {
$itemText = $this->validateArgument($object, $text);
Expand All @@ -81,7 +81,7 @@ public function addNamespaceObjectArray($namespace, array $objects, $text, $url
} else {
$itemUrl = "";
}
$this->addNamespaceItem($namespace, $itemText, $itemUrl, $translationParameters);
$this->addNamespaceItem($namespace, $itemText, $itemUrl, $translationParameters, $translate);
}

return $this;
Expand Down
4 changes: 3 additions & 1 deletion Model/SingleBreadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ class SingleBreadcrumb
public $url;
public $text;
public $translationParameters;
public $translate;

public function __construct($text = "", $url = "", array $translationParameters = array())
public function __construct($text = "", $url = "", array $translationParameters = array(), $translate = true)
{
$this->url = $url;
$this->text = $text;
$this->translationParameters = $translationParameters;
$this->translate = $translate;
}
}
6 changes: 3 additions & 3 deletions Resources/views/breadcrumbs.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
{% for b in breadcrumbs %}
<li{% if itemClass is defined and itemClass|length %} class="{{ itemClass }}"{% endif %} itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
{% if b.url and not loop.last %}
<a href="{{ b.url }}" itemprop="item"{% if linkRel is defined and linkRel|length %} rel="{{ linkRel }}"{% endif %}>
<a href="{{ b.url }}" itemprop="item"{% if linkRel is defined and linkRel|length %} rel="{{ linkRel }}"{% endif %}>
{% endif %}
<span itemprop="name">{{- b.text | trans(b.translationParameters, translation_domain, locale) -}}</span>
<span itemprop="name">{% if b.translate is defined and b.translate == true %}{{- b.text | trans(b.translationParameters, translation_domain, locale) -}}{% else %}{{- b.text -}}{% endif %}</span>
{% if b.url and not loop.last %}
</a>
</a>
{% endif %}
<meta itemprop="position" content="{{ loop.index }}" />

Expand Down

0 comments on commit a4a7bbc

Please sign in to comment.