function WorkspacePublishForm::buildForm

Same name and namespace in other branches
  1. 9 core/modules/workspaces/src/Form/WorkspacePublishForm.php \Drupal\workspaces\Form\WorkspacePublishForm::buildForm()
  2. 10 core/modules/workspaces/src/Form/WorkspacePublishForm.php \Drupal\workspaces\Form\WorkspacePublishForm::buildForm()

Overrides ConfirmFormBase::buildForm

File

core/modules/workspaces/src/Form/WorkspacePublishForm.php, line 75

Class

WorkspacePublishForm
Provides the workspace publishing form.

Namespace

Drupal\workspaces\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, ?WorkspaceInterface $workspace = NULL) {
    $this->workspace = $workspace;
    $form = parent::buildForm($form, $form_state);
    $workspace_publisher = $this->workspaceOperationFactory
        ->getPublisher($this->workspace);
    $args = [
        '%source_label' => $this->workspace
            ->label(),
        '%target_label' => $workspace_publisher->getTargetLabel(),
    ];
    $form['#title'] = $this->t('Publish %source_label workspace', $args);
    // List the changes that can be pushed.
    if ($source_rev_diff = $workspace_publisher->getDifferringRevisionIdsOnSource()) {
        $total_count = $workspace_publisher->getNumberOfChangesOnSource();
        $form['description'] = [
            '#theme' => 'item_list',
            '#title' => $this->formatPlural($total_count, 'There is @count item that can be published from %source_label to %target_label', 'There are @count items that can be published from %source_label to %target_label', $args),
            '#items' => [],
            '#total_count' => $total_count,
        ];
        foreach ($source_rev_diff as $entity_type_id => $revision_difference) {
            $form['description']['#items'][$entity_type_id] = $this->entityTypeManager
                ->getDefinition($entity_type_id)
                ->getCountLabel(count($revision_difference));
        }
        $form['actions']['submit']['#value'] = $this->formatPlural($total_count, 'Publish @count item to @target', 'Publish @count items to @target', [
            '@target' => $workspace_publisher->getTargetLabel(),
        ]);
    }
    else {
        // If there are no changes to push or pull, show an informational message.
        $form['help'] = [
            '#markup' => $this->t('There are no changes that can be published from %source_label to %target_label.', $args),
        ];
        // Do not allow the 'Publish' operation if there's nothing to publish.
        $form['actions']['submit']['#value'] = $this->t('Publish');
        $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.