function WorkspaceMergeForm::buildForm
Same name in other branches
- 9 core/modules/workspaces/src/Form/WorkspaceMergeForm.php \Drupal\workspaces\Form\WorkspaceMergeForm::buildForm()
- 8.9.x core/modules/workspaces/src/Form/WorkspaceMergeForm.php \Drupal\workspaces\Form\WorkspaceMergeForm::buildForm()
- 10 core/modules/workspaces/src/Form/WorkspaceMergeForm.php \Drupal\workspaces\Form\WorkspaceMergeForm::buildForm()
Overrides ConfirmFormBase::buildForm
File
-
core/
modules/ workspaces/ src/ Form/ WorkspaceMergeForm.php, line 81
Class
- WorkspaceMergeForm
- Provides a form that merges the contents for a workspace into another one.
Namespace
Drupal\workspaces\FormCode
public function buildForm(array $form, FormStateInterface $form_state, ?WorkspaceInterface $source_workspace = NULL, ?WorkspaceInterface $target_workspace = NULL) {
$this->sourceWorkspace = $source_workspace;
$this->targetWorkspace = $target_workspace;
$form = parent::buildForm($form, $form_state);
$workspace_merger = $this->workspaceOperationFactory
->getMerger($this->sourceWorkspace, $this->targetWorkspace);
$args = [
'%source_label' => $this->sourceWorkspace
->label(),
'%target_label' => $this->targetWorkspace
->label(),
];
// List the changes that can be merged into the target.
if ($source_rev_diff = $workspace_merger->getDifferringRevisionIdsOnSource()) {
$total_count = $workspace_merger->getNumberOfChangesOnSource();
$form['merge'] = [
'#theme' => 'item_list',
'#title' => $this->formatPlural($total_count, 'There is @count item that can be merged from %source_label to %target_label', 'There are @count items that can be merged from %source_label to %target_label', $args),
'#items' => [],
'#total_count' => $total_count,
];
foreach ($source_rev_diff as $entity_type_id => $revision_difference) {
$form['merge']['#items'][$entity_type_id] = $this->entityTypeManager
->getDefinition($entity_type_id)
->getCountLabel(count($revision_difference));
}
}
// If there are no changes to merge, show an informational message.
if (!isset($form['merge'])) {
$form['description'] = [
'#markup' => $this->t('There are no changes that can be merged from %source_label to %target_label.', $args),
];
$form['actions']['submit']['#disabled'] = TRUE;
}
return $form;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.