Returns given $fields structured in hash array with field definition ids and language codes as keys.

@param \eZ\Publish\SPI\Persistence\Content\Field[] $fields
@param array $languageCodes

@return \eZ\Publish\SPI\Persistence\Content\Field[][]
497104
protected function getFieldMap(array $fields, &$languageCodes = null)
    {
        $fieldMap = array();
        foreach ($fields as $field) {
            if (isset($languageCodes)) {
                $languageCodes[$field->languageCode] = true;
            }
            $fieldMap[$field->fieldDefinitionId][$field->languageCode] = $field;
        }

        return $fieldMap;
    }
7333
public function getSimpleTree($fields=array(),$transfields=array(),$lang='',$wh=array()){
		$lang=$this->detectLanguage($lang);
		//
		$cachekey=$this->tableName.':simpletree:'.$lang;
		if(!empty($wh)){
			$cachekey.=':wh('.implode(';',$wh).')';
		}
		//Try to get simple tree from internal cache...
		static $cache_simpletree=array();
		if(isset($cache_simpletree[$cachekey])){
			return $cache_simpletree[$cachekey];
			}
		//
		$bcache=\Brilliant\BFactory::getCache();
		if($bcache){
			$res=$bcache->get($cachekey);
			if(($res!==false)&&($res!==NULL)){
				$this->cache_simpletree[$lang]=$res;
				return $res;
				}
			}
		//Load simle cities names.
		if(!$db=\Brilliant\BFactory::getDBO()){return NULL;}
		$qr='SELECT `'.$this->primaryKeyName.'`';
		foreach($fields as $fld){
			$qr.=', `'.$fld.'`';
			}
		foreach($transfields as $fld){
			$qr.=', `'.$fld.'_'.$lang.'` as `'.$fld.'`';
			}
		$qr.=' FROM `'.$this->tableName.'`';
		if(!empty($wh)){
			$qr.=' WHERE ('.implode(' AND ',$wh).')';
			}
		$qr.=' ORDER BY `'.$this->leftKeyName.'`;';
		$q=$db->Query($qr);
		if(empty($q)){
			return $res;
			}
		//
		$res=array();
		while($l=$db->fetch($q)){
			$id=(int)$l[$this->primaryKeyName];
			$val=array();
			$val[$this->primaryKeyName]=$id;
			foreach($fields as $fld){
				$val[$fld]=$l[$fld];
				}
			foreach($transfields as $fld){
				$val[$fld]=$l[$fld];
				}
			$xval=(object)$val;
			$this->getSimpleTreeFilterItem($xval);
			$res[$id]=$xval;
			}
		$this->cache_simpletree[$cachekey]=$res;
		if($bcache){
			$bcache->set($cachekey,$res,3600);//1 hour
			}
		return $res;
		}
1023781
public static function fromArray(array $properties, $localeGroup, array $languages = [])
    {
        $resource = new Resource();

        if (array_key_exists('fields', $properties) && is_array($properties['fields'])) {
            $resource->fields = FieldTransformer::fromArray($properties['fields'], $localeGroup, $languages, true);
        }

        if (array_key_exists('relations', $properties) && is_array($properties['relations'])) {
            $resource->relations = self::getRelations($properties['relations']);
        }

        if (array_key_exists('indexes', $properties) && is_array($properties['indexes'])) {
            $resource->indexes = self::getIndexes($properties['indexes']);
        }

        if (array_key_exists('auto-manage-created-and-updated-at', $properties)) {
            $resource->setCreateAndUpdateAtManaged($properties['auto-manage-created-and-updated-at']);
        }

        if (array_key_exists('table-name', $properties)) {
            $resource->setTableName($properties['table-name']);
        }

        if (array_key_exists('protection', $properties) && is_array($properties['protection'])) {

            foreach ($properties['protection'] as $name => $value) {
                $resource->setProtection($name, $value);
            }

        }

        return $resource;
    }
526229
public function getLanguage($languageCode = null): ?string
    {
        $languageCode = $languageCode ? mb_strtoupper($languageCode) : null;

        return $this->get("languages.{$languageCode}") ?: (current($this->get('languages', [])) ?: null);
    }
