public function ReplicationActionForm::buildForm in Deploy - Content Staging 8
Implements buildForm().
.
Overrides FormInterface::buildForm
File
- src/
Form/ ReplicationActionForm.php, line 90
Class
- ReplicationActionForm
- ReplicationActionForm class.
Namespace
Drupal\deploy\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$entity = $this
->getEntity($form_state);
$form['#weight'] = 9999;
$form['replication_id'] = [
'#type' => 'hidden',
'#value' => $entity
->id(),
];
// Allow the user to not abort on conflicts.
if ($default_source = $this
->getDefaultSource($form_state)) {
$source_workspace = $default_source
->getWorkspace();
}
if ($default_target = $this
->getDefaultTarget($form_state)) {
$target_workspace = $default_target
->getWorkspace();
}
$conflicts = $this->conflictTracker
->useWorkspace($source_workspace)
->getAll();
if ($conflicts) {
$form['message'] = $this
->generateMessageRenderArray('error', $this
->t('There are <a href=":link">@count conflict(s) with the :target workspace</a>. Pushing changes to :target may result in unexpected behavior or data loss, and cannot be undone. Please proceed with caution.', [
'@count' => count($conflicts),
':link' => Url::fromRoute('entity.workspace.conflicts', [
'workspace' => $source_workspace
->id(),
])
->toString(),
':target' => $this
->getDefaultTarget($form_state)
->label(),
]));
$form['is_aborted_on_conflict'] = [
'#type' => 'radios',
'#title' => $this
->t('Abort if there are conflicts?'),
'#default_value' => 'true',
'#options' => [
'true' => $this
->t('Yes, if conflicts are found do not replicate to upstream.'),
'false' => $this
->t('No, go ahead and push any conflicts to the upstream.'),
],
'#weight' => 0,
];
}
else {
$form['message'] = $this
->generateMessageRenderArray('status', 'There are no conflicts.');
}
if ($source_workspace && !$source_workspace
->isPublished() && $target_workspace && !$target_workspace
->isPublished()) {
$message = $this
->t('This deployment cannot be re-deployed because both source workspace (%source) and target workspace (%target) have been archived.', [
'%source' => $source_workspace
->label(),
'%target' => $target_workspace
->label(),
]);
}
elseif (!$default_source || $source_workspace && !$source_workspace
->isPublished()) {
$message = $this
->t('This deployment cannot be re-deployed because the source workspace %source has been archived.', [
'%source' => $source_workspace ? '(' . $source_workspace
->label() . ')' : '',
]);
}
elseif (!$default_target || $target_workspace && !$target_workspace
->isPublished()) {
$message = $this
->t('This deployment cannot be re-deployed because the target workspace %target has been archived.', [
'%target' => $target_workspace ? '(' . $target_workspace
->label() . ')' : '',
]);
}
elseif ($entity
->getArchiveSource()) {
$message = $this
->t('This deployment cannot be re-deployed because the source workspace %source has been marked to be archived.', [
'%source' => $source_workspace ? '(' . $source_workspace
->label() . ')' : '',
]);
}
if (isset($message)) {
$form['message'] = $this
->generateMessageRenderArray('warning', $message);
}
else {
$form['submit'] = [
'#type' => 'submit',
'#value' => $entity
->get('replicated')->value ? $this
->t('Re-deploy') : $this
->t('Deploy'),
];
}
return $form;
}