MetaModels\Attribute\Base::parseValue PHP Method

parseValue() public method

public parseValue ( $arrRowData, $strOutputFormat = 'text', $objSettings = null )
    public function parseValue($arrRowData, $strOutputFormat = 'text', $objSettings = null)
    {
        $arrResult = array('raw' => $arrRowData[$this->getColName()]);
        /** @var ISimpleRenderSetting $objSettings */
        if ($objSettings && $objSettings->get('template')) {
            $strTemplate = $objSettings->get('template');
            $objTemplate = new Template($strTemplate);
            $this->prepareTemplate($objTemplate, $arrRowData, $objSettings);
            // Now the desired format.
            if ($strValue = $objTemplate->parse($strOutputFormat, false)) {
                $arrResult[$strOutputFormat] = $strValue;
            }
            // Text rendering is mandatory, try with the current setting,
            // upon exception, try again with the default settings, as the template name might have changed.
            // if this fails again, we are definately out of luck and bail the exception.
            try {
                $arrResult['text'] = $objTemplate->parse('text', true);
            } catch (\Exception $e) {
                $objSettingsFallback = $this->getDefaultRenderSettings()->setParent($objSettings->getParent());
                $objTemplate = new Template($objSettingsFallback->get('template'));
                $this->prepareTemplate($objTemplate, $arrRowData, $objSettingsFallback);
                $arrResult['text'] = $objTemplate->parse('text', true);
            }
        } else {
            // Text rendering is mandatory, therefore render using default render settings.
            $arrResult = $this->parseValue($arrRowData, 'text', $this->getDefaultRenderSettings());
        }
        // HOOK: apply additional formatters to attribute.
        $arrResult = $this->hookAdditionalFormatters($arrResult, $arrRowData, $strOutputFormat, $objSettings);
        return $arrResult;
    }