You are here

function config_ignore_form_config_admin_import_form_alter in Config Ignore 8

Same name and namespace in other branches
  1. 8.2 config_ignore.module \config_ignore_form_config_admin_import_form_alter()

Implements hook_form_FORM_ID_alter().

File

./config_ignore.module, line 29
Hooks implemented by the config_ignore module.

Code

function config_ignore_form_config_admin_import_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  // Load the needed services.
  $storage_sync = \Drupal::service('config.storage.sync');
  $storage = \Drupal::service('config.storage');
  $config_manager = \Drupal::service('config.manager');
  $storage_compare = new StorageComparer($storage_sync, $storage, $config_manager);
  foreach ($storage_compare
    ->getAllCollectionNames() as $collection) {

    // Add a new header.
    $form[$collection]['update']['list']['#header'][] = t('Ignored');

    // Now check if the rows match any of the ignored entities.
    if (isset($form[$collection]['update']['list']['#rows']) && !empty($form[$collection]['update']['list']['#rows'])) {
      foreach ($form[$collection]['update']['list']['#rows'] as $key => $row) {
        if (ConfigImporterIgnore::matchConfigName($row['name'])) {
          $form[$collection]['update']['list']['#rows'][$key]['ignored'] = t('✔');
        }
        else {
          $form[$collection]['update']['list']['#rows'][$key]['ignored'] = t('✖');
        }
      }
    }
  }
}