<?php

/*
 * Smarty plugin
 * -------------------------------------------------------------
 * Type:     function
 * Name:     get_richcontent
 * Purpose:  get a richcontent by kupshop richcontent ID
 * -------------------------------------------------------------
 */

use KupShop\ElninoBundle\Util\RichContentUtil;
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;

function smarty_function_insert_richcontent($params, &$smarty)
{
    extract($params);

    if (empty($params['id'])) {
        return;
    }

    $richContentUtil = ServiceContainer::getService(RichContentUtil::class);
    $content = $richContentUtil->getRichContent($params['id']);

    if (!empty($params['assign'])) {
        $smarty->assign($params['assign'], $content);
    } else {
        return $content;
    }
}