972234
public function get( array $languageIds )
	{
		$i18nPaths = $this->container->get( 'aimeos' )->get()->getI18nPaths();

		foreach( $languageIds as $langid )
		{
			if( !isset( $this->i18n[$langid] ) )
			{
				$i18n = new \Aimeos\MW\Translation\Gettext( $i18nPaths, $langid );

				$apc = (bool) $this->container->getParameter( 'aimeos_shop.apc_enable' );
				$prefix = $this->container->getParameter( 'aimeos_shop.apc_prefix' );

				if( function_exists( 'apcu_store' ) === true && $apc === true ) {
					$i18n = new \Aimeos\MW\Translation\Decorator\APC( $i18n, $prefix );
				}

				$translations = $this->container->getParameter( 'aimeos_shop.i18n' );

				if( isset( $translations[$langid] ) ) {
					$i18n = new \Aimeos\MW\Translation\Decorator\Memory( $i18n, $translations[$langid] );
				}

				$this->i18n[$langid] = $i18n;
			}
		}

		return $this->i18n;
	}
526181
public static function addCodes($langs)
    {
        // Get languages from config
        $languages = config('localizer_languages.languages');

        $array = [];

        // Generate an array with $lang as key and $lang code as value
        foreach ($langs as $lang) {
            $lang_code = 'unk';

            foreach ($languages as $language) {
                if ($language['name'] == $lang) {
                    $lang_code = $language['code'];
                }
            }

            $array[$lang] = $lang_code;
        }

        return $array;
    }
393499
public function getAllEmailAddresses($fields = ['to', 'from', 'cc', 'bcc'])
    {
        $addresses = [];
        foreach ($fields as $field) {
            if(isset($this->allEmailAddressesByField[$field])) {
                foreach ($this->allEmailAddressesByField[$field] as $emailAddress) {
                    $addresses[] = $emailAddress;
                }
            }
        }

        return array_unique($addresses);
    }
202844
public function getMappedField($field, $language, $fallbackLanguage = null)
    {
        if ($this->mappedFields->containsKey($language)) {
            $mappedField = $this->mappedFields->get($language);
        } elseif ($this->mappedFields->containsKey($fallbackLanguage)) {
            $mappedField = $this->mappedFields->get($fallbackLanguage);
        } else {
            foreach ($this->mappedFields as $testMappedField) {
                if ($testMappedField->getLanguage() === $language) {
                    $mappedField = $testMappedField;
                    break;
                }
            }
            if (!isset($mappedField)) {
                foreach ($this->mappedFields as $testMappedField) {
                    if ($testMappedField->getLanguage() === $fallbackLanguage) {
                        $mappedField = $testMappedField;
                        break;
                    }
                }
            }
            if (!isset($mappedField)) {
                return null;
            }
        }

        if ($field === 'page') {
            if ($mappedField->getPage()) {
                return $mappedField->getPage();
            } else {
                $field = 'backend';
            }
        }

        if ($field === 'navigation') {
            if ($mappedField->getNavigation()) {
                return $mappedField->getNavigation();
            } else {
                $field = 'backend';
            }
        }

        if ($field === 'backend') {
            return $mappedField->getBackend();
        }

        if ($field === 'date' && $mappedField->getDate()) {
            return $mappedField->getDate();
        }

        if ($field === 'forward' && $mappedField->getForward()) {
            return json_decode($mappedField->getForward(), true);
        }

        if ($field === 'custom1' && $mappedField->getCustom1()) {
            return $mappedField->getCustom1();
        } elseif ($field === 'custom2' && $mappedField->getCustom2()) {
            return $mappedField->getCustom2();
        } elseif ($field === 'custom3' && $mappedField->getCustom3()) {
            return $mappedField->getCustom3();
        } elseif ($field === 'custom4' && $mappedField->getCustom4()) {
            return $mappedField->getCustom4();
        } elseif ($field === 'custom5' && $mappedField->getCustom5()) {
            return $mappedField->getCustom5();
        }

        return null;
    }
999240
protected function mergeFieldMap(Content $content, array $fieldMap, array $languageCodes)
    {
        if (empty($fieldMap)) {
            return $content->fields;
        }

        $mergedFieldMap = array();

        foreach ($content->fields as $fieldIdentifier => $fieldLanguageMap) {
            foreach ($languageCodes as $languageCode) {
                $mergedFieldMap[$fieldIdentifier][$languageCode] = isset($fieldMap[$fieldIdentifier][$languageCode])
                    ? $fieldMap[$fieldIdentifier][$languageCode]
                    : $fieldLanguageMap[$languageCode];
            }
        }

        return $mergedFieldMap;
    }
