Skip to content

Instantly share code, notes, and snippets.

View AndyButland's full-sized avatar

Andy Butland AndyButland

View GitHub Profile
var commands = new List<ImageUrlGenerationOptions>();
imageUrlGeneratorMock.Verify(x => x.GetImageUrl(Capture.In(commands, cmd => true)));
foreach (ImageUrlGenerationOptions command in commands)
{
System.Diagnostics.Debug.WriteLine(command.Height);
}
imageUrlGeneratorMock
.Setup(x => x.GetImageUrl(It.IsAny<ImageUrlGenerationOptions>()))
.Returns("/test.png");
imageUrlGeneratorMock
.Setup(x => x.GetImageUrl(It.Is<ImageUrlGenerationOptions>(y => y.Height == Height)))
.Returns("/test.png");
@AndyButland
AndyButland / AjaxFormPage.cshtml
Last active December 13, 2023 09:26
Umbraco Forms API usage with vanilla JavaScript
@*
Demonstration of using the Umbraco Forms API for retrieving the definition of a form, rendering it and posting an entry.
It's based off an Umbraco content item with a property with alias "Form", of type "Form Picker".
*@
@using Microsoft.AspNetCore.Antiforgery
@using Microsoft.Extensions.Options;
@using Umbraco.Cms.Web.Common.PublishedModels;
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<ContentModels.AJaxformPage>
@using ContentModels = Umbraco.Cms.Web.Common.PublishedModels;
{
"name": "Contact Us",
"route": {
"path": "/contact-us/",
"startItem": {
"id": "ca4249ed-2b23-4337-b522-63cabe5587d1",
"path": "home"
}
},
"id": "4a1f4198-e143-48ba-a0f5-1a7ef2df23aa",
public async Task Get(string id)
{
var response = await_authorizedServiceCaller.GetRequestAsyncContactResponse>(
"hubspot",
$"/crm/v3/objects/contacts/{id}");
if (response == null)
{
return NotFound();
}
[ApiExplorerSettings(GroupName = "forms")]
builder.Services.ConfigureOptions<ConfigureUmbracoFormsApiSwaggerGenOptions>();
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
namespace Umbraco.Forms.Web.Configuration
{
public class ConfigureUmbracoFormsApiSwaggerGenOptions : IConfigureOptions<SwaggerGenOptions>
{
public void Configure(SwaggerGenOptions options)
private void PopulateGotoPageOnSubmit(Form form, FormDto dto)
{
if (form.GoToPageOnSubmit == 0)
{
return;
}
Attempt<Guid> gotToPageKeyAttempt = _entityService.GetKey(form.GoToPageOnSubmit, UmbracoObjectTypes.Document);
if (gotToPageKeyAttempt.Success == false)
{