Skip to content

Commit

Permalink
Merge pull request #36 from basz/fix-menu-helper-call-method
Browse files Browse the repository at this point in the history
fixes overwriting of call
  • Loading branch information
Jurian Sluiman committed Jan 7, 2014
2 parents 87abbae + 52be614 commit fe94098
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/SlmLocale/View/Helper/LocaleMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ public function __toString()
$labelLocale = $this->getLabelInCurrentLocale() ? $locale : $current;

$url = $this->getView()->localeUrl($locale);
$title = $this->callLocale($this->getTitleMethod(), $locale, $titleLocale);
$label = $this->callLocale($this->getLabelMethod(), $locale, $labelLocale);
$title = $this->getLocaleProperty($this->getTitleMethod(), $locale, $titleLocale);
$label = $this->getLocaleProperty($this->getLabelMethod(), $locale, $labelLocale);

$item = sprintf(
'<li><a href="%s" title="%s"%s>%s</a></li>' . "\n",
Expand Down Expand Up @@ -297,16 +297,24 @@ protected function checkLocaleMethod($method)
}
}

protected function callLocale($method, $locale, $in_locale = false)
/**
* Retrieves a value by property from Locale
*
* @param $property
* @param $locale
* @param bool $in_locale
* @return mixed
*/
protected function getLocaleProperty($property, $locale, $in_locale = false)
{
$method = sprintf('\Locale::get%s', ucfirst($method));
$callback = sprintf('\Locale::get%s', ucfirst($property));

$args = array($locale);

if ($in_locale && !in_array($method, array('primaryLanguage', 'region', 'script'))) {
if ($in_locale && !in_array($property, array('primaryLanguage', 'region', 'script'))) {
$args[] = $in_locale;
}

return call_user_func_array($method, $args);
return call_user_func_array($callback, $args);
}
}

0 comments on commit fe94098

Please sign in to comment.