You are here

function acquia_contenthub_moderation_form_workflow_edit_form_alter in Acquia Content Hub 8.2

Implements hook_form_FORM_ID_alter().

File

modules/acquia_contenthub_moderation/acquia_contenthub_moderation.module, line 13
Provides a way to select moderation state during imports from Content Hub.

Code

function acquia_contenthub_moderation_form_workflow_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $config_settings = \Drupal::configFactory()
    ->get('acquia_contenthub_moderation.settings');
  $states = $form['states_container']['states'];
  foreach ($states as $state => $value) {
    if (substr($state, 0, 1) === '#') {
      unset($states[$state]);
      continue;
    }
    $states[$state] = $states[$state]['state']['#markup'];
  }
  $workflow = $form['id']['#default_value'];
  $configured_import_state = $config_settings
    ->get("workflows.{$workflow}.moderation_state");
  $form['acquia_contenthub'] = [
    '#type' => 'details',
    '#title' => t("Acquia Content Hub: Import Moderation State"),
    '#open' => TRUE,
    '#collapsible' => 'FALSE',
  ];
  $form['acquia_contenthub']['import_moderation_state'] = [
    '#type' => 'select',
    '#title' => t('Import Moderation State'),
    '#options' => $states,
  ];
  if (!empty($configured_import_state)) {
    $form['acquia_contenthub']['import_moderation_state']['#default_value'] = $configured_import_state;
  }
  if (isset($form['actions']['submit'])) {
    $form['actions']['submit']['#submit'][] = 'acquia_contenthub_moderation_import_moderation_state_submit';
  }
}