File: D:/HostingSpaces/SBogers10/netwerkbrabant.komma.pro/app/KommaApp/Tags/Kms/TagService.php
<?php
namespace App\KommaApp\Tags\Kms;
use App\Helpers\KommaHelpers;
use App\KommaApp\Tags\Models\Tag;
use App\KommaApp\Kms\Core\AbstractTranslatableModel;
use App\KommaApp\Kms\Core\Attributes\Attribute;
use App\KommaApp\Kms\Core\Sections\SectionService;
use App\KommaApp\Kms\SidebarListItem;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
class TagService extends SectionService
{
protected $sortable = false;
protected $orderByDisplayName = true;
protected $orderReverse = false;
function __construct()
{
$this->forModelName = Tag::class;
parent::__construct();
}
public function saveModel(Model $model = null, Collection $sectionTabItems): Model
{
/** @var TreeModel $model */
$sectionTabItems->each(function($sectionTabItem, $key) use($model) {
/** @var SectionTabItem $sectionTabItem */
$attribute = $sectionTabItem->getAttribute();
$reference = $attribute->getsValueFromReference();
switch ($attribute->getsValueFrom())
{
case Attribute::ValueFromTranslationModel:
if($reference == 'name')
{
/** @var Language $language */
$language = $attribute->getAssociatedLanguage();
$translation = $this->getTranslationModelForModelByLanguage($model, $language);
$translation['slug'] = $this->createOrGetUniqueSlug($translation, $attribute->getValue());
}
break;
}
});
$model->save(); //Save the newsArticle
$model = parent::saveModel($model, $sectionTabItems); //First make sure we have a model and save the attributes in them from the SectionTabItem attributes
return $model;
}
}