Esempio n. 1
0
 /**
  * Return rendered translated title
  *
  * @param array  $params
  * @param string $title
  * @param string $prefix
  * @param string $suffix
  * @param bool   $isJSON
  * @param bool   $isShort
  * @return $this
  */
 public function render($params = array(), $title = null, $prefix = null, $suffix = null, $isJSON = false, $isShort = false)
 {
     if (!is_null($title) && $isJSON) {
         try {
             /** @var $data \Oro\Bundle\NavigationBundle\Title\StoredTitle */
             $data = $this->serializer->deserialize($title, 'Oro\\Bundle\\NavigationBundle\\Title\\StoredTitle', 'json');
             $params = $data->getParams();
             if ($isShort) {
                 $title = $data->getShortTemplate();
             } else {
                 $title = $data->getTemplate();
                 $prefix = $data->getPrefix();
                 $suffix = $data->getSuffix();
             }
         } catch (RuntimeException $e) {
             // wrong json string - ignore title
             $params = array();
             $title = 'Untitled';
             $prefix = '';
             $suffix = '';
         }
     }
     if (empty($params)) {
         $params = $this->getParams();
     }
     if ($isShort) {
         if (is_null($title)) {
             $title = $this->getShortTemplate();
         }
     } else {
         if (is_null($title)) {
             $title = $this->getTemplate();
         }
         if (is_null($prefix)) {
             $prefix = $this->prefix;
         }
         if (is_null($suffix)) {
             $suffix = $this->suffix;
         }
         $title = $prefix . $title . $suffix;
     }
     $title = $this->titleTranslator->trans($title, $params);
     return $title;
 }
Esempio n. 2
0
 /**
  * @dataProvider transDataProvider
  */
 public function testTrans($titleTemplate, $params, $expectedResult)
 {
     $this->assertEquals($expectedResult, $this->titleTranslator->trans($titleTemplate, $params));
 }