visualbuilder / email-templates

Email Template Editor for Filament
GNU General Public License v3.0
74 stars 19 forks source link

Change the translation of the headers #24

Closed slash12 closed 4 weeks ago

slash12 commented 4 weeks ago

image

i try to override the email template resource, for the navigation group, it works but not for the headers. I'm kinda lost

cannycookie commented 4 weeks ago

Hmm we need to update the table to have translateable labels. The table columns need

->label(__('vb-email-templates::email-templates.form-fields-labels.xxxxx'))

In here: https://github.com/visualbuilder/email-templates/blob/9254df243ffd9dbb587e540752fac9b9e866c649/src/Resources/EmailTemplateResource.php

   public static function table(Table $table): Table
    {

        return $table
            ->query(EmailTemplate::query())
            ->columns(
            [
                TextColumn::make('id')
                        ->sortable()
                        ->searchable(),
                TextColumn::make('name')
                        ->limit(50)
                        ->sortable()
                        ->searchable(),
                TextColumn::make('language')
                        ->limit(50),
                TextColumn::make('subject')
                        ->searchable()
                        ->limit(50),
            ]
        )

If you need it urgently then just create a new resource and extend this file. You'll just need to copy n paste the table method and add the labels. Pull request welcomed :-)

slash12 commented 3 weeks ago

I did as you requested, here is my code:



namespace App\Filament\Resources\EmailTemplates;

use Filament\Notifications\Notification;
use Filament\Tables;
use Filament\Tables\Actions\Action;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\View\View;
use Visualbuilder\EmailTemplates\Contracts\CreateMailableInterface;
use Visualbuilder\EmailTemplates\Models\EmailTemplate;
use Visualbuilder\EmailTemplates\Resources\EmailTemplateResource as VisualBuilderEmailTemplateResource;

class EmailTemplateResource extends VisualBuilderEmailTemplateResource
{
    public static function getNavigationGroup(): ?string
    {
        return __('admin.site_general_settings');
    }

    public static function table(Table $table): Table
    {

        return $table
            ->query(EmailTemplate::query())
            ->columns(
                [
                    TextColumn::make('id')
                        ->sortable()
                        ->searchable(),
                    TextColumn::make('test name')
                        ->limit(50)
                        ->sortable()
                        ->searchable(),
                    TextColumn::make('language')
                        ->limit(50),
                    TextColumn::make('subject')
                        ->searchable()
                        ->limit(50),
                ]
            )
            ->filters(
                [
                    Tables\Filters\TrashedFilter::make(),
                ]
            )
            ->actions(
                [
                    Action::make('create-mail-class')
                        ->label("Build Class")
                        //Only show the button if the file does not exist
                        ->visible(function (EmailTemplate $record) {
                            return !$record->mailable_exists;
                        })
                        ->icon('heroicon-o-document-text')
                        // ->action('createMailClass'),
                        ->action(function (EmailTemplate $record) {
                            $notify = app(CreateMailableInterface::class)->createMailable($record);
                            Notification::make()
                                ->title($notify->title)
                                ->icon($notify->icon)
                                ->iconColor($notify->icon_color)
                                ->duration(10000)
                                //Fix for bug where body hides the icon
                                ->body("<span style='overflow-wrap: anywhere;'>" . $notify->body . "</span>")
                                ->send();
                        }),
                    Tables\Actions\ViewAction::make('Preview')
                        ->icon('heroicon-o-magnifying-glass')
                        ->modalContent(fn(EmailTemplate $record): View => view(
                            'vb-email-templates::forms.components.iframe',
                            ['record' => $record],
                        ))->form(null)
                        ->modalHeading(fn(EmailTemplate $record): string => 'Preview Email: ' . $record->name)
                        ->modalSubmitAction(false)
                        ->modalCancelAction(false)
                        ->slideOver(),

                    Tables\Actions\EditAction::make(),
                    Tables\Actions\DeleteAction::make(),
                    Tables\Actions\ForceDeleteAction::make()
                        ->before(function (EmailTemplate $record, \Visualbuilder\EmailTemplates\Resources\EmailTemplateResource $emailTemplateResource) {
                            $emailTemplateResource->handleLogoDelete($record->logo);
                        }),
                    Tables\Actions\RestoreAction::make(),
                ]
            )
            ->bulkActions(
                [
                    Tables\Actions\DeleteBulkAction::make(),
                    Tables\Actions\ForceDeleteBulkAction::make(),
                    Tables\Actions\RestoreBulkAction::make(),
                ]
            );
    }
}```

i change name heading to 'test name' but it is not overriden...and i don't why
cannycookie commented 3 weeks ago

No the attribute names must be the same as the database. Use the label property:-

 TextColumn::make('name')
                        ->label('Nome')
                        ->limit(50)
                        ->sortable()
                        ->searchable(),
slash12 commented 3 weeks ago

<?php

namespace App\Filament\Resources\EmailTemplates;

use Filament\Notifications\Notification;
use Filament\Tables;
use Filament\Tables\Actions\Action;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\View\View;
use Visualbuilder\EmailTemplates\Contracts\CreateMailableInterface;
use Visualbuilder\EmailTemplates\Models\EmailTemplate;
use Visualbuilder\EmailTemplates\Resources\EmailTemplateResource as VisualBuilderEmailTemplateResource;

class EmailTemplateResource extends VisualBuilderEmailTemplateResource
{
    public static function getNavigationGroup(): ?string
    {
        return __('admin.site_general_settings');
    }

    public static function table(Table $table): Table
    {

        return $table
            ->query(EmailTemplate::query())
            ->columns(
                [
                    TextColumn::make('id')
                        ->sortable()
                        ->searchable(),
                    TextColumn::make('name')
                        ->label('test')
                        ->limit(50)
                        ->sortable()
                        ->searchable(),
                    TextColumn::make('language')
                        ->limit(50),
                    TextColumn::make('subject')
                        ->searchable()
                        ->limit(50),
                ]
            )
            ->filters(
                [
                    Tables\Filters\TrashedFilter::make(),
                ]
            )
            ->actions(
                [
                    Action::make('create-mail-class')
                        ->label("Build Class")
                        //Only show the button if the file does not exist
                        ->visible(function (EmailTemplate $record) {
                            return !$record->mailable_exists;
                        })
                        ->icon('heroicon-o-document-text')
                        // ->action('createMailClass'),
                        ->action(function (EmailTemplate $record) {
                            $notify = app(CreateMailableInterface::class)->createMailable($record);
                            Notification::make()
                                ->title($notify->title)
                                ->icon($notify->icon)
                                ->iconColor($notify->icon_color)
                                ->duration(10000)
                                //Fix for bug where body hides the icon
                                ->body("<span style='overflow-wrap: anywhere;'>" . $notify->body . "</span>")
                                ->send();
                        }),
                    Tables\Actions\ViewAction::make('Preview')
                        ->icon('heroicon-o-magnifying-glass')
                        ->modalContent(fn(EmailTemplate $record): View => view(
                            'vb-email-templates::forms.components.iframe',
                            ['record' => $record],
                        ))->form(null)
                        ->modalHeading(fn(EmailTemplate $record): string => 'Preview Email: ' . $record->name)
                        ->modalSubmitAction(false)
                        ->modalCancelAction(false)
                        ->slideOver(),

                    Tables\Actions\EditAction::make(),
                    Tables\Actions\DeleteAction::make(),
                    Tables\Actions\ForceDeleteAction::make()
                        ->before(function (EmailTemplate $record, \Visualbuilder\EmailTemplates\Resources\EmailTemplateResource $emailTemplateResource) {
                            $emailTemplateResource->handleLogoDelete($record->logo);
                        }),
                    Tables\Actions\RestoreAction::make(),
                ]
            )
            ->bulkActions(
                [
                    Tables\Actions\DeleteBulkAction::make(),
                    Tables\Actions\ForceDeleteBulkAction::make(),
                    Tables\Actions\RestoreBulkAction::make(),
                ]
            );
    }
}

still not working 
cannycookie commented 3 weeks ago

do you have this in your Panel provider config:-

            ->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')

Also is your namespace right?

namespace App\Filament\Resources\EmailTemplates;

perhaps it should be:-

namespace App\Filament\Resources;

can you try composer du to check your classes are loaded

slash12 commented 3 weeks ago

do you have this in your Panel provider config: Yes this is defined

Also is your namespace right?

i have tried both App\Filament\Resources\EmailTemplates and App\Filament\Resources, but the problem persists

composer du: image

slash12 commented 3 weeks ago

Well, i finally got the solution, it was a crazy journey 🥲 , all i have done is remove this line 'EmailTemplatesPlugin::make()' from AdminPanelProvider.php and redefine the function 'getPages' in the EmailTemplateResource and EmailTemplateThemeResource to point to my overridden pages and it works finally