Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,14 @@ function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )

foreach ( $params as $param => $value )
{
$customAttributes[$param] = $value;
if (is_array($value))
{
$customAttributes[$param] = implode(',', $value);
}
else
{
$customAttributes[$param] = $value;
}
}

$block->setAttribute( 'custom_attributes', $customAttributes );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@
$custom_attribute_types = array()
$custom_attribute_names = array()
$custom_attribute_selections = array()
$custom_attribute_value = ''
$custom_attribute_values = array()
$custom_attribute_default = ''
$custom_attribute_multiselect_setting = false()
$custom_attribute_multiselect_value = false()
$loop_count = 0}
{if ezini_hasvariable( $block.type, 'CustomAttributes', 'block.ini' )}
{set $custom_attributes = ezini( $block.type, 'CustomAttributes', 'block.ini' )}
Expand Down Expand Up @@ -129,12 +134,56 @@
<input id="block-custom_attribute-{$block_id}-{$loop_count}" class="textfield block-control" type="text" name="ContentObjectAttribute_ezpage_block_custom_attribute_{$attribute.id}[{$zone_id}][{$block_id}][{$custom_attrib}]" value="{$block.custom_attributes[$custom_attrib]|wash()}" />
{/case}
{case match = 'select'}
{set $custom_attribute_selections = ezini( $block.type, concat( 'CustomAttributeSelection_', $custom_attrib ), 'block.ini' )}
<select id="block-custom_attribute-{$block_id}-{$loop_count}" class="block-control" name="ContentObjectAttribute_ezpage_block_custom_attribute_{$attribute.id}[{$zone_id}][{$block_id}][{$custom_attrib}]">
{foreach $custom_attribute_selections as $selection_value => $selection_name}
<option value="{$selection_value|wash()}"{if eq( $block.custom_attributes[$custom_attrib], $selection_value )} selected="selected"{/if} />{$selection_name|wash()}</option>
{/foreach}
</select>
{set $custom_attribute_selections = ezini( $block.type, concat( 'CustomAttributeSelection_', $custom_attrib ),'block.ini' )}

{* Check if there is a default value for the select *}
{if ezini_hasvariable( $block.type, concat( 'CustomAttributeSelectionDefault_', $custom_attrib ), 'block.ini' )}
{set $custom_attribute_default = ezini( $block.type, concat( 'CustomAttributeSelectionDefault_', $custom_attrib ), 'block.ini' )}
{else}
{set $custom_attribute_default = ''}
{/if}

{* Check if there is a value set for the custom attribute - empty is assumed to be no value *}
{if $block.custom_attributes[$custom_attrib]|ne( '' )}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that the user would want to select no value and we only want to set a default on the first load? (I'm not sure what the solution would be in that case and/or whether that's a valid use case, but it's something to consider.)

{set $custom_attribute_value = $block.custom_attributes[$custom_attrib]}
{else}
{set $custom_attribute_value = $custom_attribute_default}
{/if}

{* Test for multiselect option *}
{set $custom_attribute_multiselect_setting = ezini_hasvariable( $block.type, concat( 'CustomAttributeMultipleSelection_', $custom_attrib ), 'block.ini' )}
{* If multiselect select option is set, use the value *}
{if $custom_attribute_multiselect_setting}
{* Test against common settings which may be used *}
{set $custom_attribute_multiselect_value = array('1',1,'true',true())|contains(ezini( $block.type, concat( 'CustomAttributeMultipleSelection_', $custom_attrib ), 'block.ini' ))}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should standardize a value. I would suggest "enabled".

{else}
{* Default value is false - single select *}
{set $custom_attribute_multiselect_value = false()}
{/if}

{* Set custom_attribute_values based on the multiselect setting value *}
{if $custom_attribute_multiselect_value}
{set $custom_attribute_values = $custom_attribute_value|explode(',')}
{else}
{set $custom_attribute_values = array( $custom_attribute_value )}
{/if}

{def $i_selected = ''}
<select id="block-custom_attribute-{$block_id}-{$loop_count}" class="block-control" name="ContentObjectAttribute_ezpage_block_custom_attribute_{$attribute.id}[{$zone_id}][{$block_id}][{$custom_attrib}]{if $custom_attribute_multiselect_value}[]" multiple="multiple" size="{min($custom_attribute_selections|count(), 6)}"{else}" size="1"{/if}>
{foreach $custom_attribute_selections as $selection_value => $selection_name}

{* mark option as selected *}
{set $i_selected = ''}
{foreach $custom_attribute_values as $value}
{if eq( $value|trim(), $selection_value|trim() )}
{set $i_selected = 'selected="selected"'}
{break}
{/if}
{/foreach}

<option value="{$selection_value|trim()|wash()}" {$i_selected}>{$selection_name|wash()}</option>
{/foreach}
</select>
{/case}
{case}
<input id="block-custom_attribute-{$block_id}-{$loop_count}" class="textfield block-control" type="text" name="ContentObjectAttribute_ezpage_block_custom_attribute_{$attribute.id}[{$zone_id}][{$block_id}][{$custom_attrib}]" value="{$block.custom_attributes[$custom_attrib]|wash()}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ RootSubtree=1
# CustomAttributeSelection_color[]
# CustomAttributeSelection_color[blue]=Blue
# CustomAttributeSelection_color[green]=Green
# Set the default
# CustomAttributeSelectionDefault_color=green
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can multiple defaults be selected? If so, this should be documented.

# Allow multiple items to be selected
# CustomAttributeMultipleSelection_color[]=1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be an array?

# UseBrowseMode[node_id]=true
# Optional: set the browse mode start node for a custom attribute
# CustomAttributeStartBrowseNode[node_id]=<node_id>
Expand Down