Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • supertrip 4 posts 75 karma points
    May 17, 2022 @ 13:58
    supertrip
    0

    How to use PropertyValueConverterBase asynchronously?

    Hi, I am developing an Umbraco 9 package.

    I learnt how to use the PropertyValueConverterBase object, and how to intercept data called from the database in the following way:

    ```

    public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
    {
            var configuration = propertyType.DataType.ConfigurationAs<MappeConfigurationModel>();
    
            var model = string.IsNullOrWhiteSpace(inter?.ToString()) ? configuration.Tipologia : _jsonSerializer.Deserialize<MappeModel>(inter.ToString());
    
            model.Configuration = configuration;
            return model;
    }
    

    ```

    As you can see, with the method above I have the chance to intercept the data fetched from the database and manipulate it before it gets returned to the property editor as a value (and then displayed on the front-end).

    However, I am in need now to make a http request call to an API controller to fetch some additional data...

    How I achieve such result? The IPropertyValueConverter interface from which I inherit my object does not have an async version of ConvertIntermediateToObject...

    For example, the code below is not accepted:

    ```

    public async override Task<object> ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
    {
            var client = _httpClientFactory.CreateClient();
    
            var response = await client.GetAsync(baseUri + "umbraco/plugin/people/getpeople");
    
            var configuration = propertyType.DataType.ConfigurationAs<MappeConfigurationModel>();
    
            var model = string.IsNullOrWhiteSpace(inter?.ToString()) ? configuration.Tipologia : _jsonSerializer.Deserialize<MappeModel>(inter.ToString());
    
            model.Configuration = configuration;
            return model;
    }
    

    ```

    In other words, does anyone know how to wait for the response of a HTTP call before passing the value to a propertyEditor in Umbraco?

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies