You are here

function node_revisions_autoclean_alter_type_form in Node Revisions Autoclean 8

Alters form node type.

Parameters

array $form: Form.

2 calls to node_revisions_autoclean_alter_type_form()
node_revisions_autoclean_form_node_type_add_form_alter in ./node_revisions_autoclean.module
Implements hook_form_FORM_ID_alter().
node_revisions_autoclean_form_node_type_edit_form_alter in ./node_revisions_autoclean.module
Implements hook_form_FORM_ID_alter().

File

./node_revisions_autoclean.module, line 66
Contains node_revisions_autoclean.module.

Code

function node_revisions_autoclean_alter_type_form(array &$form) {
  $config = \Drupal::config('node_revisions_autoclean.settings');
  $machine_name = isset($form['type']['#default_value']) ? $form['type']['#default_value'] : '';
  $form['node_revisions_autoclean'] = [
    '#type' => 'details',
    '#title' => t('Node revisions autoclean'),
    '#group' => 'additional_settings',
    'node__nra' => [
      '#type' => 'number',
      '#title' => t('Revisions limit'),
      '#description' => t('Max revisions, "-1" means unlimited number of revisions, "0" keeps only the last.'),
      '#default_value' => $config
        ->get("node.{$machine_name}") ? $config
        ->get("node.{$machine_name}") : -1,
      '#required' => TRUE,
    ],
    'node__enable_date_nra' => [
      '#type' => 'checkbox',
      '#title' => t("Keep latest revisions based on date"),
      '#return_value' => 1,
      '#default_value' => $config
        ->get("interval.{$machine_name}") ? 1 : 0,
    ],
    'interval__nra' => [
      '#type' => 'select',
      '#title' => t("Keep latests revisions"),
      '#states' => [
        'visible' => [
          ':input[name="node__enable_date_nra"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
      '#options' => [
        '0' => t('Choose value'),
        'P1W' => t('1 week'),
        'P2W' => t('2 weeks'),
        'P3W' => t('3 weeks'),
        'P1M' => t('1 month'),
        'P2M' => t('2 months'),
        'P3M' => t('3 months'),
        'P4M' => t('4 months'),
        'P5M' => t('5 months'),
        'P6M' => t('6 months'),
        'P1Y' => t('1 year'),
      ],
      '#default_value' => $config
        ->get("interval.{$machine_name}") ? $config
        ->get("interval.{$machine_name}") : 0,
    ],
  ];
  $form['actions']['submit']['#submit'][] = 'node_revisions_autoclean_form_node_type_edit_form_submit';
  if (isset($form['actions']['save_continue'])) {
    $form['actions']['save_continue']['#submit'][] = 'node_revisions_autoclean_form_node_type_edit_form_submit';
  }
}