You are here

function ds_extras_form_ds_admin_form_alter in Display Suite 8.4

Same name and namespace in other branches
  1. 8.2 modules/ds_extras/ds_extras.module \ds_extras_form_ds_admin_form_alter()
  2. 8.3 modules/ds_extras/ds_extras.module \ds_extras_form_ds_admin_form_alter()

Implements hook_form_FORM_ID_alter().

File

modules/ds_extras/ds_extras.module, line 58
Display Suite extras main functions.

Code

function ds_extras_form_ds_admin_form_alter(&$form, FormStateInterface $form_state) {
  $config = \Drupal::configFactory()
    ->getEditable('ds_extras.settings');
  $form['fs2'] = [
    '#type' => 'details',
    '#title' => t('Extra fields'),
    '#group' => 'additional_settings',
    '#weight' => 2,
    '#tree' => TRUE,
  ];
  $form['fs2']['fields_extra'] = [
    '#type' => 'checkbox',
    '#title' => t('Enable extra fields'),
    '#description' => t('Make fields from other modules available on the "Manage display" screens.'),
    '#default_value' => $config
      ->get('fields_extra'),
  ];
  $form['fs2']['fields_extra_list'] = [
    '#type' => 'textarea',
    '#description' => t('Enter fields line by line, where each line is a combination of entity type, bundle and field name. E.g. node|article|tweetbutton. It might be possible that the actual content of the field depends on configuration of that field/module.'),
    '#default_value' => implode("\n", $config
      ->get('fields_extra_list')),
    '#states' => [
      'visible' => [
        'input[name="fs2[fields_extra]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['fs3']['field_permissions'] = [
    '#type' => 'checkbox',
    '#title' => t('Field permissions'),
    '#description' => t('Enables view permissions on all Display Suite fields.'),
    '#default_value' => $config
      ->get('field_permissions'),
  ];
  $form['fs3']['switch_field'] = [
    '#type' => 'checkbox',
    '#title' => t('View mode switcher'),
    '#description' => t('Adds a field with links to switch view modes inline with Ajax. Only works for nodes at this time. It does not work in combination with the reset layout.'),
    '#default_value' => $config
      ->get('switch_field'),
  ];
  $form['fs3']['hidden_region'] = [
    '#type' => 'checkbox',
    '#title' => t('Hidden region'),
    '#description' => t('Add a hidden region to the layouts. Fields will be built but not printed.'),
    '#default_value' => $config
      ->get('hidden_region'),
  ];
  $form['fs3']['override_node_revision'] = [
    '#type' => 'checkbox',
    '#title' => t('Custom node revision view mode'),
    '#description' => t('Override the node revision page view with a custom view mode'),
    '#default_value' => $config
      ->get('override_node_revision'),
  ];
  $options = [];
  $view_modes = \Drupal::service('entity_display.repository')
    ->getViewModes('node');
  foreach ($view_modes as $key => $view_mode) {
    $options[$key] = $view_mode['label'];
  }
  $form['fs3']['override_node_revision_view_mode'] = [
    '#type' => 'select',
    '#description' => t('The revision view mode'),
    '#default_value' => $config
      ->get('override_node_revision_view_mode'),
    '#options' => $options,
    '#states' => [
      'visible' => [
        'input[name="fs3[override_node_revision]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['#submit'][] = 'ds_extras_settings_submit';
  $form['#attached']['library'][] = 'ds_extras/admin';
}