PHP Класс fewbricks\bricks\brick

Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$args A place to store arbitrary arguments.
$data Data for the brick
$get_html_args Extra settings that is passed to get_html() / get_brick_html()
$is_layout True if the brick is a layout for flexible content
$is_option True if the brick belongs to an ACF options page.
$is_sub_brick True if the brick is sub brick of another brick.
$is_sub_field True if the brick is a sub field for a repeater
$settings Extra settings to allow for greater flexibility for the arguments.

Открытые методы

Метод Описание
__construct ( string $name, string $key = '' )
add_brick_layout ( string $brick_layout ) Add a single layout to the brick. String with the name of the layout (without .php).
add_css_class ( $class_name ) Old code that could cause trouble if removed now since people may be using it.
add_fields ( $fields_to_add )
get_arg ( string $name, boolean $default = false ) : mixed Get an argument.
get_brick_layouted_html ( $html ) : string
get_brick_layouts ( ) : array Returns the brick layouts set for the brick. These are the values previously passed to set_brick_layouts and/or add_brick_layout.
get_data ( ) : array | boolean
get_data_group ( $group_name, boolean $default_value = false, boolean $prepend_this_name = true ) : boolean | mixed Use this to get an entire group of data.
get_data_item ( $item_name, boolean $prepend_this_name = true, boolean $group_name = false, boolean $default_value = false ) : boolean | mixed Get the value of a data item
get_html ( array $args = [], mixed $brick_layouts = false ) : string
get_inline_css ( boolean $group_name = false ) : boolean | mixed | string
get_is_layout ( ) : boolean
get_is_option ( ) : boolean
get_is_sub_field ( ) : boolean
get_key ( ) : string
get_name ( ) : string
get_post_id_to_get_field_from ( ) : boolean
get_setting ( string $name, string $default_value = '' ) : string This function makes sure that we have means to get essential settings in the same way as for fields etc.
get_settings ( fewbricks\acf\field-group | layout | repeater | flexible_content | brick $object_to_get_for ) : array Get settings of a field.
has_brick_layout ( $brick_layout_name ) : boolean Checks if the brick has a layout with the name that you pass to the function. Returns true if it does, false if not.
set_arg ( $name, $value ) Set an argument.
set_brick_layouts ( string | array $brick_layouts ) Set brick layouts.
set_data ( array $data ) : brick
set_data_item ( $item_name, $value, boolean $prepend_this_name = true, boolean $group_name = false ) Use this to set custom data for the brick.
set_field_label_prefix ( $prefix )
set_field_label_suffix ( $suffix )
set_inline_css ( $attribute, $value, boolean $group_name = false )
set_is_layout ( $is_layout )
set_is_option ( $is_option )
set_is_sub_brick ( $is_sub_brick )
set_is_sub_field ( $is_sub_field )
set_key ( $key )
set_label ( $label )
set_name ( $name )
set_post_id_to_get_field_from ( $post_id ) Set a value that should be passed as the second argument to ACFs get_field.
set_setting ( $name, $value ) This function makes sure that we have means to get essential settings in the same way as for fields etc.

Защищенные методы

Метод Описание
add_brick ( brick $brick_to_add ) Add a sub brick to the brick.
add_common_field ( string $common_field_array_key, string $key, array $settings = [] ) Add a common field to the brick.
add_field ( field $field ) : mixed Add a field to the brick.
add_flexible_content ( flexible_content $flexible_content ) Add a flexible content to the brick.
add_repeater ( repeater $repeater ) Add a repeater to the brick.
create_sub_brick_object ( $sub_brick_name, $name_setting ) : mixed
get_brick_template_html ( boolean | string $template_base_path = false ) : string Executes a template file for the current class and returns the output.
get_child_brick ( string $brick_class_name, $name, boolean $is_layout = false, boolean $is_sub_field = false ) : mixed Returns an instance of a class with the name of $brick_class_name as an ACF layout in flexible content.
get_child_brick_in_repeater ( $repeater_name, $brick_name, $brick_class_name ) : mixed
get_data_name ( $data_name ) : string
get_field ( $data_name, boolean $post_id = false, boolean $prepend_this_name = true, boolean $get_from_sub_field = false ) : boolean | mixed | null | void
get_field_in_repeater ( string $repeater_name, $data_name, boolean $post_id = false ) : boolean | mixed | null | void
have_rows ( $name ) : boolean Wrapper function for ACFs have_rows()
the_row ( ) Wrapper function for ACFs the_row to avoid confusion on when to use $this or not for ACF functions.

Приватные методы

Метод Описание
prepare_label ( $object_to_prepare_for )
prepare_label_addition ( repeater | flexible_content | brick $object_to_prepare_for, $setting )
prepare_name ( repeater | flexible_content | brick $object_to_prepare_for )
prepare_settings ( $object_to_prepare_for ) Prepare settings of the brick.
remove_fields ( )

Описание методов

__construct() публичный Метод

