コード例 #1
0
ファイル: ConfigHelper.php プロジェクト: Maksold/platform
 /**
  * Returns translation key (placeholder) by entity class name, field name and property code
  * examples (for default scope which is 'entity'):
  *      [vendor].[bundle].[entity].[field].[config property]
  *      oro.user.group.name.label
  *
  *      if [entity] == [bundle] -> skip it
  *      oro.user.first_name.label
  *
  *      if NO fieldName -> add prefix 'entity_'
  *      oro.user.entity_label
  *      oro.user.group.entity_label
  * examples (for other scopes, for instance 'test'):
  *      [vendor].[bundle].[entity].[field].[scope]_[config property]
  *      oro.user.group.name.test_label
  *
  *      if [entity] == [bundle] -> skip it
  *      oro.user.first_name.test_label
  *
  *      if NO fieldName -> add prefix 'entity_'
  *      oro.user.entity_test_label
  *      oro.user.group.entity_test_label
  *
  * @param string $scope
  * @param string $propertyName property key: label, description, plural_label, etc.
  * @param string $className
  * @param string $fieldName
  *
  * @return string
  *
  * @throws \InvalidArgumentException
  */
 public static function getTranslationKey($scope, $propertyName, $className, $fieldName = null)
 {
     if (empty($scope)) {
         throw new \InvalidArgumentException('$scope must not be empty');
     }
     if (empty($propertyName)) {
         throw new \InvalidArgumentException('$propertyName must not be empty');
     }
     if (empty($className)) {
         throw new \InvalidArgumentException('$className must not be empty');
     }
     // handle 'entity' scope separately
     if ($scope === 'entity') {
         return EntityLabelBuilder::getTranslationKey($propertyName, $className, $fieldName);
     }
     $parts = EntityLabelBuilder::explodeClassName($className);
     $propertyName = Inflector::tableize($scope) . '_' . $propertyName;
     if ($fieldName) {
         $parts[] = Inflector::tableize($fieldName);
         $parts[] = $propertyName;
     } else {
         $parts[] = 'entity_' . $propertyName;
     }
     return implode('.', $parts);
 }
コード例 #2
0
 /**
  * @dataProvider getTranslationKeyProvider
  */
 public function testGetTranslationKey($expected, $propertyName, $className, $fieldName)
 {
     $result = EntityLabelBuilder::getTranslationKey($propertyName, $className, $fieldName);
     $this->assertEquals($expected, $result);
 }