You are here

public function ContentModerationConfigureEntityTypesForm::ajaxCallback in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/content_moderation/src/Form/ContentModerationConfigureEntityTypesForm.php \Drupal\content_moderation\Form\ContentModerationConfigureEntityTypesForm::ajaxCallback()

Ajax callback to close the modal and update the selected text.

Return value

\Drupal\Core\Ajax\AjaxResponse An ajax response object.

File

core/modules/content_moderation/src/Form/ContentModerationConfigureEntityTypesForm.php, line 199

Class

ContentModerationConfigureEntityTypesForm
The form for editing entity types associated with a workflow.

Namespace

Drupal\content_moderation\Form

Code

public function ajaxCallback() {
  $selected_bundles = [];
  foreach ($this->bundleInfo
    ->getBundleInfo($this->entityType
    ->id()) as $bundle_id => $bundle) {
    if ($this->workflow
      ->getTypePlugin()
      ->appliesToEntityTypeAndBundle($this->entityType
      ->id(), $bundle_id)) {
      $selected_bundles[$bundle_id] = $bundle['label'];
    }
  }
  $selected_bundles_list = [
    '#theme' => 'item_list',
    '#items' => $selected_bundles,
    '#context' => [
      'list_style' => 'comma-list',
    ],
    '#empty' => $this
      ->t('none'),
  ];
  $response = new AjaxResponse();
  $response
    ->addCommand(new CloseDialogCommand());
  $response
    ->addCommand(new HtmlCommand('#selected-' . $this->entityType
    ->id(), $selected_bundles_list));
  return $response;
}