public __construct ( string $name, string $key = '' )
$name string Name to use when fetching data for the brick
$key string This value must be unique system wide. See the readme-file for tips on how to achieve this. Note that it only needs to be set when registering the brick to a field group, layout etc. No need to pass it when called from the frontend to print the brick.

add_brick() защищенный Метод

Add a sub brick to the brick.
protected add_brick ( brick $brick_to_add )
$brick_to_add brick

add_brick_layout() публичный Метод

Layout files must be placed in [theme]/fewbricks/brick-layouts/.
public add_brick_layout ( string $brick_layout )
$brick_layout string

add_common_field() защищенный Метод

Add a common field to the brick.
protected add_common_field ( string $common_field_array_key, string $key, array $settings = [] )
$common_field_array_key string A key corresponding to an item in the fewbricks_common_fields array
$key string A site wide unique key for the field
$settings array Any extra settings to set on the field. Can be used to override existing settings as well.

add_css_class() публичный Метод

Use set_data_item / get_data_item instead.
public add_css_class ( $class_name )
$class_name

add_field() защищенный Метод

Add a field to the brick.
protected add_field ( field $field ) : mixed
$field fewbricks\acf\fields\field
Результат mixed

add_fields() публичный Метод

public add_fields ( $fields_to_add )
$fields_to_add

add_flexible_content() защищенный Метод

Add a flexible content to the brick.
protected add_flexible_content ( flexible_content $flexible_content )
$flexible_content fewbricks\acf\fields\flexible_content

add_repeater() защищенный Метод

Add a repeater to the brick.
protected add_repeater ( repeater $repeater )
$repeater fewbricks\acf\fields\repeater

create_sub_brick_object() защищенный Метод

protected create_sub_brick_object ( $sub_brick_name, $name_setting ) : mixed
$sub_brick_name
$name_setting
Результат mixed

get_arg() публичный Метод

Get an argument.
public get_arg ( string $name, boolean $default = false ) : mixed
$name string The name of the argument to get
$default boolean The value to return if there is no argument with the sent name.
Результат mixed The value of the argument or default if the argument ha snot been set

get_brick_layouted_html() публичный Метод

public get_brick_layouted_html ( $html ) : string
$html
Результат string

get_brick_layouts() публичный Метод

Returns the brick layouts set for the brick. These are the values previously passed to set_brick_layouts and/or add_brick_layout.
public get_brick_layouts ( ) : array
Результат array

get_brick_template_html() защищенный Метод

Implements filter fewbricks/brick/brick_template_base_path allowing you to override where the template file resides. Value returned by the hook should end with a slash. Note that the filter will only run if the first argument to this funciton is false.
protected get_brick_template_html ( boolean | string $template_base_path = false ) : string
$template_base_path boolean | string If you want to set a specific base path, pass it here. End with a slash.
Результат string

get_child_brick() защищенный Метод

Returns an instance of a class with the name of $brick_class_name as an ACF layout in flexible content.
protected get_child_brick ( string $brick_class_name, $name, boolean $is_layout = false, boolean $is_sub_field = false ) : mixed
$brick_class_name string The name of the class to get.
$name
$is_layout boolean
$is_sub_field boolean
Результат mixed

get_child_brick_in_repeater() защищенный Метод

protected get_child_brick_in_repeater ( $repeater_name, $brick_name, $brick_class_name ) : mixed
$repeater_name
$brick_name
$brick_class_name
Результат mixed

get_data() публичный Метод

public get_data ( ) : array | boolean
Результат array | boolean

get_data_group() публичный Метод

Use this to get an entire group of data.
public get_data_group ( $group_name, boolean $default_value = false, boolean $prepend_this_name = true ) : boolean | mixed
$group_name string The name of the group.
$default_value boolean If the group could not be found, this value will be returned.
$prepend_this_name boolean If the name of the brick should be prepended on the group name.
Результат boolean | mixed

get_data_item() публичный Метод

Get the value of a data item
public get_data_item ( $item_name, boolean $prepend_this_name = true, boolean $group_name = false, boolean $default_value = false ) : boolean | mixed
$item_name string The name of the item that we want to get.
$prepend_this_name boolean If the name of the brick should be prepended on the item name. See set_data_item for more info on this.
$group_name boolean The name of the group that the data is in.
$default_value boolean If the data item does not exist, this is what will be returned.
Результат boolean | mixed

get_data_name() защищенный Метод

protected get_data_name ( $data_name ) : string
$data_name
Результат string

get_field() защищенный Метод

protected get_field ( $data_name, boolean $post_id = false, boolean $prepend_this_name = true, boolean $get_from_sub_field = false ) : boolean | mixed | null | void
$data_name
$post_id boolean
$prepend_this_name boolean
$get_from_sub_field boolean
Результат boolean | mixed | null | void

get_field_in_repeater() защищенный Метод

protected get_field_in_repeater ( string $repeater_name, $data_name, boolean $post_id = false ) : boolean | mixed | null | void
$repeater_name string The name of the repeater that the field with the data is in.
$data_name
$post_id boolean Specific post id
Результат boolean | mixed | null | void

get_html() публичный Метод

