You are here

function better_revisions_form_alter in Better Revisions 8

Same name and namespace in other branches
  1. 7 better_revisions.module \better_revisions_form_alter()

Implements hook_form_alter().

File

./better_revisions.module, line 36
Main enhanced revisions module file.

Code

function better_revisions_form_alter(&$form, &$form_state, $form_id) {
  if (isset($form['revision_log'])) {
    $config = \Drupal::config('better_revisions.settings');
    $req = $config
      ->get('br_require');
    $condition = [
      ':input[name="revision"]' => [
        'checked' => TRUE,
      ],
    ];
    $form['revision_log']['#title'] = $config
      ->get('br_list_title');
    if ($desc = $config
      ->get('br_list_help')) {
      $form['revision_log']['#description'] = $desc;
    }
    $form['revision_log']['#type'] = 'select';
    $form['revision_log']['#options'] = _better_revisions_options();
    $form['revision_log']['#group'] = 'revision_information';
    unset($form['revision_log']['#rows']);
    $form['revision_log']['#weight'] = 1;
    $form['revision_information']['revision_log'] = $form['revision_log'];
    unset($form['revision_log']);
    $area = $config
      ->get('br_add_txt');
    if ($area != 0) {
      $form['revision_log_extra'] = [
        '#type' => 'textarea',
        '#default_value' => '',
        '#title' => $config
          ->get('br_area_title'),
        '#states' => [
          'visible' => $condition,
        ],
        '#weight' => 2,
        '#group' => 'revision_information',
      ];
    }
    $actions = [
      'submit',
      'publish',
      'unpublish',
    ];
    foreach ($actions as $action) {
      @array_unshift($form['actions'][$action]['#submit'], 'better_revisions_log_combine');
    }
    if ($req || $area == 2) {
      $form['#validate'][] = '_better_revisions_validate';
    }
  }
}