Same name and namespace in other branches
- 9 core/modules/workspaces/src/Form/WorkspacePublishForm.php \Drupal\workspaces\Form\WorkspacePublishForm
Provides the workspace publishing form.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
- class \Drupal\workspaces\Form\WorkspacePublishForm implements ContainerInjectionInterface, WorkspaceSafeFormInterface
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
Expanded class hierarchy of WorkspacePublishForm
1 file declares its use of WorkspacePublishForm
- WorkspacePublishFormTest.php in core/
modules/ workspaces/ tests/ src/ Kernel/ WorkspacePublishFormTest.php
1 string reference to 'WorkspacePublishForm'
- workspaces.routing.yml in core/
modules/ workspaces/ workspaces.routing.yml - core/modules/workspaces/workspaces.routing.yml
File
- core/
modules/ workspaces/ src/ Form/ WorkspacePublishForm.php, line 19
Namespace
Drupal\workspaces\FormView source
class WorkspacePublishForm extends ConfirmFormBase implements ContainerInjectionInterface, WorkspaceSafeFormInterface {
/**
* The workspace that will be published.
*
* @var \Drupal\workspaces\WorkspaceInterface
*/
protected $workspace;
/**
* The workspace operation factory.
*
* @var \Drupal\workspaces\WorkspaceOperationFactory
*/
protected $workspaceOperationFactory;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a new WorkspacePublishForm.
*
* @param \Drupal\workspaces\WorkspaceOperationFactory $workspace_operation_factory
* The workspace operation factory service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(WorkspaceOperationFactory $workspace_operation_factory, EntityTypeManagerInterface $entity_type_manager) {
$this->workspaceOperationFactory = $workspace_operation_factory;
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('workspaces.operation_factory'), $container
->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'workspace_publish_form';
}
/**
* {@inheritdoc}
*/
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;
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this
->t('Would you like to publish the contents of the %label workspace?', [
'%label' => $this->workspace
->label(),
]);
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this
->t('Publish workspace contents.');
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return Url::fromRoute('entity.workspace.collection', [], [
'query' => $this
->getDestinationArray(),
]);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$workspace = $this->workspace;
try {
$workspace
->publish();
$this
->messenger()
->addMessage($this
->t('Successful publication.'));
} catch (WorkspaceAccessException $e) {
$this
->messenger()
->addMessage($e
->getMessage(), 'error');
} catch (\Exception $e) {
$this
->messenger()
->addMessage($this
->t('Publication failed. All errors have been logged.'), 'error');
$this
->getLogger('workspaces')
->error($e
->getMessage());
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfirmFormBase:: |
public | function |
Returns a caption for the link which cancels the action. Overrides ConfirmFormInterface:: |
2 |
ConfirmFormBase:: |
public | function |
Returns a caption for the button that confirms the action. Overrides ConfirmFormInterface:: |
21 |
ConfirmFormBase:: |
public | function |
Returns the internal name used to refer to the confirmation item. Overrides ConfirmFormInterface:: |
|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 2 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 2 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function | Returns a redirect response object for the specified route. | |
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
47 |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 8 |
MessengerTrait:: |
public | function | Gets the messenger. | 8 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 3 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 1 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
WorkspacePublishForm:: |
protected | property | The entity type manager. | |
WorkspacePublishForm:: |
protected | property | The workspace that will be published. | |
WorkspacePublishForm:: |
protected | property | The workspace operation factory. | |
WorkspacePublishForm:: |
public | function |
Form constructor. Overrides ConfirmFormBase:: |
|
WorkspacePublishForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
WorkspacePublishForm:: |
public | function |
Returns the route to go to if the user cancels the action. Overrides ConfirmFormInterface:: |
|
WorkspacePublishForm:: |
public | function |
Returns additional text to display as a description. Overrides ConfirmFormBase:: |
|
WorkspacePublishForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
WorkspacePublishForm:: |
public | function |
Returns the question to ask the user. Overrides ConfirmFormInterface:: |
|
WorkspacePublishForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
WorkspacePublishForm:: |
public | function | Constructs a new WorkspacePublishForm. |