PHP Class fewbricks\bricks\brick

Afficher le fichier Open project: folbert/fewbricks Class Usage Examples

Protected Properties

Свойство Type Description
$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.

Méthodes publiques

Méthode Description
__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.

Méthodes protégées

Méthode Description
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.

Private Methods

Méthode Description
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 ( )

Method Details

__construct() public méthode

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() protected méthode

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

add_brick_layout() public méthode

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

add_common_field() protected méthode

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() public méthode

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

add_field() protected méthode

Add a field to the brick.
protected add_field ( field $field ) : mixed
$field fewbricks\acf\fields\field
Résultat mixed

add_fields() public méthode

public add_fields ( $fields_to_add )
$fields_to_add

add_flexible_content() protected méthode

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

add_repeater() protected méthode

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

create_sub_brick_object() protected méthode

protected create_sub_brick_object ( $sub_brick_name, $name_setting ) : mixed
$sub_brick_name
$name_setting
Résultat mixed

get_arg() public méthode

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.
Résultat mixed The value of the argument or default if the argument ha snot been set

get_brick_layouted_html() public méthode

public get_brick_layouted_html ( $html ) : string
$html
Résultat string

get_brick_layouts() public méthode

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
Résultat array

get_brick_template_html() protected méthode

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.
Résultat string

get_child_brick() protected méthode

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
Résultat mixed

get_child_brick_in_repeater() protected méthode

protected get_child_brick_in_repeater ( $repeater_name, $brick_name, $brick_class_name ) : mixed
$repeater_name
$brick_name
$brick_class_name
Résultat mixed

get_data() public méthode

public get_data ( ) : array | boolean
Résultat array | boolean

get_data_group() public méthode

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.
Résultat boolean | mixed

get_data_item() public méthode

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.
Résultat boolean | mixed

get_data_name() protected méthode

protected get_data_name ( $data_name ) : string
$data_name
Résultat string

get_field() protected méthode

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
Résultat boolean | mixed | null | void

get_field_in_repeater() protected méthode

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
Résultat boolean | mixed | null | void

get_html() public méthode

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/.
Résultat string

get_inline_css() public méthode

public get_inline_css ( boolean $group_name = false ) : boolean | mixed | string
$group_name boolean
Résultat boolean | mixed | string

get_is_layout() public méthode

public get_is_layout ( ) : boolean
Résultat boolean

get_is_option() public méthode

public get_is_option ( ) : boolean
Résultat boolean

get_is_sub_field() public méthode

public get_is_sub_field ( ) : boolean
Résultat boolean

get_key() public méthode

public get_key ( ) : string
Résultat string

get_name() public méthode

public get_name ( ) : string
Résultat string

get_post_id_to_get_field_from() public méthode

get_setting() public méthode

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
Résultat string

get_settings() public méthode

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
Résultat array

has_brick_layout() public méthode

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
Résultat boolean True if the brick has a layout with the passed name, false if not.

have_rows() protected méthode

Wrapper function for ACFs have_rows()
protected have_rows ( $name ) : boolean
$name
Résultat boolean

set_arg() public méthode

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

set_brick_layouts() public méthode

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 méthode

public set_data ( array $data ) : brick
$data array
Résultat brick $this

set_data_item() public méthode

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 méthode

public set_field_label_prefix ( $prefix )
$prefix

set_field_label_suffix() public méthode

public set_field_label_suffix ( $suffix )
$suffix

set_inline_css() public méthode

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

set_is_layout() public méthode

public set_is_layout ( $is_layout )
$is_layout

set_is_option() public méthode

public set_is_option ( $is_option )
$is_option

set_is_sub_brick() public méthode

public set_is_sub_brick ( $is_sub_brick )
$is_sub_brick

set_is_sub_field() public méthode

public set_is_sub_field ( $is_sub_field )
$is_sub_field

set_key() public méthode

public set_key ( $key )
$key

set_label() public méthode

public set_label ( $label )
$label

set_name() public méthode

public set_name ( $name )
$name

set_post_id_to_get_field_from() public méthode

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

set_setting() public méthode

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() protected méthode

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

Property Details

$args protected_oe property

A place to store arbitrary arguments.
protected $args

$data protected_oe property

Data for the brick
protected $data

$get_html_args protected_oe property

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

$is_layout protected_oe property

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

$is_option protected_oe property

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

$is_sub_brick protected_oe property

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

$is_sub_field protected_oe property

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

$settings protected_oe property

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