class Block (View source)

(3.x): This is not really a service, and we should move this to another location.

Constants

SOURCE_APP

SOURCE_TWILL

SOURCE_CUSTOM

TYPE_BLOCK

TYPE_REPEATER

PREG_REPLACE_INNER

Properties

string $title
string $titleField
bool $hideTitlePrefix
string $trigger
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

Methods

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

Make a block instance out of arguments.

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
getForComponent(string $type, bool $repeater = false)

No description

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

Block constructor.

$this
setSource($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($name)

No description

$this
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
render()

No description

static string
removeSpecialBladeTags($contents)

No description

getBlockView($blockViewMappings = [])

No description

Details

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

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 getForComponent(string $type, bool $repeater = false)

No description

Parameters

string $type
bool $repeater

Return Value

Block

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

Block constructor.

Parameters

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

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

Exceptions

Exception

$this setSource($source)

No description

Parameters

$source

Return Value

$this

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($name)

No description

Parameters

$name

Return Value

string

$this parse()

No description

Return Value

$this

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 render()

No description

Return Value

string

Exceptions

Throwable

static string removeSpecialBladeTags($contents)

No description

Parameters

$contents

Return Value

string

getBlockView($blockViewMappings = [])

No description

Parameters

$blockViewMappings