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 adding Translatable to Panels #99

Merged
merged 2 commits into from
Nov 27, 2023
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
12 changes: 6 additions & 6 deletions src/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function make(array $fields): self

public function __construct(array $fields = [])
{
if (! count(static::$defaultLocales)) {
if (!count(static::$defaultLocales)) {
throw InvalidConfiguration::defaultLocalesNotSet();
}

Expand All @@ -66,7 +66,7 @@ public function __construct(array $fields = [])
$this->originalFields = $fields;

$this->displayLocalizedNameUsingCallback = self::$displayLocalizedNameByDefaultUsingCallback ?? function (Field $field, string $locale) {
return ucfirst($field->name)." ({$locale})";
return ucfirst($field->name) . " ({$locale})";
};

$this->createTranslatableFields();
Expand Down Expand Up @@ -188,9 +188,9 @@ protected function createTranslatedField(Field $originalField, string $locale):

$translatedField
->resolveUsing(function ($value, Model $model) use ($translatedField, $locale, $originalAttribute) {
$translatedField->attribute = 'translations_'.$originalAttribute.'_'.$locale;
$translatedField->panel = $this->panel;
$translatedField->assignedPanel = $this->assignedPanel;
$translatedField->attribute = 'translations_' . $originalAttribute . '_' . $locale;
$translatedField->panel ??= $this->panel;
Copy link
Member

Choose a reason for hiding this comment

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

I believe this operator is only available starting from PHP 7.4.

Could you also up the PHP requirements for this package?

Copy link
Contributor Author

@marijoo marijoo Nov 27, 2023

Choose a reason for hiding this comment

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

Sorry for the style changes I accidentally commited. I reverted them and also now use the ?? instead of ??=. I know this is a little less beautiful, but I don’t think it legitimates requiring [email protected]. What do you think?

Thanks for pointing out that this operator wasn’t available in 7.3.

$translatedField->assignedPanel ??= $this->assignedPanel;

return $model->translations[$originalAttribute][$locale] ?? '';
});
Expand Down Expand Up @@ -226,7 +226,7 @@ protected function createTranslatedField(Field $originalField, string $locale):

protected function onIndexPage(): bool
{
if (! request()->route()) {
if (!request()->route()) {
return false;
}

Expand Down
Loading