A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.umbraco.com/umbraco-ui-builder/how-to-guides/creating-your-first-integration below:

Creating your First Integration | Umbraco UI Builder

Creating your First Integration | Umbraco UI Builder
  1. How-to Guides
Creating your First Integration

Creating your first integration with Umbraco UI Builder.

This guide walks you through a basic implementation of Umbraco UI Builder to manage a custom database table.

By default, Umbraco UI Builder uses a database for data storage. However, you can configure this using a custom Repository class instead.

Umbraco UI Builder uses PetaPoco as its default persistence layer.

In this section, you will create a Person table to store data.

To create a Person table, run the following script in SQL Server Management Studio (SSMS).

CREATE TABLE [Person] (
    [Id] int IDENTITY (1,1) NOT NULL,
    [Name] nvarchar(255) NOT NULL,
    [JobTitle] nvarchar(255) NOT NULL,
    [Email] nvarchar(255) NOT NULL,
    [Telephone] nvarchar(255) NOT NULL,
    [Age] int NOT NULL,
    [Avatar] nvarchar(255) NOT NULL
);

This script creates a table for storing people’s details. You may want to populate it with some dummy data for testing.

With the database table created, define the Person model in your project.

To create a Model:

  1. Create a new folder called Models in your project.

  2. Add a new class file called Person.cs.

using NPoco;
using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;

[TableName("Person")]
[PrimaryKey("Id")]
public class Person
{
    [PrimaryKeyColumn]
    public int Id { get; set; }
    public string? Name { get; set; }
    public string? JobTitle { get; set; }
    public string? Email { get; set; }
    public string? Telephone { get; set; }
    public int Age { get; set; }
    public string? Avatar { get; set; }
}
Configure Umbraco UI Builder

With the database and model set up, it is time to configure Umbraco UI Builder to work with the Person model. This will allow you to manage Person entities from the Umbraco backoffice.

You can configure Umbraco UI Builder either through a Composer or by using the AddUIBuilder extension method in Program.cs.

The following steps cover the Program.cs approach. For more details, including configuring via a Composer, see the the Configuration article.

Configuring via Program.cs
  1. Open the Program.cs file in your project.

  2. Locate the CreateUmbracoBuilder() method.

  3. Add AddUIBuilder before AddComposers().

builder.CreateUmbracoBuilder()
    .AddBackOffice()
    .AddWebsite()
    .AddDeliveryApi()
    .AddComposers()
    .AddUIBuilder(cfg => {
        // Apply your configuration here
    })
    .Build();

Here’s an example configuration defining a section, a list view, and an editor for managing Person entities:

...
.AddUIBuilder(cfg => {

    cfg.AddSectionAfter("media", "Repositories", sectionConfig => sectionConfig
        .Tree(treeConfig => treeConfig
            .AddCollection<Person>(x => x.Id, "Person", "People", "A person entity", "icon-umb-users", "icon-umb-users", collectionConfig => collectionConfig
                .SetNameProperty(p => p.Name)
                .ListView(listViewConfig => listViewConfig
                    .AddField(p => p.JobTitle).SetHeading("Job Title")
                    .AddField(p => p.Email)
                )
                .Editor(editorConfig => editorConfig
                    .AddTab("General", tabConfig => tabConfig
                        .AddFieldset("General", fieldsetConfig => fieldsetConfig
                            .AddField(p => p.JobTitle).MakeRequired()
                            .AddField(p => p.Age)
                            .AddField(p => p.Email).SetValidationRegex("[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+")
                            .AddField(p => p.Telephone).SetDescription("inc area code")
                        )
                        .AddFieldset("Media", fieldsetConfig => fieldsetConfig
                            .AddField(p => p.Avatar).SetDataType("Upload File")
                        )
                    )
                )
            )
        )
    );

})
...
Accessing the Umbraco Backoffice

After defining the configuration, compile and run your project. To access the newly defined section, you need to give permission to the backoffice user account:

  1. Login to the Umbraco backoffice.

  2. Navigate to the user group you wish to assign the newly defined section.

User group permissions
  1. Refresh the browser to view the new section.

Newly defined section

If you click on a person's name, you will see the following screen:

People editor

This setup allows you to extend and customize your Umbraco site by managing data and entities directly in the backoffice. The simplicity of the implementation allows to create dynamic, user-friendly interfaces for your own data models.

Last updated 4 months ago


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4