---
title: UI Builders
---

# UI Builders

<div class="documentation__toc"></div>

## Introduction

UI builders help you easily define complex UI structures from basic array configuration called `definitions` for each `component` of the UI object.

The `builder` classes are responsible for taking your input and _building_ a corresponding UI class and all it's components.

For example a [form](../ui/forms) might have a field definition like this:

```php
protected $fields = [
    'name' => [
        'type' => 'anomaly.field_type.text',
        'label' => 'What is your name?',
    ],
];
```

Assuming the above is defined in our builder, we can `build` and then access the resulting component object and use it.

```php
$builder->build();

$builder->getFormField('name')->getInput();
// Outputs the field's input HTML
```

This is great because we didn't have to do much work to set this up. We can do even less if we leverage stream data (instead of defining the fields manually).

## Builders

The builder classes are where your definitions go. You work with builders _before_ the build process to configure the resulting UI objects.

During the build process the input from the builder is read, processed, and transferred to the builder's UI object. That's why the above example reaches into it's form for the finished object with `getFormField`.

### Models

Most builders use a `model`. In most cases builders use a `streams` model but they can be used with non-stream models as well as no model at all (self handling forms for example or tables of API data).

### Components

Components comprise the primary structure of the builders.

Form builders for example have the following components:

- Fields
- Sections
- Actions
- Buttons
- Options

### Definitions

Definitions are the basic array based configuration for components. Definition inputs are designed to require minimal input and maximum automation but can be defined in more detail to override anything.

### Handlers

The `build` process often leverages [evaluation](../utilities/evaluator) and [resolving](../utilities/resolver) for all components. It's important to understand these concepts along with basic [hydration](../utilities/hydrator) going forward as this documentation will assume you are familiar with the concepts.

Handlers let you wrap the setting of component definitions into classes.

```php
<?php namespace Anomaly\InstallerModule\Installer\Form;

class InstallerFormFields
{

    public function handle(InstallerFormBuilder $builder)
    {
        $builder->setFields(...);
    }
}
```
