Skip to main content

API Reference

Quick reference for all public APIs.

DataView

Constructor

$view = new DataView(array $config);

Methods

MethodReturnsDescription
register()staticRegisters admin menu and hooks
get_handler()PluralHandler|SingularHandlerRequest handler
get_object()PluralObject|SingularObjectData object
get_dataset()DataSetDataset instance
get_config()DataViewConfigConfiguration
get_field_registry()FieldTypeRegistryField registry
url(string $action, ?int $id)stringAdmin URL
set_layout(callable $callback)staticCustom layout
set_renderer(Renderer $renderer)staticCustom renderer
handle_request()voidHandle current request

DataViewConfig

Properties (readonly)

PropertyTypeDescription
$slugstringUnique identifier
$labelstringSingular label
$labelsarrayFull labels array
$fieldsarrayField definitions
$field_configsarrayFull field configs
$storagestringStorage type
$modestringplural/singular
$capabilitystringRequired capability
$storage_optionsarrayStorage options
$uiarrayUI configuration

Methods

MethodReturnsDescription
is_plural()boolIs plural mode
is_singular()boolIs singular mode
get_menu_page()stringMenu slug
get_menu_label()stringMenu label
get_parent_menu()?stringParent menu
get_icon()stringMenu icon
get_position()?intMenu position
get_singular_label()stringSingular label
get_plural_label()?stringPlural label
get_label(string $key, ?string $fallback)?stringSpecific label
get_field_config(string $name)?arrayField config

PluralHandler

CRUD Methods

$result = $handler->create(array $data);
$result = $handler->read(int $id);
$result = $handler->update(int $id, array $data);
$result = $handler->delete(int $id);
$result = $handler->list();

Validation

$handler->add_validator(string $field, callable $validator);

Lifecycle Hooks

$handler->before_create(callable $callback);
$handler->after_create(callable $callback);
$handler->before_update(callable $callback);
$handler->after_update(callable $callback);
$handler->before_delete(callable $callback);
$handler->after_delete(callable $callback);

SingularHandler

Methods

$result = $handler->read();
$result = $handler->update(array $data);
$handler->add_validator(string $field, callable $validator);
$handler->before_update(callable $callback);
$handler->after_update(callable $callback);

Validators

use Tangible\RequestHandler\Validators;

Validators::required();
Validators::email();
Validators::min_length(int $length);
Validators::max_length(int $length);
Validators::min(int $value);
Validators::max(int $value);
Validators::in(array $values);

Result Object

$result->is_success();
$result->is_error();
$result->get_entity(); // PluralHandler
$result->get_entities(); // PluralHandler::list()
$result->get_data(); // SingularHandler
$result->get_errors();

ValidationError

use Tangible\RequestHandler\ValidationError;

$error = new ValidationError(string $message, ?string $field = null);
$error->get_message();
$error->get_field();

Layout Classes

Layout

$layout = new Layout(DataSet $dataset);
$layout->section(string $label, callable $callback);
$layout->tabs(callable $callback);
$layout->sidebar(callable $callback);
$layout->get_structure();
$layout->get_dataset();

Section

$section->field(string $name);
$section->section(string $label, callable $callback);
$section->tabs(callable $callback);
$section->columns(int $count);
$section->condition(string $field, mixed $value);

Field (in Section)

$section->field('name')
->placeholder(string $text)
->help(string $text)
->readonly()
->width(string $width);

Tabs

$tabs->tab(string $label, callable $callback);

Tab

$tab->field(string $name);
$tab->section(string $label, callable $callback);
$tab->tabs(callable $callback);
$sidebar->field(string $name);
$sidebar->actions(array $actions);

FieldTypeRegistry

$registry->has_type(string $type);
$registry->get_dataset_type(string $type);
$registry->get_sanitizer(string $type);
$registry->get_schema(string $type);
$registry->get_input_type(string $type);
$registry->register_type(string $name, array $config);

Renderer Interface

interface Renderer {
public function render_editor(Layout $layout, array $data = []): string;
public function render_list(DataSet $dataset, array $entities): string;
}

UrlBuilder

$builder = new UrlBuilder(DataViewConfig $config);
$builder->url(string $action, ?int $id, array $extra);
$builder->url_with_nonce(string $action, ?int $id, string $nonce_action);
$builder->get_current_action();
$builder->get_current_id();
$builder->get_nonce_action(string $action, ?int $id);