Handle a Image Asset attribute

@param ImageAssetValue $value
@param string     $fieldDefinitionIdentifier
@param string     $languageCode

@return string
774496
protected function handleImageAssetValue(ImageAssetValue $value, $fieldDefinitionIdentifier, $languageCode)
    {
        if (!$value->destinationContentId) {
            return '';
        }

        $content = $this->repository->getContentService()->loadContent($value->destinationContentId);

        foreach ($content->getFields() as $field) {
            if ($field->value instanceof ImageValue) {
                return $this->handleImageValue($field->value, $fieldDefinitionIdentifier, $languageCode);
            }
        }

        return  '';
    }
1186115
public function getFieldDefinition($fieldDefinitionIdentifier)
    {
        $fieldDefinitions = $this->getFieldDefinitions();
        foreach ($fieldDefinitions as $fieldDefinition) {
            if ($fieldDefinition->identifier === $fieldDefinitionIdentifier) {
                return $fieldDefinition;
            }
        }

        return null;
    }
197466
public function getOne($languageCode, $locale = 'en')
	{

		$result = $this->has($languageCode, $locale);

		if (!$result)
		{
			throw new LanguageNotFoundException($languageCode);
		}

		return $result;
	}
510390
public function getFirstValueByAttributeCodeAsString(string $code, $asTitle = true)
    {
        $attributeValue = $this->getFirstValueByAttributeCode($code);

        if (!$attributeValue) {
            return "";
        }

        $field = $asTitle ? 'title' : 'value';

        return $attributeValue->$field;
    }
541845
public function deleteTranslatedFields($languageCode, $contentId, $versionNo = null)
    {
        $query = $this->connection->createQueryBuilder();
        $query
            ->delete('ezcontentobject_attribute')
            ->where('contentobject_id = :contentId')
            ->andWhere('language_code = :languageCode')
            ->setParameters(
                [
                    ':contentId' => $contentId,
                    ':languageCode' => $languageCode,
                ]
            )
        ;

        if (null !== $versionNo) {
            $query
                ->andWhere('version = :versionNo')
                ->setParameter(':versionNo', $versionNo)
            ;
        }

        $query->execute();
    }
692067
public function getIndexData(Field $field, FieldDefinition $fieldDefinition)
    {
        $tagKeywords = [];
        $parentTagIds = [];
        $tagIds = [];

        if (!empty($field->value->externalData)) {
            foreach ($field->value->externalData as $tag) {
                if (isset($tag['keywords'][$field->languageCode])) {
                    $tagKeywords[] = $tag['keywords'][$field->languageCode];
                    $parentTagIds[] = $tag['parent_id'];
                    $tagIds[] = $tag['id'];
                } elseif (isset($tag['keywords'][$tag['main_language_code']])) {
                    $tagKeywords[] = $tag['keywords'][$tag['main_language_code']];
                    $parentTagIds[] = $tag['parent_id'];
                    $tagIds[] = $tag['id'];
                } else {
                    // Something went wrong with the tag, we will not index it
                    continue;
                }
            }
        }

        return [
            new Search\Field(
                'tag_keywords',
                $tagKeywords,
                new Search\FieldType\MultipleStringField()
            ),
            new Search\Field(
                'parent_tag_ids',
                $parentTagIds,
                new Search\FieldType\MultipleIntegerField()
            ),
            new Search\Field(
                'tag_ids',
                $tagIds,
                new Search\FieldType\MultipleIntegerField()
            ),
            new Search\Field(
                'tag_text',
                implode(' ', $tagKeywords),
                new Search\FieldType\TextField()
            ),
            new Search\Field(
                'fulltext',
                implode(' ', $tagKeywords),
                new Search\FieldType\FullTextField()
            ),
        ];
    }
979617
public Attribute getLabelAttribute(String langCode) {
    Attribute labelAttr = getLabelAttribute();
    Attribute i18nLabelAttr =
        labelAttr != null ? getAttribute(labelAttr.getName() + '-' + langCode) : null;
    return i18nLabelAttr != null ? i18nLabelAttr : labelAttr;
  }
993308
function guid( $contentObject, $languageCode = '' )
    {
        if ( !$contentObject instanceof eZContentObject )
            return md5( self::installationID() . '-' . $contentObject . '-' . $languageCode );

        return md5( self::installationID() . '-' . $contentObject->attribute( 'id' ) . '-' . $languageCode );
    }
466669
public function render(FieldValueInterface $fieldValue)
    {
        $value = $fieldValue->getValue();
        $value = unserialize($value);

        if (empty($value['src'])) {
            return '';
        }

        $fileName = $this->uploadManager->getTargetDir() . DIRECTORY_SEPARATOR . $value['src'];
        if (!file_exists($fileName)) {
            return '';
        }

        $fileName = $this->assetPackages->getUrl($this->uploadManager->getWebPath() . '/' . $value['src']);

        return '<img src="' . $fileName . '" alt="' . $value['alt'] . '"/>';
    }
