CoreFiles by mySites.guru
TagApiSerializerTrait.php54 lines, 1,282 bytes, from Joomla_4.4.13-Stable-Full_Package.zip
Raw History Compare with 4.4.12
md5
3cfdb7c6c3a1c57c4d3b7fdb91a82fae
sha1
b4099f6733408ab1dcbd6be4f5802066efb8f543
sha256
f887f102a9de9f96a3798948781c72f174d103bbfb565889faa97edc665b505f
<?php

/**
 * Joomla! Content Management System
 *
 * @copyright  (C) 2020 Open Source Matters, Inc. <https://www.joomla.org>
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\CMS\Tag;

use Joomla\CMS\Router\Route;
use Joomla\CMS\Serializer\JoomlaSerializer;
use Joomla\CMS\Uri\Uri;
use Tobscure\JsonApi\Collection;
use Tobscure\JsonApi\Relationship;
use Tobscure\JsonApi\Resource;

// phpcs:disable PSR1.Files.SideEffects
\defined('JPATH_PLATFORM') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Trait for implementing tags in an API Serializer
 *
 * @since  4.0.0
 */
trait TagApiSerializerTrait
{
    /**
     * Build tags relationship
     *
     * @param   \stdClass  $model  Item model
     *
     * @return  Relationship
     *
     * @since 4.0.0
     */
    public function tags($model)
    {
        $resources = [];

        $serializer = new JoomlaSerializer('tags');

        foreach ($model->tags as $id => $tagName) {
            $resources[] = (new Resource($id, $serializer))
                ->addLink('self', Route::link('site', Uri::root() . 'api/index.php/v1/tags/' . $id));
        }

        $collection = new Collection($resources, $serializer);

        return new Relationship($collection);
    }
}

The same content is in 70 releases, Joomla 4.2.1 to 4.4.14. See them all, or every version of this file.