Last active
December 25, 2017 16:05
-
-
Save hawkidoki/440e96bcfae5853b114abe536e611405 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('acf/field_group/admin_head', 'hwk_acf_flexible_metabox'); | |
function hwk_acf_flexible_metabox(){ | |
global $field_group; | |
if(isset($field_group['hwk_flexible_dynamique']) && !empty($field_group['hwk_flexible_dynamique'])){ | |
add_meta_box('acf-field-group-layouts-flexible', __('Flexible Layouts', 'acf'), function(){ | |
global $field_group; | |
$group = $field_group; | |
if(!acf_is_field_group_key( $group['key'])) | |
$group['key'] = uniqid('group_'); | |
$name = str_replace('-', '_', sanitize_title($group['title'])); | |
$flexible = 'hwk_contenu_flexible_' . $name; | |
$sub_groups = hwk_acf_get_layouts($flexible); | |
ob_start(); ?> | |
<div class="hwk-acf-field-group-fields" style="margin:-15px -12px;"> | |
<div class="acf-field-list"> | |
<?php if(!empty($sub_groups)){ ?> | |
<?php | |
$i=0; | |
$duplicate = array(); | |
foreach($sub_groups as $sub_group_key){ $i++; | |
if(in_array($sub_group_key, $duplicate)) | |
continue; | |
$duplicate[] = $sub_group_key; ?> | |
<?php $sub_group = _acf_get_field_group_by_key($sub_group_key); ?> | |
<div class="acf-field-object acf-field-object-text"> | |
<div class="handle"> | |
<ul class="acf-hl acf-tbody"> | |
<li class="li-field-order"> | |
<span class="acf-icon"><?php echo $i; ?></span> | |
</li> | |
<li class="li-field-label"> | |
<strong> | |
<a class="edit-field" title="Modifier ce champ" href="<?php echo admin_url('post.php?post='.$sub_group['ID'].'&action=edit'); ?>"><?php echo $sub_group['title']; ?></a> | |
</strong> | |
<div class="row-options"> | |
<a class="edit-field" title="Modifier ce champ" href="<?php echo admin_url('post.php?post='.$sub_group['ID'].'&action=edit'); ?>">Modifier</a> | |
</div> | |
</li> | |
<li class="li-field-name"> | |
<?php echo (isset($sub_group['hwk_flexible_group_title']) && !empty($sub_group['hwk_flexible_group_title'])) ? $sub_group['hwk_flexible_group_title'] : $sub_group['title']; ?> | |
</li> | |
</ul> | |
</div> | |
</div> | |
<?php } ?> | |
<?php }else{ ?> | |
<div class="acf-field-object acf-field-object-text"> | |
<div class="no-fields-message" style=""> | |
Aucun layout. Assignez un groupe de champs au contenu flexible. | |
</div> | |
</div> | |
<?php } ?> | |
</div> | |
</div> | |
<?php | |
$html = ob_get_clean(); | |
acf_render_field_wrap(array( | |
'label' => '', | |
'instructions' => '', | |
'type' => 'message', | |
'name' => 'hwk_flexible_layouts', | |
'prefix' => 'acf_field_group', | |
'new_lines' => '', | |
//'message' => '' | |
'message' => $html | |
)); | |
?> | |
<script type="text/javascript"> | |
if( typeof acf !== 'undefined' ) { | |
acf.postbox.render({ | |
'id': 'acf-field-group-layouts-flexible', | |
'label': 'top' | |
}); | |
} | |
</script> | |
<?php | |
}, 'acf-field-group', 'normal', 'high'); | |
} | |
$match = false; | |
foreach($field_group['location'] as $location){ | |
foreach($location as $rule){ | |
if($rule['param'] == 'hwk_flexible_content_rule'){ | |
$match = true; | |
break; | |
} | |
} | |
} | |
if(!$match && !acf_get_fields($field_group)){ | |
add_meta_box('acf-field-group-options-flexible', __('Flexible Dynamique', 'acf'), function(){ | |
global $field_group; | |
$group = $field_group; | |
if(!acf_is_field_group_key( $group['key'])) | |
$group['key'] = uniqid('group_'); | |
acf_render_field_wrap(array( | |
'label' => __('Activer','acf'), | |
'instructions' => __('Convertir ce groupe de champs en contenu flexible dynamique','acf'), | |
'type' => 'true_false', | |
'name' => 'hwk_flexible_dynamique', | |
'prefix' => 'acf_field_group', | |
'value' => (isset($group['hwk_flexible_dynamique'])) ? $group['hwk_flexible_dynamique'] : '', | |
'ui' => true, | |
'ui_on_text' => "Oui", | |
'ui_off_text' => "Non" | |
)); | |
?> | |
<script type="text/javascript"> | |
if( typeof acf !== 'undefined' ) { | |
acf.postbox.render({ | |
'id': 'acf-field-group-options-flexible', | |
'label': 'left' | |
}); | |
} | |
jQuery(document).ready(function($){ | |
if($('[data-name="hwk_flexible_dynamique"] .acf-switch').hasClass('-on')) | |
$('#acf-field-group-fields.postbox').addClass('acf-hidden'); | |
$('[data-name="hwk_flexible_dynamique"] .acf-switch').click(function(){ | |
if($(this).hasClass('-on')){ | |
$('#acf-field-group-fields.postbox').removeClass('acf-hidden'); | |
$('#acf-field-group-layouts-flexible').addClass('acf-hidden'); | |
}else{ | |
$('#acf-field-group-fields.postbox').addClass('acf-hidden'); | |
$('#acf-field-group-layouts-flexible').removeClass('acf-hidden'); | |
} | |
}); | |
}); | |
</script> | |
<?php | |
}, 'acf-field-group', 'normal', 'high'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment