Skip to content

Commit

Permalink
Updates fpr PR #3 to handle backwards compatibility and the PropertyV…
Browse files Browse the repository at this point in the history
…alueConverter
  • Loading branch information
dinc5150 committed Jun 24, 2021
1 parent 2e91dca commit 6a52c13
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ angular.module("umbraco")

$scope.updateShareImage = function () {
$scope.model.value.shareImage = null;


//check if there is one already set.
if ($scope.model.value.share.imageUrl != null) {
Expand Down Expand Up @@ -232,26 +232,27 @@ angular.module("umbraco")
if (typeof properties[p].value !== "undefined" && properties[p].value !== "" && properties[p].value !== null) {
//Found a fallback property value
console.log("fallback", properties[p])
$scope.model.value.shareImage = properties[p];
$scope.model.value.shareImage = properties[p].value;


if ($scope.model.value.shareImage.view == "mediapicker" && $scope.model.value.shareImage.value != null && $scope.model.value.shareImage.value.startsWith("umb://")) {
if (properties[p].view == "mediapicker" && $scope.model.value.shareImage != null && $scope.model.value.shareImage.startsWith("umb://")) {
//The fallback is a media picker
entityResource.getById($scope.model.value.shareImage.value, "Media")
entityResource.getById($scope.model.value.shareImage, "Media")
.then(function (mediaEntity) {
$scope.model.value.shareImageUrl = mediaEntity.metaData.MediaPath;
});
} else if ($scope.model.value.shareImage.view == "mediapicker3" && $scope.model.value.shareImage.value.length > 0) {
} else if (properties[p].view == "mediapicker3" && Array.isArray(properties[p].value) && properties[p].value.length > 0) {
//The fallback is a media picker
console.log(properties[p].value)
$scope.model.value.shareImage = properties[p].value[0].mediaKey
entityResource.getById($scope.model.value.shareImage, "Media")
.then(function (mediaEntity) {
console.log(mediaEntity);
$scope.model.value.shareImageUrl = mediaEntity.metaData.MediaPath;
});
} else if ($scope.model.value.shareImage.value.startsWith("/")) {
} else if (!Array.isArray(properties[p].value) && $scope.model.value.shareImage.startsWith("/")) {
//Probably an upload field. Could be another random property too, so be careful
$scope.model.value.shareImageUrl = $scope.model.value.shareImage.value;
$scope.model.value.shareImageUrl = $scope.model.value.shareImage;
} else {
//Not a property with a valid source image
$scope.model.value.shareImageUrl = null;
Expand Down

0 comments on commit 6a52c13

Please sign in to comment.