Hi,
for my current project, I am using markup-ids that create dynamic sub-filters like this :
beans_open_markup_e( "{$current_module}[post-{$post_id}][grid-{$section_index}][column-{$col_index}]", "div", array(
"class" => $current_module,
)
);
that translates to something like
<div class="lablab-accordion" data-markup-id="lablab-accordion[post-319][grid-2][column-1]">
Now when I want to add a css class only to the accordion in the first column of the second grid of post number 319 using this:
beans_add_attribute( 'lablab-accordion[post-319][grid-2][column-1]', 'class', 'test' );
everything works fine. But when I remove the column-sub-filter and use
beans_add_attribute( 'lablab-accordion[post-319][grid-2]', 'class', 'test' );
the class "test" is added twice (to the same element). When I also remove the grid-sub-filter, the class is added only once.
I don't know why this happens, but the add
method of the _Beans_Attributes
class seems to be called twice when I set 3 sub-filters in the markup and target an element using only the second sub-level.
Inside this method, there's some logic checking if the attribute already exists and if it does, it concatenates the value with the existing value (maybe another css class), but it doesn't check if the same value already exists. So I modified this method (just for testing purposes) like this:
public function add( $attributes ) {
if ( ! isset( $attributes[ $this->attribute ] ) ) {
$attributes[ $this->attribute ] = $this->value;
} else {
$_attributes = explode( ' ', $attributes[$this->attribute] );
if ( ! in_array( $this->value, $_attributes ) ){
$attributes[ $this->attribute ] = $attributes[ $this->attribute ] . ' ' . $this->value;
}
}
return $attributes;
}
and now the class is added only once no matter what combination of sub-filters is used.
But I'd like to understand what's going on there. Is it ok to use 3 sub-filters? It's mentioned here that it should be possible:
Maximum 3 sub-hooks allowed.
Or is it one filter and 2 sub-filters?