tag settings

This commit is contained in:
Билай Станислав 2024-11-27 16:19:19 +03:00
parent 6d9d19ce36
commit bba35c7b14
8 changed files with 21 additions and 5 deletions

View File

@ -71,6 +71,7 @@ class TagModule extends Module
{
$tag = new Tag();
$tag->label = $request->post('tag');
$tag->entity = $entity;
$tag->status = Tag::ACTIVE_STATUS;
$tag->slug = Slug::createSlug($request->post('tag'), $model);
$tag->save();

View File

@ -18,13 +18,14 @@ class EntityRelation
}
public function getEntityList(): array
public static function getEntityList(): array
{
$list = [];
$activeModules = $this->moduleService->getActiveModules();
$moduleService = new ModuleService();
$activeModules = $moduleService->getActiveModules();
foreach ($activeModules as $module) {
if (isset($module['type']) and $module['type'] === "entity") {
$list[] = $module['slug'];
$list[$module['slug']] = $module['name'];
}
}

View File

@ -100,7 +100,7 @@ class TagController extends AdminController
public function actionSettings(): void
{
echo "tag settings";
$this->cgView->render('form.php');
}
}

View File

@ -14,6 +14,7 @@ return new class extends Migration
\kernel\App::$db->schema->create('tag', function (Blueprint $table) {
$table->increments('id');
$table->string('label', 255)->nullable(false);
$table->string('entity', 255)->nullable(false);
$table->string('slug', 255)->unique();
$table->integer('status')->default(1);
$table->timestamps();

View File

@ -25,6 +25,7 @@ class Tag extends Model
{
return [
'label' => 'Заголовок',
'entity' => 'Сущность',
'slug' => 'Slug',
'status' => 'Статус',
];

View File

@ -11,6 +11,7 @@ class CreateTagForm extends FormModel
{
return [
'label' => 'required|min-str-len:5|max-str-len:30',
'entity' => 'required',
'slug' => '',
'status' => ''
];

View File

@ -4,15 +4,17 @@ namespace kernel\app_modules\tag\services;
use kernel\app_modules\tag\models\Tag;
use kernel\FormModel;
use kernel\helpers\Debug;
use kernel\helpers\Slug;
use kernel\services\ModuleService;
class TagService
{
public function create(FormModel $form_model): false|Tag
{
$model = new Tag();
$model->label = $form_model->getItem('label');
$model->entity = $form_model->getItem('entity');
$model->status = $form_model->getItem('status');
$model->slug = Slug::createSlug($form_model->getItem('label'), Tag::class);
if ($model->save()){
@ -28,6 +30,7 @@ class TagService
$tag->slug = Slug::createSlug($form_model->getItem('label'), Tag::class);
}
$tag->label = $form_model->getItem('label');
$tag->entity = $form_model->getItem('entity');
$tag->status = $form_model->getItem('status');
if ($tag->save()){

View File

@ -16,6 +16,14 @@ $form->field(class: \itguild\forms\inputs\TextInput::class, name: "label", param
->setLabel("Заголовок")
->render();
$form->field(class: \itguild\forms\inputs\Select::class, name: "entity", params: [
'class' => "form-control",
'value' => $model->entity ?? ''
])
->setLabel("Сущность")
->setOptions(\kernel\EntityRelation::getEntityList())
->render();
$form->field(\itguild\forms\inputs\Select::class, 'status', [
'class' => "form-control",
'value' => $model->status ?? ''