Helper function to construct the storage changes in a configuration synchronization form.
array $form: The form structure to add to. Passed by reference.
array $form_state: The current state of the form. Passed by reference.
Drupal\Core\Config\StorageInterface $source_storage: The source storage to retrieve differences from.
Drupal\Core\Config\StorageInterface $target_storage: The target storage to compare differences to.
function config_admin_sync_form(array &$form, array &$form_state, StorageInterface $source_storage, StorageInterface $target_storage) {
$source_list = $source_storage
->listAll();
if (empty($source_list)) {
$form['no_changes'] = array(
'#markup' => t('There is no configuration to import.'),
);
return $form;
}
$config_changes = config_sync_get_changes($source_storage, $target_storage);
if (empty($config_changes)) {
$form['no_changes'] = array(
'#markup' => t('There are no configuration changes.'),
);
return $form;
}
foreach ($config_changes as $config_change_type => $config_files) {
if (empty($config_files)) {
continue;
}
// @todo A table caption would be more appropriate, but does not have the
// visual importance of a heading.
$form[$config_change_type]['heading'] = array(
'#theme' => 'html_tag__h3',
'#tag' => 'h3',
);
switch ($config_change_type) {
case 'create':
$form[$config_change_type]['heading']['#value'] = format_plural(count($config_files), '@count new', '@count new');
break;
case 'change':
$form[$config_change_type]['heading']['#value'] = format_plural(count($config_files), '@count changed', '@count changed');
break;
case 'delete':
$form[$config_change_type]['heading']['#value'] = format_plural(count($config_files), '@count removed', '@count removed');
break;
}
$form[$config_change_type]['list'] = array(
'#theme' => 'table',
'#header' => array(
'Name',
),
);
foreach ($config_files as $config_file) {
$form[$config_change_type]['list']['#rows'][] = array(
$config_file,
);
}
}
}