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 locals config option #13

Merged
merged 3 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ FilamentTypes::register([
]);
```

## Config Locales

You can change the locals within the `filament-types` config.

- Publish the config file/
- Modify the `locals` array to include the two character language code that applys to the language you wish to offer. EG:

```
'locals' = ['en'],
```

## Use Type Helper

you can find any type with the helper method to use it anywhere
Expand Down Expand Up @@ -112,7 +123,7 @@ TypeColumn::make('type')
->searchable(),
```

## Auto Caching
## Auto Caching

on your `.env` add this

Expand Down Expand Up @@ -181,7 +192,7 @@ class NotesGroups extends BaseTypePage
}
```

it will be not appear on the navigation menu by default but you can change that by just use this method
it will be not appear on the navigation menu by default but you can change that by just use this method

```php
public static function shouldRegisterNavigation(): bool
Expand All @@ -195,7 +206,7 @@ public static function shouldRegisterNavigation(): bool
if you like to use a type as a package we create a blade component for you to make it easy to use anywhere on your app like this

```html
<x-tomato-type :type="$type" label="Group"/>
<x-tomato-type :type="$type" label="Group" />
```

## User Types Resource Hooks
Expand Down Expand Up @@ -277,7 +288,7 @@ public function boot()
ManagePageActions::register([
Filament\Actions\Action::make('action')
]);

}
```

Expand Down Expand Up @@ -331,7 +342,6 @@ if you like to check the code by `PHPStan` just use this command
composer analyse
```


## Other Filament Packages

Checkout our [Awesome TomatoPHP](https://github.com/tomatophp/awesome)
16 changes: 6 additions & 10 deletions config/filament-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,11 @@
* Locals
*
* If you need to use locals for the types you can set it here
*
* EG: ['en','ar'] will provide English and Arabic options.
*
* Default: NULL, provides English and Arabic options.
*/
'locals' => [
'ar' => [
'ar' => 'العربية',
'en' => 'Arabic',
],
'en' => [
'ar' => 'الإنجليزية',
'en' => 'English',
],
],

'locals' => NULL,
];
8 changes: 3 additions & 5 deletions src/FilamentTypesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ class FilamentTypesPlugin implements Plugin
/**
* @return $this
*/
public function locals(array $locals): self
public function locals()
{
self::$locals = $locals;

return $this;
return (!is_null(config('filament-types.locals'))) ? config('filament-types.locals') : $this->locals;
pschilly marked this conversation as resolved.
Show resolved Hide resolved
}

public function getLocals(): array
{
return self::$locals;
return $this->locals();
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Type compatibility issue confirmed - locals() can return null

The locals() method can indeed return null when both config('filament-types.locals') is null and $this->locals is null, which is incompatible with the getLocals(): array return type declaration. This needs to be fixed by either:

  • Adding null check in getLocals()
  • Ensuring $this->locals is always initialized as an array
  • Changing return type to array|null
🔗 Analysis chain

Verify return type compatibility.

The getLocals() method declares : array return type but calls locals() which could return null. Ensure type compatibility is maintained.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for potential type mismatches in method calls
ast-grep --pattern 'getLocals()' -A 5

Length of output: 39


Script:

#!/bin/bash
# Let's check the class implementation and method signatures
ast-grep --pattern 'class FilamentTypesPlugin {
  $$$
}'

# Also check for the locals() method implementation
ast-grep --pattern 'function locals() {
  $$$
}'

Length of output: 109


Script:

#!/bin/bash
# Let's try with ripgrep to find the class and method implementations
rg -l "class FilamentTypesPlugin" --type php

# Find the locals method
rg "function locals\(" --type php -A 5

Length of output: 474

}

/**
Expand Down
Loading