441681
public function getFieldName(SPIValue $value, FieldDefinition $fieldDefinition, $languageCode)
    {
        if (empty($value->selection)) {
            return '';
        }

        $names = [];
        $fieldSettings = $fieldDefinition->getFieldSettings();

        foreach ($value->selection as $optionIndex) {
            if (isset($fieldSettings['multilingualOptions'][$languageCode][$optionIndex])) {
                $names[] = $fieldSettings['multilingualOptions'][$languageCode][$optionIndex];
            } elseif (isset($fieldSettings['multilingualOptions'][$fieldDefinition->mainLanguageCode][$optionIndex])) {
                $names[] = $fieldSettings['multilingualOptions'][$fieldDefinition->mainLanguageCode][$optionIndex];
            } elseif (isset($fieldSettings['options'][$optionIndex])) {
                $names[] = $fieldSettings['options'][$optionIndex];
            }
        }

        return implode(' ', $names);
    }
955228
public function mapFields(Content $content, $languageCode)
    {
        $fieldsGrouped = [[]];
        $contentType = $this->contentTypeHandler->load(
            $content->versionInfo->contentInfo->contentTypeId
        );

        foreach ($content->fields as $field) {
            if ($field->languageCode !== $languageCode) {
                continue;
            }

            $fieldsGrouped[] = $this->mapField($contentType, $field);
        }

        return array_merge(...$fieldsGrouped);
    }
72590
public function getKeys(
        array $domains = [],
        array $languages = []
    ) : array {
        return array_reduce(
            $this->getTranslations(
                $domains,
                $languages
            ),
            function (array $keys, Translation $translation) {
                $keys[] = $translation->getKey();

                return $keys;
            },
            []
        );
    }
852189
protected function extractImportsFromFields(array $fields)
    {
        $imports = [];

        foreach ($fields as $field) {
            $options = $field->getLanguage(static::LANGUAGE);
            $imports = array_merge($imports, explode(PHP_EOL, $options->get('imports')));

            if ($field->getFormat()) {
                $imports[] = "import Format from '@gdbots/pbj/enums/Format';";
            }

            switch ($field->getType()->getTypeName()->getValue()) {
                case TypeName::INT_ENUM;
                case TypeName::STRING_ENUM;
                    $enum = $field->getEnum();
                    $imports[] = sprintf(
                        "import %s from '%s/%s';",
                        $this->enumToClassName($enum),
                        $this->enumToNativeNamespace($enum),
                        $this->enumToClassName($enum)
                    );
                    break;

                default:
                    break;
            }
        }

        return $imports;
    }
259872
private static function getFieldTypeArray($fields)
    {
        if (count($fields) === 0) {
            return;
        }

        $types = array();

        foreach ($fields as &$field) {
            $types[] = $field->type;
        }

        return $types;
    }
795480
public static function getDisplayLanguages($languages, $languageRedirects)
    {
        foreach ($languages as $key => $value) {
            $key = (isset($languageRedirects[$key])) ? $languageRedirects[$key] : $key;
            $redirects[$key] = $value;
        }
        return $redirects;
    }
941320
public function updateFieldsTo(?string $initialLanguageCode, array $fields): self
    {
        $languageCodes = array_map(
            function (Field $field) {
                return $field->languageCode;
            },
            $fields
        );

        $this->targetVersionProperties['forUpdateInitialLanguageCode'] = $initialLanguageCode;
        $this->targetVersionProperties['forUpdateLanguageCodesList'] = array_values(
            array_unique($languageCodes)
        );

        return $this;
    }
981217
public function getServerBundle($langCode)
    {
        $cache = $this->getServiceLocator()->get(common_cache_Cache::SERVICE_ID);
        try {
            $translations = $cache->get(self::TRANSLATION_PREFIX.$langCode);
        } catch (common_cache_NotFoundException $ex) {
            $translations = $this->buildServerBundle($langCode);
        }
        return $translations;
    }