732264
public static function init(common_ext_Extension $extension, $langCode)
    {
    	// if the langCode is empty do nothing
    	if (empty($langCode)){
    		throw new Exception("Language is not defined");
    	}
    	
		//init the ClearFw l10n tools
        $translations = tao_models_classes_LanguageService::singleton()->getServerBundle($langCode);
        l10n::init($translations);

        $serviceManager = \oat\oatbox\service\ServiceManager::getServiceManager();
        $extraPoService = $serviceManager->get(\oat\tao\model\i18n\ExtraPoService::SERVICE_ID);
        $extraPoCount = $extraPoService->requirePos();
    }
511349
public function deleteTranslationFromVersionFields(VersionInfo $versionInfo, $languageCode)
    {
        $fieldTypeIdsMap = $this->contentGateway->getFieldIdsByType(
            $versionInfo->contentInfo->id,
            $versionInfo->versionNo,
            $languageCode
        );
        foreach ($fieldTypeIdsMap as $fieldType => $ids) {
            $this->storageHandler->deleteFieldData($fieldType, $versionInfo, $ids);
        }
        $this->contentGateway->deleteTranslatedFields(
            $languageCode,
            $versionInfo->contentInfo->id,
            $versionInfo->versionNo
        );
    }
273710
public function deleteTranslationFromContent($contentId, $languageCode)
    {
        $language = $this->languageHandler->loadByLanguageCode($languageCode);

        $this->connection->beginTransaction();
        try {
            $this->deleteTranslationFromContentVersions($contentId, $language->id);
            $this->deleteTranslationFromContentNames($contentId, $languageCode);
            $this->deleteTranslationFromContentObject($contentId, $language->id);

            $this->connection->commit();
        } catch (DBALException $e) {
            $this->connection->rollBack();
            throw $e;
        }
    }
709115
private function handleCustomFileTree(&$fieldDefinition)
    {
        if ($this->get('file_uploadFolder')) {
            // Set root path of file chooser depending on contao version.
            $file = null;

            if ($this->validator->isStringUuid($this->get('file_uploadFolder'))
                || $this->validator->isBinaryUuid($this->get('file_uploadFolder'))
            ) {
                $file = $this->fileRepository->findByUuid($this->get('file_uploadFolder'));
            }

            // Check if we have a file.
            if (null !== $file) {
                $fieldDefinition['eval']['path'] = $file->path;
            } else {
                // Fallback.
                $fieldDefinition['eval']['path'] = $this->get('file_uploadFolder');
            }
        }

        if ($this->get('file_validFileTypes')) {
            $fieldDefinition['eval']['extensions'] = $this->get('file_validFileTypes');
        }

        if ($this->get('file_filesOnly')) {
            $fieldDefinition['eval']['filesOnly'] = true;
        }
    }
1038287
public function validateImageAspect($attribute, $value, $parameters)
    {
        $image = $this->getImagePath($value);

        // Get the image dimension info, or fail.

        $image_size = @getimagesize($image);
        if ($image_size === false) {
            return false;
        }

        $image_width = $image_size[0];
        $image_height = $image_size[1];

        // Parse the parameter(s).  Options are:
        //
        // 	"0.75"   - one param: a decimal ratio (width/height)
        // 	"3,4"    - two params: width, height
        //
        // If the first value is prefixed with "~", the orientation doesn't matter, i.e.:
        //
        // 	"~3,4"   - would accept either "3:4" or "4:3" images

        $both_orientations = false;

        if (substr($parameters[0], 0, 1) === '~') {
            $parameters[0] = substr($parameters[0], 1);
            $both_orientations = true;
        }

        if (count($parameters) === 1) {
            $aspect_width = $parameters[0];
            $aspect_height = 1;
        } else {
            $aspect_width = (int) $parameters[0];
            $aspect_height = (int) $parameters[1];
        }

        if ($aspect_width === 0 || $aspect_height === 0) {
            throw new RuntimeException('Aspect is zero or infinite: ' . $parameters[0]);
        }

        $check = ($image_width * $aspect_height) / $aspect_width;

        if ((int) round($check) === $image_height) {
            return true;
        }

        if ($both_orientations) {
            $check = ($image_width * $aspect_width) / $aspect_height;
            if ((int) round($check) === $image_height) {
                return true;
            }
        }

        return false;
    }
251704
function storeIdentifierValue( $contentClassAttribute, $contentObjectAttribute, $identifierValue )
    {
        $value = eZIdentifierType::generateIdentifierString( $contentClassAttribute, $identifierValue );
        $contentObjectAttribute->setAttribute( 'data_text', $value );
        $contentObjectAttribute->setAttribute( 'data_int', $identifierValue );
        return true;
    }
651456
private static function convertValueBasedOnAttributeName($value, $attrName)
    {
        switch ($attrName) {
            case Profile::ATTR_DOCUMENT_DETAILS:
                return new DocumentDetails($value);

            case Profile::ATTR_DOCUMENT_IMAGES:
                if (!($value instanceof MultiValue)) {
                    throw new AttributeException('Document Images could not be decoded');
                }
                return $value
                  ->allowInstance(Image::class)
                  ->immutable();

            default:
                return $value;
        }
    }
1059384
public function buildFieldCreateForm(
        FormBuilderInterface $formBuilder,
        FieldDefinition $fieldDefinition,
        $languageCode
    ) {
        $this->buildFieldForm($formBuilder, $fieldDefinition, $languageCode);
    }