public get_html ( array $args = [], mixed $brick_layouts = false ) : string
$args array Any arguments that you need to pass to the brick on runtime. Available as $this->get_html_args
$brick_layouts mixed Array or string with the file name(s) (without .php) of any layouts that you want to wrap the brick in. Layout files must be placed in [theme]/fewbricks/brick-layouts/.
Результат string

get_inline_css() публичный Метод

public get_inline_css ( boolean $group_name = false ) : boolean | mixed | string
$group_name boolean
Результат boolean | mixed | string

get_is_layout() публичный Метод

public get_is_layout ( ) : boolean
Результат boolean

get_is_option() публичный Метод

public get_is_option ( ) : boolean
Результат boolean

get_is_sub_field() публичный Метод

public get_is_sub_field ( ) : boolean
Результат boolean

get_key() публичный Метод

public get_key ( ) : string
Результат string

get_name() публичный Метод

public get_name ( ) : string
Результат string

get_post_id_to_get_field_from() публичный Метод

public get_post_id_to_get_field_from ( ) : boolean
Результат boolean

get_setting() публичный Метод

This function makes sure that we have means to get essential settings in the same way as for fields etc.
public get_setting ( string $name, string $default_value = '' ) : string
$name string
$default_value string
Результат string

get_settings() публичный Метод

Get settings of a field.
public get_settings ( fewbricks\acf\field-group | layout | repeater | flexible_content | brick $object_to_get_for ) : array
$object_to_get_for fewbricks\acf\field-group | fewbricks\acf\layout | fewbricks\acf\fields\repeater | fewbricks\acf\fields\flexible_content | brick
Результат array

has_brick_layout() публичный Метод

Checks if the brick has a layout with the name that you pass to the function. Returns true if it does, false if not.
public has_brick_layout ( $brick_layout_name ) : boolean
$brick_layout_name
Результат boolean True if the brick has a layout with the passed name, false if not.

have_rows() защищенный Метод

Wrapper function for ACFs have_rows()
protected have_rows ( $name ) : boolean
$name
Результат boolean

set_arg() публичный Метод

Set an argument.
public set_arg ( $name, $value )
$name
$value

set_brick_layouts() публичный Метод

Set brick layouts.
public set_brick_layouts ( string | array $brick_layouts )
$brick_layouts string | array Array or string with the name of the layout(s) (without .php). Layout files must be placed in [theme]/fewbricks/brick-layouts/.

set_data() публичный Метод

public set_data ( array $data ) : brick
$data array
Результат brick $this

set_data_item() публичный Метод

Use this to set custom data for the brick.
public set_data_item ( $item_name, $value, boolean $prepend_this_name = true, boolean $group_name = false )
$item_name string The name of the item.
$value mixed The value of the item.
$prepend_this_name boolean If the item name should be prepended with the name of the brick. This is an unfortunate left over from an early version. But it would cause a lot of trouble to remove it now so we leave it be.
$group_name boolean Use this if you want to create groups of data.

set_field_label_prefix() публичный Метод

public set_field_label_prefix ( $prefix )
$prefix

set_field_label_suffix() публичный Метод

public set_field_label_suffix ( $suffix )
$suffix

set_inline_css() публичный Метод

public set_inline_css ( $attribute, $value, boolean $group_name = false )
$attribute
$value
$group_name boolean

set_is_layout() публичный Метод

public set_is_layout ( $is_layout )
$is_layout

set_is_option() публичный Метод

public set_is_option ( $is_option )
$is_option

set_is_sub_brick() публичный Метод

public set_is_sub_brick ( $is_sub_brick )
$is_sub_brick

set_is_sub_field() публичный Метод

public set_is_sub_field ( $is_sub_field )
$is_sub_field

set_key() публичный Метод

public set_key ( $key )
$key

set_label() публичный Метод

public set_label ( $label )
$label

set_name() публичный Метод

public set_name ( $name )
$name

set_post_id_to_get_field_from() публичный Метод

Note that it can also be options, taxonomies, users etc.
public set_post_id_to_get_field_from ( $post_id )
$post_id

set_setting() публичный Метод

This function makes sure that we have means to get essential settings in the same way as for fields etc.
public set_setting ( $name, $value )
$name
$value

the_row() защищенный Метод

Wrapper function for ACFs the_row to avoid confusion on when to use $this or not for ACF functions.
protected the_row ( )

Описание свойств

$args защищенное свойство

A place to store arbitrary arguments.
protected $args

$data защищенное свойство

Data for the brick
protected $data

$get_html_args защищенное свойство

Extra settings that is passed to get_html() / get_brick_html()
protected $get_html_args

$is_layout защищенное свойство

True if the brick is a layout for flexible content
protected $is_layout

$is_option защищенное свойство

True if the brick belongs to an ACF options page.
protected $is_option

$is_sub_brick защищенное свойство

True if the brick is sub brick of another brick.
protected $is_sub_brick

$is_sub_field защищенное свойство

True if the brick is a sub field for a repeater
protected $is_sub_field

$settings защищенное свойство

Extra settings to allow for greater flexibility for the arguments.
protected $settings