PHP code example of fork / craft-transform

1. Go to this page and download the library: Download fork/craft-transform library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fork / craft-transform example snippets




return [
    '*' => [
        'transformerNamespace' => '\company\project\transformers'
    ],
    'dev' => [
        'enableCache' => false,
    ],
    'staging' => [
        'enableCache' => true,
    ],
    'production' => [
        'enableCache' => true,
    ],
];



namespace company\project\transformers;

use Craft;
use League\Fractal\TransformerAbstract;

class FooterTransformer extends TransformerAbstract {

    public function transform()
    {
        $footer = Craft::$app->globals->getSetByHandle('footer');
        $footerNavGlobals = $footer->footerNavigationElements->all();
        $footerLinks = [];

        foreach ($footerNavGlobals as $linkEntry) {
            $link = [
                'href' => $linkEntry->navigationLink->getUrl(),
                'name' => $linkEntry->navigationLink->getText(),
                'slug' => $linkEntry->navigationLink->hasElement() ? $linkEntry->navigationLink->getElement()->slug : $linkEntry->navigationLink->getUrl(),
                'target' => $linkEntry->navigationLink->getTarget()
            ];
            $footerLinks[] = $link;
        }

        return $footerLinks;
    }

}