<?php

namespace Medienreaktor\Energize\UserFunc;


use Medienreaktor\Energize\Service\FieldConfService;
use TYPO3\CMS\Core\Utility\DebugUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class SelectItemsProcFunc
{

    /**
     * Uses the Energize FieldConf API to get this fields items
     * The configuration for this API is under EXT:energize/Configuration/yaml/EnergizeFieldConf.yaml
     *
     * @param $conf array configuration of the field
     */
    public function getItemsForField(&$conf): void
    {
        $fieldConfService = GeneralUtility::makeInstance(FieldConfService::class);
        $tcaItems = $fieldConfService->getTcaItemsByType(
            $conf["table"],
            $conf["field"],
            is_array($conf["row"]["CType"]) ? $conf["row"]["CType"][0] : $conf["row"]["CType"]
        );

        $conf['items'] = $tcaItems;
    }

}
