You are here

public function ModerationSidebarSettingsForm::buildForm in Moderation Sidebar 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/ModerationSidebarSettingsForm.php, line 64

Class

ModerationSidebarSettingsForm
Configure Moderation Sidebar settings for this site.

Namespace

Drupal\moderation_sidebar\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('moderation_sidebar.settings');
  $workflows = $this->entityTypeManager
    ->getStorage('workflow')
    ->loadMultiple();
  foreach ($workflows as $key => $workflow) {
    $workflow_form_key = $key . '_workflow';
    $form[$workflow_form_key] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Disabled @workflow transitions', [
        '@workflow' => $workflow
          ->label(),
      ]),
      '#description' => $this
        ->t('Select transitions, which should be disabled in the Moderation Sidebar, when the @workflow workflow is in use.', [
        '@workflow' => $workflow
          ->label(),
      ]),
      '#open' => TRUE,
      '#tree' => TRUE,
      '#parents' => [
        'workflows',
        $workflow_form_key,
      ],
    ];

    // Create an array with transition ids and labels.
    $transitions = $workflow
      ->getTypePlugin()
      ->getTransitions();
    $transitions = array_map(function ($transition) {
      return $transition
        ->label();
    }, $transitions);
    $form[$workflow_form_key]['disabled_transitions'] = [
      '#type' => 'checkboxes',
      '#options' => $transitions,
      '#default_value' => $config
        ->get('workflows.' . $workflow_form_key . '.disabled_transitions') ?: [],
    ];
  }
  return parent::buildForm($form, $form_state);
}