Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/2.2.6 #5885

Merged
merged 4 commits into from
Oct 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 68 additions & 31 deletions includes/base/element-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class Element_Base extends Controls_Stack {
*
* @var Element_Base[]
*/
private $_children;
private $children;

/**
* Element render attributes.
Expand All @@ -39,7 +39,7 @@ abstract class Element_Base extends Controls_Stack {
*
* @var array
*/
private $_render_attributes = [];
private $render_attributes = [];

/**
* Element default arguments.
Expand All @@ -51,19 +51,7 @@ abstract class Element_Base extends Controls_Stack {
*
* @var array
*/
private $_default_args = [];

/**
* Element edit tools.
*
* Holds all the edit tools of the element. For example: delete, duplicate etc.
*
* @access protected
* @static
*
* @var array
*/
protected static $_edit_tools;
private $default_args = [];

/**
* Is type instance.
Expand All @@ -74,7 +62,7 @@ abstract class Element_Base extends Controls_Stack {
*
* @var bool
*/
private $_is_type_instance = true;
private $is_type_instance = true;

/**
* Depended scripts.
Expand All @@ -100,6 +88,18 @@ abstract class Element_Base extends Controls_Stack {
*/
private $depended_styles = [];

/**
* Element edit tools.
*
* Holds all the edit tools of the element. For example: delete, duplicate etc.
*
* @access protected
* @static
*
* @var array
*/
protected static $_edit_tools;

/**
* Add script depends.
*
Expand Down Expand Up @@ -385,11 +385,11 @@ protected function print_template_content( $template_content ) {
* @return Element_Base[] Child elements.
*/
public function get_children() {
if ( null === $this->_children ) {
if ( null === $this->children ) {
$this->init_children();
}

return $this->_children;
return $this->children;
}

/**
Expand All @@ -406,7 +406,7 @@ public function get_children() {
* @return array Default argument(s).
*/
public function get_default_args( $item = null ) {
return self::_get_items( $this->_default_args, $item );
return self::_get_items( $this->default_args, $item );
}

/**
Expand Down Expand Up @@ -439,7 +439,7 @@ public function get_parent() {
* @return Element_Base|false Child element instance, or false if failed.
*/
public function add_child( array $child_data, array $child_args = [] ) {
if ( null === $this->_children ) {
if ( null === $this->children ) {
$this->init_children();
}

Expand All @@ -452,7 +452,7 @@ public function add_child( array $child_data, array $child_args = [] ) {
$child = Plugin::$instance->elements_manager->create_element_instance( $child_data, $child_args, $child_type );

if ( $child ) {
$this->_children[] = $child;
$this->children[] = $child;
}

return $child;
Expand Down Expand Up @@ -501,21 +501,58 @@ public function add_render_attribute( $element, $key = null, $value = null, $ove
return $this;
}

if ( empty( $this->_render_attributes[ $element ][ $key ] ) ) {
$this->_render_attributes[ $element ][ $key ] = [];
if ( empty( $this->render_attributes[ $element ][ $key ] ) ) {
$this->render_attributes[ $element ][ $key ] = [];
}

settype( $value, 'array' );

if ( $overwrite ) {
$this->_render_attributes[ $element ][ $key ] = $value;
$this->render_attributes[ $element ][ $key ] = $value;
} else {
$this->_render_attributes[ $element ][ $key ] = array_merge( $this->_render_attributes[ $element ][ $key ], $value );
$this->render_attributes[ $element ][ $key ] = array_merge( $this->render_attributes[ $element ][ $key ], $value );
}

return $this;
}

/**
* Get Render Attributes
*
* Used to retrieve render attribute.
*
* The returned array is either all elements and their attributes if no `$element` is specified, an array of all
* attributes of a specific element or a specific attribute properties if `$key` is specified.
*
* Returns null if one of the requested parameters isn't set.
*
* @param string $element
* @param string $key
*
* @return array
*/
public function get_render_attributes( $element = '', $key = '' ) {
$attributes = $this->render_attributes;

if ( $element ) {
if ( ! isset( $attributes[ $element ] ) ) {
return null;
}

$attributes = $attributes[ $element ];

if ( $key ) {
if ( ! isset( $attributes[ $key ] ) ) {
return null;
}

$attributes = $attributes[ $key ];
}
}

return $attributes;
}

/**
* Set render attribute.
*
Expand Down Expand Up @@ -549,11 +586,11 @@ public function set_render_attribute( $element, $key = null, $value = null ) {
* is empty or not exist.
*/
public function get_render_attribute_string( $element ) {
if ( empty( $this->_render_attributes[ $element ] ) ) {
if ( empty( $this->render_attributes[ $element ] ) ) {
return '';
}

$render_attributes = $this->_render_attributes[ $element ];
$render_attributes = $this->render_attributes[ $element ];

$attributes = [];

Expand Down Expand Up @@ -739,7 +776,7 @@ protected function render_edit_tools() {
* @return bool Whether the element is an instance of that type.
*/
public function is_type_instance() {
return $this->_is_type_instance;
return $this->is_type_instance;
}

/**
Expand Down Expand Up @@ -903,7 +940,7 @@ private function get_child_type( $element_data ) {
* @access private
*/
private function init_children() {
$this->_children = [];
$this->children = [];

$children_data = $this->get_data( 'elements' );

Expand Down Expand Up @@ -936,9 +973,9 @@ private function init_children() {
**/
public function __construct( array $data = [], array $args = null ) {
if ( $data ) {
$this->_is_type_instance = false;
$this->is_type_instance = false;
} elseif ( $args ) {
$this->_default_args = $args;
$this->default_args = $args;
}

parent::__construct( $data );
Expand Down