Ojs\CoreBundle\Entity\TranslateableTrait::getLogicalFieldTranslation PHP Method

getLogicalFieldTranslation() public method

public getLogicalFieldTranslation ( $field, boolean $withLocale = true ) : string
$field
$withLocale boolean
return string
    public function getLogicalFieldTranslation($field, $withLocale = true)
    {
        $accessor = PropertyAccess::createPropertyAccessor();
        $fieldValue = $accessor->getValue($this->translate(), $field);
        if (!empty($fieldValue) && $fieldValue !== '-') {
            if ($withLocale) {
                return '[' . $this->getCurrentLocale() . ']' . $fieldValue;
            } else {
                return $fieldValue;
            }
        }
        foreach ($this->translations as $translation) {
            $fieldValue = $accessor->getValue($translation, $field);
            if (!empty($fieldValue) && $fieldValue !== '-') {
                if ($withLocale) {
                    return '[' . $translation->getLocale() . ']' . $fieldValue;
                } else {
                    return $fieldValue;
                }
            }
        }
        return '';
    }