From 206168672b3d7302e9949fe7c6d6033b547cda80 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 3 Sep 2015 10:22:47 +0200 Subject: [PATCH] NavigationItem: Add method getUniqueName() refs #5600 --- .../Icinga/Web/Navigation/NavigationItem.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/library/Icinga/Web/Navigation/NavigationItem.php b/library/Icinga/Web/Navigation/NavigationItem.php index e92561411..a4294fa0a 100644 --- a/library/Icinga/Web/Navigation/NavigationItem.php +++ b/library/Icinga/Web/Navigation/NavigationItem.php @@ -325,6 +325,30 @@ class NavigationItem implements IteratorAggregate return $this; } + /** + * Return this item's name escaped with only ASCII chars and/or digits + * + * @return string + */ + protected function getEscapedName() + { + return preg_replace('~[^a-zA-Z0-9]~', '_', $this->getName()); + } + + /** + * Return a unique version of this item's name + * + * @return string + */ + public function getUniqueName() + { + if ($this->getParent() === null) { + return 'navigation-' . $this->getEscapedName(); + } + + return $this->getParent()->getEscapedName() . '-' . $this->getEscapedName(); + } + /** * Return this item's name *