Skip to content

Commit

Permalink
Merge pull request #52 from sitegeist/bugfix/89219/ArrayToString
Browse files Browse the repository at this point in the history
Bugfix/89219/array to string
  • Loading branch information
galoppi authored May 24, 2024
2 parents 785c62a + 4c75409 commit 234eb75
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 36 deletions.
44 changes: 16 additions & 28 deletions Classes/ViewHelpers/TranslateElementPropertyViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,23 @@ class TranslateElementPropertyViewHelper extends \TYPO3\CMS\Form\ViewHelpers\Tra

use RenderTranslation;

protected static function getPropertyName($property)
protected static function getPropertyName(string|array $property): string
{
return \is_array($property) ? implode('.', $property) : $property;
if (is_string($property)) {
return $property;
}

if (count($property) === count($property, COUNT_RECURSIVE)) {
return implode('.', $property);
}

return $property[0] ?? '';
}

public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
$element = $arguments['element'];

$renderingOptions = $element->getRenderingOptions();

$property = null;
$propertyType = 'properties';

Expand All @@ -74,25 +80,6 @@ public static function renderStatic(array $arguments, \Closure $renderChildrenCl
$propertyParts = [$property];
}

if ($property === 'label') {
$defaultValue = $element->getLabel();
} else {
if ($element instanceof FormElementInterface) {
try {
$defaultValue = ArrayUtility::getValueByPath($element->getProperties(), $propertyParts, '.');
} catch (MissingArrayPathException $exception) {
$defaultValue = null;
}
} else {
$propertyType = 'renderingOptions';
try {
$defaultValue = ArrayUtility::getValueByPath($renderingOptions, $propertyParts, '.');
} catch (MissingArrayPathException $exception) {
$defaultValue = null;
}
}
}

/** @var TYPO3\CMS\Form\FormRuntime $formRuntime */
$formRuntime = $renderingContext
->getViewHelperVariableContainer()
Expand All @@ -119,17 +106,18 @@ public static function renderStatic(array $arguments, \Closure $renderChildrenCl
$formIdentifier,
$element->getIdentifier(),
'properties',
self::getPropertyName($property)
self::getPropertyName($property),
);
try {

$translationArguments = [];
if (!empty($element->getRenderingOptions()['translation']['arguments'])) {
$translationArguments = ArrayUtility::getValueByPath(
$element->getRenderingOptions()['translation']['arguments'] ?? [],
$propertyParts,
$translationKey,
'.'
);
} catch (MissingArrayPathException $e) {
$translationArguments = [];
}

$ret = parent::renderStatic($arguments, $renderChildrenClosure, $renderingContext);
if ($property === 'label' ||
$property === 'elementDescription' ||
Expand Down
15 changes: 8 additions & 7 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,15 @@ default language.
## Change Log
| translatelabels | TYPO3 | Changes |
|-----------------|--------|-----------------------------------------|
| 1.0.x | 9.5.x | Initial release |
| 1.1.x | 9.5.x | Removed LLL:EXT: prefix from label keys |
| 2.0.x | 10.1.x | Compatibility for TYPO3 10.1 |
| 2.1.x | 11.5.x | Compatibility for TYPO3 11.5 |
| 2.3.0 | 11.5.x | Compatibility for PHP 8.1 |
| translatelabels | TYPO3 | Changes |
|-----------------|--------|--------------------------------------------------------|
| 1.0.x | 9.5.x | Initial release |
| 1.1.x | 9.5.x | Removed LLL:EXT: prefix from label keys |
| 2.0.x | 10.1.x | Compatibility for TYPO3 10.1 |
| 2.1.x | 11.5.x | Compatibility for TYPO3 11.5 |
| 2.3.0 | 11.5.x | Compatibility for PHP 8.1 |
| 2.3.2 | 11.5.x | Added event dispatcher to show translate labels or not |
| 2.3.5 | 11.5.x | Bugfix: PHP Warning: Array to string conversion | |
## How to activate for BE users
Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'author' => 'Alexander Bohndorf',
'author_email' => '[email protected]',
'state' => 'beta',
'version' => '2.3.4',
'version' => '2.3.5',
'constraints' => [
'depends' => [
'typo3' => '10.0.0-11.5.99',
Expand Down

0 comments on commit 234eb75

Please sign in to comment.