class Block (View source)

Constants

SOURCE_APP

SOURCE_TWILL

SOURCE_CUSTOM

SOURCE_VENDOR

TYPE_BLOCK

TYPE_SETTINGS

TYPE_REPEATER

PREG_REPLACE_INNER

Properties

string $title
string $titleField
bool $hideTitlePrefix
string $trigger
string|null $selectTrigger

For repeaters only: The select existing button text.

string $source
string $name
string $group
string $type
string $icon
bool $compiled
string $component
int $max
bool $isNewFormat
SplFileInfo $file
string $fileName
string $renderNamespace
string $contents
array $rules
array $rulesForTranslatedFields
RenderData|null $renderData Renderedata.
TwillBlockComponent $componentClass
InlineRepeater|null $inlineRepeater

Methods

static Block
forComponent(string $componentClass)

No description

static Block
make($file, $type, $source, $name = null, string $renderNamespace = null)

Make a block instance out of arguments.

newInstance()

No description

static Block|null
findFirstWithType(string $type)

Gets the first match being a block or repeater.

static Block
getForType(string $type, bool $repeater = false)

No description

static Block|null
getForComponent(string $type, bool $repeater = false)

No description

__construct(SplFileInfo|null $file, string|null $type, $source, $name = null, string|null $renderNamespace = null, string|null $componentClass = null, InlineRepeater|null $inlineRepeater = null)

Block constructor.

setSource(string $source)

No description

array
getData(array $data, Block $block)

No description

array
getFormData()

Gets the form data. This is only called once and not per create.

Collection
toList()

No description

Collection
toShortList()

No description

string
makeName(string $name)

No description

parse()

No description

array
getRules()

Checks both the blade file or helper class for validation rules. Returns in order the first one with data.

array
getRulesForTranslatedFields()

Checks both the blade file or helper class for validation rules. Returns in order the first one with data.

string
parseProperty(string $property, string $block, string $blockName, string|null $default = null)

Parse a string property directive in the form of @twillTypeProperty('value').

void
parseArrayProperty(string $property, string $block, string $blockName, callable $callback)

Parse an array property directive in the form of @twillTypeProperty([...]) and pass the result to a given callback.

mixed
parseMixedProperty(string $property, string $block, string $blockName, callable $callback)

Parse a mixed property directive in the form of @twillTypeProperty('value', [...]) and pass the result to a given callback.

bool
isNewFormat($block)

No description

string
getFileName()

No description

string
renderForm()

No description

getBlockView($blockViewMappings = [])

No description

void
setRenderData(RenderData $renderData)

No description

Block|null
block()

No description

string
renderView(array $blockViewMappings, array $data, bool $inEditor = false)

No description

Details

static Block forComponent(string $componentClass)

No description

Parameters

string $componentClass

Return Value

Block

static Block make($file, $type, $source, $name = null, string $renderNamespace = null)

Make a block instance out of arguments.

Parameters

$file
$type
$source
$name
string $renderNamespace

Mainly for packages, but this will get the preview/render view file from that namespace.

Return Value

Block

Block newInstance()

No description

Return Value

Block

static Block|null findFirstWithType(string $type)

Gets the first match being a block or repeater.

Parameters

string $type

Return Value

Block|null

static Block getForType(string $type, bool $repeater = false)

No description

Parameters

string $type
bool $repeater

Return Value

Block

static Block|null getForComponent(string $type, bool $repeater = false)

No description

Parameters

string $type
bool $repeater

Return Value

Block|null

final __construct(SplFileInfo|null $file, string|null $type, $source, $name = null, string|null $renderNamespace = null, string|null $componentClass = null, InlineRepeater|null $inlineRepeater = null)

Block constructor.

Parameters

SplFileInfo|null $file
string|null $type
$source
$name
string|null $renderNamespace

Mainly for packages, but this will get the preview/render view file from that namespace.

string|null $componentClass
InlineRepeater|null $inlineRepeater

used when registering dynamic repeaters.

Exceptions

Exception

Block setSource(string $source)

No description

Parameters

string $source

Return Value

Block

array getData(array $data, Block $block)

No description

Parameters

array $data
Block $block

Return Value

array

array getFormData()

Gets the form data. This is only called once and not per create.

This function is not aware of the context. If you need to know the current module you have to figure that out yourself by for example parsing the route.

Return Value

array

Collection toList()

No description

Return Value

Collection

Collection toShortList()

No description

Return Value

Collection

string makeName(string $name)

No description

Parameters

string $name

Return Value

string

Block parse()

No description

Return Value

Block

Exceptions

Exception

array getRules()

Checks both the blade file or helper class for validation rules. Returns in order the first one with data.

Return Value

array

array getRulesForTranslatedFields()

Checks both the blade file or helper class for validation rules. Returns in order the first one with data.

Return Value

array

string parseProperty(string $property, string $block, string $blockName, string|null $default = null)

Parse a string property directive in the form of @twillTypeProperty('value').

Parameters

string $property
string $block
string $blockName
string|null $default

Return Value

string

Exceptions

Exception

void parseArrayProperty(string $property, string $block, string $blockName, callable $callback)

Parse an array property directive in the form of @twillTypeProperty([...]) and pass the result to a given callback.

Parameters

string $property
string $block
string $blockName
callable $callback

Should have the following signature: function (array $value)

Return Value

void

Exceptions

Exception

mixed parseMixedProperty(string $property, string $block, string $blockName, callable $callback)

Parse a mixed property directive in the form of @twillTypeProperty('value', [...]) and pass the result to a given callback.

Parameters

string $property
string $block
string $blockName
callable $callback

Should have the following signature: function ($value, $options)

Return Value

mixed

Exceptions

Exception

bool isNewFormat($block)

No description

Parameters

$block

Return Value

bool

string getFileName()

No description

Return Value

string

string renderForm()

No description

Return Value

string

Exceptions

Throwable

getBlockView($blockViewMappings = [])

No description

Parameters

$blockViewMappings

void setRenderData(RenderData $renderData)

No description

Parameters

RenderData $renderData

Return Value

void

Block|null block()

No description

Return Value

Block|null

string renderView(array $blockViewMappings, array $data, bool $inEditor = false)

No description

Parameters

array $blockViewMappings
array $data
bool $inEditor

Return Value

string