Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(AssetDefinition): prevent PHP warning about missing translation on create #17084

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Asset/AssetDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,12 @@ private function validateCapacityArray(mixed $capacities, bool $check_values = t
*/
private function getDecodedTranslationsField(): array
{
// prevent warning when no translation are available (create step)
if (empty($this->fields['translations'])) {
$this->fields['translations'] = '[]'; // prevent warning to be triggered on each method call
return [];
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may hide unexpected empty value on existing items.
Another possible fix is to check if item is new in the getTranslatedName() method:

    public function getTranslatedName(int $count = 1): string
    {
        if ($this->isNewItem()) {
            return '';
        }

By the way, I do not even see where the translated name would be displayed in the creation form.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


$translations = @json_decode($this->fields['translations'], associative: true);
if (!$this->validateTranslationsArray($translations)) {
trigger_error(
Expand Down
Loading