function _cms_content_sync_add_push_pool_form in CMS Content Sync 2.1.x
Same name and namespace in other branches
- 8 cms_content_sync.module \_cms_content_sync_add_push_pool_form()
- 2.0.x cms_content_sync.module \_cms_content_sync_add_push_pool_form()
Add the push widgets to the form, providing flow and pool selection.
2 calls to _cms_content_sync_add_push_pool_form()
- cms_content_sync_form_alter in ./
cms_content_sync.module - 1) Make sure the user is informed that content will not only be deleted on this * instance but also on all connected instances if configured that way.
- _cms_content_sync_paragraphs_push_settings_form in ./
cms_content_sync.module - Add the Push settings for to the several Paragraph widget types.
File
- ./
cms_content_sync.module, line 868 - Module file for cms_content_sync.
Code
function _cms_content_sync_add_push_pool_form(&$form, $selectable_push_flows, $entity = NULL, $parentEntity = NULL) {
_cms_content_sync_add_form_group($form);
$selected_flow = NULL;
// Flow selection.
if (count($selectable_push_flows) === 1) {
$id = array_keys($selectable_push_flows)[0];
$form['cms_content_sync_group']['cms_content_sync_flow'] = [
'#title' => t('Push flow selection'),
'#type' => 'hidden',
'#value' => $id,
];
$selected_flow = Flow::getAll()[$id];
}
else {
$flow_options = [];
foreach ($selectable_push_flows as $flow_id => $selectable_push_flow) {
if (!$selected_flow) {
$selected_flow = Flow::getAll()[$flow_id];
}
$flow_options[$flow_id] = $selectable_push_flow['flow_label'];
}
$form['cms_content_sync_group']['cms_content_sync_flow'] = [
'#title' => t('Push flow selection'),
'#type' => 'select',
'#default_value' => $selected_flow->id,
'#options' => $flow_options,
'#ajax' => [
'callback' => '_cms_content_sync_update_pool_selector',
'event' => 'change',
'wrapper' => 'ajax-pool-selector-wrapper',
],
];
}
// Pool selection.
$options = $selectable_push_flows[$selected_flow->id];
// Get configured widget type for the current active flow.
if ($options['widget_type'] == 'single_select' || $options['widget_type'] == 'multi_select') {
$widget_type = 'select';
}
else {
$widget_type = $options['widget_type'];
}
$pushed_to_pools = [];
$selected_pools = [];
if ($entity) {
$infos = EntityStatus::getInfosForEntity($entity
->getEntityTypeId(), $entity
->uuid());
foreach ($infos as $info) {
if ($info
->getLastPull()) {
$pushed_to_pools[] = $info
->getPool()
->id();
}
else {
foreach ($selected_flow
->getController()
->getPoolsToPushTo($entity, PushIntent::PUSH_ANY, SyncIntent::ACTION_CREATE, FALSE) as $pool) {
$pushed_to_pools[] = $pool->id;
}
}
$selected_pools = $pushed_to_pools;
}
}
elseif ($parentEntity) {
foreach ($selected_flow
->getController()
->getPoolsToPushTo($parentEntity, PushIntent::PUSH_ANY, SyncIntent::ACTION_UPDATE, FALSE) as $pool) {
if (!isset($options['pools'][$pool->id])) {
continue;
}
$selected_pools[] = $pool->id;
}
}
$single = $options['widget_type'] == 'single_select' || $options['widget_type'] == 'radios';
$pool_list = [];
if ($single) {
$pool_list['ignore'] = t('None');
$default_value = empty($selected_pools) ? 'ignore' : $selected_pools[0];
}
else {
$default_value = $selected_pools;
}
$pool_list = array_merge($pool_list, $options['pools']);
$form['cms_content_sync_group']['cms_content_sync_pool'] = [
'#title' => t('Push to pool'),
'#prefix' => '<div id="ajax-pool-selector-wrapper">',
'#suffix' => '</div>',
'#type' => $widget_type,
'#default_value' => $default_value,
'#options' => $pool_list,
'#disabled' => !empty($pushed_to_pools),
];
if ($entity) {
$form['cms_content_sync_group']['cms_content_sync_uuid'] = [
'#type' => 'hidden',
'#value' => $entity
->uuid(),
];
}
if ($options['widget_type'] == 'multi_select') {
$form['cms_content_sync_group']['cms_content_sync_pool']['#multiple'] = TRUE;
}
// Entity form submit handler.
if (isset($form['actions']['submit'])) {
if (!empty($form['actions']['submit']['#submit'])) {
array_unshift($form['actions']['submit']['#submit'], '_cms_content_sync_set_entity_push_pools');
}
else {
$form['actions']['submit']['#submit'][] = '_cms_content_sync_set_entity_push_pools';
}
}
}