Skip to content

Commit

Permalink
added is_sortable arg to repeater blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewKosloski committed Jun 26, 2017
1 parent df46901 commit 8019157
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions metabox_constructor_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,11 @@ public function addWysiwyg($args, $repeater = false) {
}

public function addRepeaterBlock($args) {
$field = array_merge(array('type' => 'repeater', 'single_label' => 'Item'), $args);
$field = array_merge(array(
'type' => 'repeater',
'single_label' => 'Item',
'is_sortable' => true
), $args);
$this->_fields[] = $field;
}

Expand Down Expand Up @@ -385,6 +389,8 @@ public function get_repeated_block($field, $meta, $index, $isTemplate = false) {
esc_attr( $this->get_block_element_class('repeated', false) )
);

echo sprintf('%s %d', $field['single_label'], $index + 1);

foreach($field['fields'] as $child_field) {
$old_id = $child_field['id'];

Expand All @@ -410,13 +416,15 @@ public function get_repeated_block($field, $meta, $index, $isTemplate = false) {
);

// "sort" button
echo sprintf(
'<a class="button %s %s" title="Click and drag to sort">
<span class="dashicons dashicons-menu"></span></span>
</a>',
esc_attr( $this->get_block_element_class('repeater-button', false) ),
esc_attr( sprintf('js-%s-sort', self::BLOCK_NAMESPACE) )
);
if($field['is_sortable']) {
echo sprintf(
'<a class="button %s %s" title="Click and drag to sort">
<span class="dashicons dashicons-menu"></span></span>
</a>',
esc_attr( $this->get_block_element_class('repeater-button', false) ),
esc_attr( sprintf('js-%s-sort', self::BLOCK_NAMESPACE) )
);
}

echo '</div>';
}
Expand Down

0 comments on commit 8019157

Please sign in to comment.