public function WorkspaceDeployForm::form in Drupal 8
Gets the actual form array to be built.
Overrides ContentEntityForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- core/
modules/ workspaces/ src/ Form/ WorkspaceDeployForm.php, line 77
Class
- WorkspaceDeployForm
- Provides the workspace deploy form.
Namespace
Drupal\workspaces\FormCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$workspace_publisher = $this->workspaceOperationFactory
->getPublisher($this->entity);
$args = [
'%source_label' => $this->entity
->label(),
'%target_label' => $workspace_publisher
->getTargetLabel(),
];
$form['#title'] = $this
->t('Deploy %source_label workspace', $args);
// List the changes that can be pushed.
if ($source_rev_diff = $workspace_publisher
->getDifferringRevisionIdsOnSource()) {
$total_count = $workspace_publisher
->getNumberOfChangesOnSource();
$form['deploy'] = [
'#theme' => 'item_list',
'#title' => $this
->formatPlural($total_count, 'There is @count item that can be deployed from %source_label to %target_label', 'There are @count items that can be deployed from %source_label to %target_label', $args),
'#items' => [],
'#total_count' => $total_count,
];
foreach ($source_rev_diff as $entity_type_id => $revision_difference) {
$form['deploy']['#items'][$entity_type_id] = $this->entityTypeManager
->getDefinition($entity_type_id)
->getCountLabel(count($revision_difference));
}
}
// If there are no changes to push or pull, show an informational message.
if (!isset($form['deploy']) && !isset($form['refresh'])) {
$form['help'] = [
'#markup' => $this
->t('There are no changes that can be deployed from %source_label to %target_label.', $args),
];
}
return $form;
}