3ba5f659359a9ae945cf1ab114d9ef78b61754f3
[yaffs-website] / web / core / modules / content_moderation / src / Form / ContentModerationStateForm.php
1 <?php
2
3 namespace Drupal\content_moderation\Form;
4
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\workflows\Plugin\WorkflowTypeStateFormBase;
7 use Drupal\workflows\StateInterface;
8
9 /**
10  * The content moderation state form.
11  *
12  * @see \Drupal\content_moderation\Plugin\WorkflowType\ContentModeration
13  */
14 class ContentModerationStateForm extends WorkflowTypeStateFormBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   public function buildConfigurationForm(array $form, FormStateInterface $form_state, StateInterface $state = NULL) {
20     /** @var \Drupal\content_moderation\ContentModerationState $state */
21     $state = $form_state->get('state');
22     $is_required_state = isset($state) ? in_array($state->id(), $this->workflowType->getRequiredStates(), TRUE) : FALSE;
23
24     $form = [];
25     $form['published'] = [
26       '#type' => 'checkbox',
27       '#title' => $this->t('Published'),
28       '#description' => $this->t('When content reaches this state it should be published.'),
29       '#default_value' => isset($state) ? $state->isPublishedState() : FALSE,
30       '#disabled' => $is_required_state,
31     ];
32
33     $form['default_revision'] = [
34       '#type' => 'checkbox',
35       '#title' => $this->t('Default revision'),
36       '#description' => $this->t('When content reaches this state it should be made the default revision; this is implied for published states.'),
37       '#default_value' => isset($state) ? $state->isDefaultRevisionState() : FALSE,
38       '#disabled' => $is_required_state,
39       // @todo Add form #state to force "make default" on when "published" is
40       // on for a state.
41       // @see https://www.drupal.org/node/2645614
42     ];
43     return $form;
44   }
45
46 }