コード例 #1
0
 /**
  * Presents an attribute option
  *
  * @param string $value
  * @param string $optionName
  *
  * @return string|null
  */
 public function attributeOptionPresenter($value, $optionName)
 {
     $presenter = $this->presenterRegistry->getAttributeOptionPresenter($optionName);
     if (null !== $presenter) {
         $locale = $this->localeResolver->getCurrentLocale();
         if (null !== $locale) {
             return $presenter->present($value, ['locale' => $locale]);
         }
     }
     return $value;
 }
コード例 #2
0
 /**
  * Localize the changeset values
  *
  * @param array $changeset
  *
  * @return array
  */
 protected function convertChangeset(array $changeset)
 {
     $options = ['locale' => $this->localeResolver->getCurrentLocale()];
     foreach ($changeset as $attribute => $changes) {
         $options['versioned_attribute'] = $attribute;
         $attributeName = $attribute;
         if (preg_match('/^(?<attribute>[a-zA-Z0-9_]+)-.+$/', $attribute, $matches)) {
             $attributeName = $matches['attribute'];
         }
         $presenter = $this->presenterRegistry->getPresenterByAttributeCode($attributeName);
         if (null !== $presenter) {
             foreach ($changes as $key => $value) {
                 $changeset[$attribute][$key] = $presenter->present($value, $options);
             }
         }
     }
     return $changeset;
 }