Back to UCMContent class

Method mapData

public array
mapData
(mixed $original, \Joomla\CMS\UCM\UCMType $type = null)
Map the original content to the Core Content fields
Parameters
  • array $original The original data array
  • \Joomla\CMS\UCM\UCMType $type Type object for this data
Returns
  • array $ucmData The mapped UCM data
Since
  • 3.1
Class: UCMContent
Project: Joomla

Method mapData - Source code

/**
 * Map the original content to the Core Content fields
 *
 * @param   array    $original  The original data array
 * @param   UCMType  $type      Type object for this data
 *
 * @return  array  $ucmData  The mapped UCM data
 *
 * @since   3.1
 */
public function mapData($original, UCMType $type = null)
{
    $contentType = $type ?: $this->type;
    $fields = json_decode($contentType->type->field_mappings);
    $ucmData = array();
    $common = \is_object($fields->common) ? $fields->common : $fields->common[0];
    foreach ($common as $i => $field) {
        if ($field && $field !== 'null' && \array_key_exists($field, $original)) {
            $ucmData['common'][$i] = $original[$field];
        }
    }
    if (\array_key_exists('special', $ucmData)) {
        $special = \is_object($fields->special) ? $fields->special : $fields->special[0];
        foreach ($special as $i => $field) {
            if ($field && $field !== 'null' && \array_key_exists($field, $original)) {
                $ucmData['special'][$i] = $original[$field];
            }
        }
    }
    $ucmData['common']['core_type_alias'] = $contentType->type->type_alias;
    $ucmData['common']['core_type_id'] = $contentType->type->type_id;
    if (isset($ucmData['special'])) {
        $ucmData['special']['ucm_id'] = $ucmData['common']['ucm_id'];
    }
    $this->ucmData = $ucmData;
    return $this->ucmData;
}