Rework admin panel and other
This commit is contained in:
@@ -3,42 +3,27 @@
|
||||
namespace App\Filament\Resources\AcademicJournalResource\Pages;
|
||||
|
||||
use App\Filament\Resources\AcademicJournalResource;
|
||||
use App\Services\Filament\Traits\SeoGenerate;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CreateAcademicJournal extends CreateRecord
|
||||
{
|
||||
protected static string $resource = AcademicJournalResource::class;
|
||||
use SeoGenerate;
|
||||
|
||||
protected array $seoData;
|
||||
protected static string $resource = AcademicJournalResource::class;
|
||||
|
||||
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
$this->seoData = $this->generateSeo($data);
|
||||
$data['search_data'] = $this->generateSearchData($data['main_info']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function afterCreate(): void
|
||||
{
|
||||
$this->record->seo()->create($this->seoData);
|
||||
}
|
||||
|
||||
private function generateSeo(array $data) : array
|
||||
{
|
||||
$title = $data['title'];
|
||||
$rowData = $this->getFirstBlockByName('paragraph', $data['main_info']);
|
||||
if ($rowData !== null) {
|
||||
$description = strip_tags($rowData['data']['content']);
|
||||
} else {
|
||||
$description = null;
|
||||
}
|
||||
return [
|
||||
'title' => $title,
|
||||
'description' => Str::limit(htmlspecialchars($description, ENT_QUOTES, 'UTF-8'), 160),
|
||||
];
|
||||
$this->createSeo($this->record);
|
||||
}
|
||||
|
||||
private function generateSearchData(array $data) : string
|
||||
|
||||
@@ -3,20 +3,21 @@
|
||||
namespace App\Filament\Resources\AcademicJournalResource\Pages;
|
||||
|
||||
use App\Filament\Resources\AcademicJournalResource;
|
||||
use App\Services\Filament\Traits\SeoGenerate;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class EditAcademicJournal extends EditRecord
|
||||
{
|
||||
use SeoGenerate;
|
||||
|
||||
protected static string $resource = AcademicJournalResource::class;
|
||||
|
||||
protected array $seoData;
|
||||
|
||||
|
||||
protected function mutateFormDataBeforeSave(array $data): array
|
||||
{
|
||||
$this->seoData = $this->generateSeo($data);
|
||||
$data['search_data'] = $this->generateSearchData($data['main_info']);
|
||||
|
||||
return $data;
|
||||
@@ -24,24 +25,7 @@ class EditAcademicJournal extends EditRecord
|
||||
|
||||
protected function afterSave(): void
|
||||
{
|
||||
$this->record->seo()->update($this->seoData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function generateSeo(array $data) : array
|
||||
{
|
||||
$title = $data['title'];
|
||||
$rowData = $this->getFirstBlockByName('paragraph', $data['main_info']);
|
||||
if ($rowData !== null) {
|
||||
$description = strip_tags($rowData['data']['content']);
|
||||
} else {
|
||||
$description = null;
|
||||
}
|
||||
return [
|
||||
'title' => $title,
|
||||
'description' => Str::limit(htmlspecialchars($description, ENT_QUOTES, 'UTF-8'), 160),
|
||||
];
|
||||
$this->updateSeo($this->record);
|
||||
}
|
||||
|
||||
private function getDataFromBlocks($block) : string
|
||||
@@ -94,15 +78,6 @@ class EditAcademicJournal extends EditRecord
|
||||
|
||||
return strtolower($result);
|
||||
}
|
||||
private function getFirstBlockByName(string $name, array $content) : array|null
|
||||
{
|
||||
$data = null;
|
||||
foreach ($content as $block) {
|
||||
$data = ($block['type'] === $name) ? $block : null;
|
||||
break;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user