protected function CopyRemoteFlow::flowImportForm in CMS Content Sync 8
Same name and namespace in other branches
- 2.1.x src/Form/CopyRemoteFlow.php \Drupal\cms_content_sync\Form\CopyRemoteFlow::flowImportForm()
- 2.0.x src/Form/CopyRemoteFlow.php \Drupal\cms_content_sync\Form\CopyRemoteFlow::flowImportForm()
Step 4: Adjust configuration before importing.
Return value
array the form
1 call to CopyRemoteFlow::flowImportForm()
- CopyRemoteFlow::form in src/
Form/ CopyRemoteFlow.php - Gets the actual form array to be built.
File
- src/
Form/ CopyRemoteFlow.php, line 665
Class
- CopyRemoteFlow
- Form handler for the Pool add and edit forms.
Namespace
Drupal\cms_content_sync\FormCode
protected function flowImportForm(array $form, FormStateInterface $form_state) {
$url = $form_state
->getValue('url') ? $form_state
->getValue('url') : $_GET['url'];
$pools = $form_state
->getValue('pools');
$flow = $form_state
->getValue('flow');
$elements['url'] = [
'#type' => 'hidden',
'#value' => $url,
];
$elements['pools'] = [
'#type' => 'hidden',
'#value' => $pools,
];
$elements['flow'] = [
'#type' => 'hidden',
'#value' => $flow,
];
$flow = $this
->getFlowConfig($url, $flow);
$elements['headline'] = [
'#markup' => '<br><br><h1>Step 4: ' . $this
->t('Copy %name from %site', [
'%name' => $flow
->getName(),
'%site' => $flow
->getSiteName(),
]) . '</h1>' . '<div class="messages messages--status">' . $this
->t('Replace settings of the flow below before importing it. If you want to copy this flow 1:1, just hit Save.<br>You can still edit the Flow and adjust all other settings after importing it.') . '</div>' . '<br><br>',
];
$data = Yaml::decode($flow
->getConfig());
$elements['name'] = [
'#type' => 'textfield',
'#title' => $this
->t('Name'),
'#maxlength' => 255,
'#attributes' => [
'autofocus' => 'autofocus',
],
'#default_value' => $data['name'],
'#description' => $this
->t('An administrative name describing the workflow intended to be achieved with this synchronization.'),
'#required' => true,
];
$elements['id'] = [
'#type' => 'machine_name',
'#default_value' => $data['id'],
'#machine_name' => [
'exists' => [
$this,
'exists',
],
'source' => [
'name',
],
],
'#required' => true,
];
$pushing = [
PushIntent::PUSH_AUTOMATICALLY => false,
PushIntent::PUSH_MANUALLY => false,
PushIntent::PUSH_AS_DEPENDENCY => false,
];
$push_to_pools = [];
$pulling = [
PullIntent::PULL_AUTOMATICALLY => false,
PullIntent::PULL_MANUALLY => false,
PullIntent::PULL_AS_DEPENDENCY => false,
];
$pull_pool_settings = [];
foreach ($data['sync_entities'] as $name => $config) {
// We're only interested in entity type configuration.
if (substr_count($name, '-') > 1) {
continue;
}
if (empty($config['handler']) || Flow::HANDLER_IGNORE === $config['handler']) {
continue;
}
$pushing[$config['export']] = true;
if (isset($config['export_pools'])) {
foreach ($config['export_pools'] as $pool => $setting) {
$push_to_pools[$config['export']][$pool][$setting] = true;
}
}
$pulling[$config['import']] = true;
if (isset($config['import_pools'])) {
foreach ($config['import_pools'] as $pool => $setting) {
$pull_pool_settings[$config['import']][$pool][$setting] = true;
}
}
}
unset($pushing[PushIntent::PUSH_DISABLED], $pulling[PullIntent::PULL_DISABLED]);
$options = [
'export_' . PushIntent::PUSH_AUTOMATICALLY => $this
->t('Push all'),
'export_' . PushIntent::PUSH_MANUALLY => $this
->t('Push manually'),
'export_' . PushIntent::PUSH_AS_DEPENDENCY => $this
->t('Push referenced'),
'import_' . PullIntent::PULL_AUTOMATICALLY => $this
->t('Pull all'),
'import_' . PullIntent::PULL_MANUALLY => $this
->t('Pull manually'),
'import_' . PullIntent::PULL_AS_DEPENDENCY => $this
->t('Pull referenced'),
];
$pool_usage_labels = [
Pool::POOL_USAGE_FORCE => 'Force',
Pool::POOL_USAGE_ALLOW => 'Allow',
Pool::POOL_USAGE_FORBID => 'Forbid',
];
$pool_options = [];
foreach (Pool::getAll() as $id => $pool) {
$pool_options[Pool::POOL_USAGE_FORCE . '_' . $id] = $this
->t('Force pool @pool', [
'@pool' => $pool
->label(),
]);
$pool_options[Pool::POOL_USAGE_ALLOW . '_' . $id] = $this
->t('Allow pool @pool', [
'@pool' => $pool
->label(),
]);
$pool_options[Pool::POOL_USAGE_FORBID . '_' . $id] = $this
->t('Forbid pool @pool', [
'@pool' => $pool
->label(),
]);
}
if (in_array(true, $pushing)) {
$elements['export'] = [
'#markup' => '<br><br><h2>' . $this
->t('Change push to') . '</h2>',
];
foreach ($pushing as $type => $does) {
if (!$does) {
continue;
}
$id = 'export_' . $type;
$elements[$id] = [
'#type' => 'fieldset',
'#title' => $options[$id],
$id . '_becomes' => [
'#type' => 'select',
'#options' => $options,
'#required' => true,
'#title' => $this
->t('Becomes'),
'#default_value' => $id,
],
];
foreach ($push_to_pools[$type] as $pool => $pool_settings) {
foreach ($pool_settings as $setting => $used) {
$elements[$id][$id . '_pool_' . $setting . '_' . $pool] = [
'#type' => 'select',
'#options' => $pool_options,
'#required' => true,
'#title' => $this
->t('%action pool %pool becomes', [
'%pool' => $pool,
'%action' => $pool_usage_labels[$setting],
]),
'#default_value' => $setting . '_' . $pool,
];
}
}
}
}
if (in_array(true, $pulling)) {
$elements['import'] = [
'#markup' => '<br><br><h2>' . $this
->t('Change pull to') . '</h2>',
];
foreach ($pulling as $type => $does) {
if (!$does) {
continue;
}
$id = 'import_' . $type;
$elements[$id] = [
'#type' => 'fieldset',
'#title' => $options[$id],
$id . '_becomes' => [
'#type' => 'select',
'#options' => $options,
'#required' => true,
'#title' => $this
->t('Becomes'),
'#default_value' => $id,
],
];
foreach ($pull_pool_settings[$type] as $pool => $pool_settings) {
foreach ($pool_settings as $setting => $used) {
$elements[$id][$id . '_pool_' . $setting . '_' . $pool] = [
'#type' => 'select',
'#options' => $pool_options,
'#required' => true,
'#title' => $this
->t('%action pool %pool becomes', [
'%pool' => $pool,
'%action' => $pool_usage_labels[$setting],
]),
'#default_value' => $setting . '_' . $pool,
];
}
}
}
}
$elements['save'] = [
'#type' => 'submit',
'#value' => $this
->t('Save'),
'#submit' => [
'::save',
],
'#attributes' => [
'class' => [
'button--primary',
],
],
];
return $elements;
}