Commit d1c9b9cb authored by Christian Wach's avatar Christian Wach

Enable sync checkbox on "Groups" create group screen

parent 5124e01b
<!-- assets/templates/admin/settings-groups.php -->
<!-- assets/templates/admin/settings-groups-create.php -->
<div class="field">
<label for="civicrm-group-field" class="field-label civicrm-group-field"><input type="checkbox" id="civicrm-group-field" name="civicrm-group-field" /> <?php _e( 'Create a CiviCRM group', 'civicrm-groups-sync' ); ?></label>
<label for="civicrm-group-field" class="field-label civicrm-group-field"><input type="checkbox" id="civicrm-group-field" name="civicrm-group-field" value="1" /> <?php _e( 'Create a CiviCRM group', 'civicrm-groups-sync' ); ?></label>
<p class="description"><?php _e( 'Checking this will create a CiviCRM group that is linked to this group. The group members will exist in both groups.', 'civicrm-groups-sync' ); ?></p>
</div>
<!-- assets/templates/admin/settings-groups-edit.php -->
<div class="field">
<p><?php _e( 'There is an existing CiviCRM group that is linked to this group. The group members will exist in both groups.', 'civicrm-groups-sync' ); ?></p>
</div>
......@@ -197,6 +197,9 @@ class CiviCRM_Groups_Sync_WordPress {
*/
public function group_created( $group_id ) {
// Bail if our checkbox was not checked.
if ( ! $this->form_get_sync() ) return;
// Get full group data.
$group = Groups_Group::read( $group_id );
......@@ -444,7 +447,7 @@ class CiviCRM_Groups_Sync_WordPress {
ob_start();
// Include template.
include( CIVICRM_GROUPS_SYNC_PATH . 'assets/templates/admin/settings-groups.php' );
include( CIVICRM_GROUPS_SYNC_PATH . 'assets/templates/admin/settings-groups-create.php' );
// Save the output and flush the buffer.
$field = ob_get_clean();
......@@ -470,6 +473,26 @@ class CiviCRM_Groups_Sync_WordPress {
*/
public function form_edit_filter( $content, $group_id ) {
// Get existing CiviCRM group.
$civicrm_group = $this->plugin->civicrm->group_get_by_wp_id( $group_id );
// Bail if there isn't one.
if ( $civicrm_group === false ) {
return;
}
// Start buffering.
ob_start();
// Include template.
include( CIVICRM_GROUPS_SYNC_PATH . 'assets/templates/admin/settings-groups-edit.php' );
// Save the output and flush the buffer.
$field = ob_get_clean();
// Add field to form.
$content .= $field;
// --<
return $content;
......@@ -478,7 +501,35 @@ class CiviCRM_Groups_Sync_WordPress {
/**
* Intercept successful Group form.
* Get our Group form variable.
*
* @since 0.1.1
*
* @return bool $sync True if the group should be synced, false otherwise.
*/
public function form_get_sync() {
// Do not sync by default.
$sync = false;
// Maybe override if our POST variable is set.
if ( isset( $_POST['civicrm-group-field'] ) AND $_POST['civicrm-group-field'] == 1 ) {
$sync = true;
}
// --<
return $sync;
}
/**
* Intercept successful Group form submission.
*
* Unfortunately for our purposes, this callback is triggered after the
* group has been created. We therefore have to check for our POST variable
* in `group_created`, `group_updated` and `group_deleted` instead.
*
* @since 0.1
*
......@@ -486,6 +537,16 @@ class CiviCRM_Groups_Sync_WordPress {
*/
public function form_submitted( $group_id ) {
/*
$e = new Exception;
$trace = $e->getTraceAsString();
error_log( print_r( array(
'method' => __METHOD__,
'group_id' => $group_id,
//'backtrace' => $trace,
), true ) );
*/
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment