You are here

protected function FeaturesDiffForm::diffOutput in Features 8.4

Same name and namespace in other branches
  1. 8.3 modules/features_ui/src/Form/FeaturesDiffForm.php \Drupal\features_ui\Form\FeaturesDiffForm::diffOutput()

Returns a form element for the given overrides.

Parameters

\Drupal\features\Package $package: A package.

array $overrides: An array of overrides.

array $missing: An array of missing config.

Return value

array A form element.

1 call to FeaturesDiffForm::diffOutput()
FeaturesDiffForm::buildForm in modules/features_ui/src/Form/FeaturesDiffForm.php
Form constructor.

File

modules/features_ui/src/Form/FeaturesDiffForm.php, line 218

Class

FeaturesDiffForm
Defines the features differences form.

Namespace

Drupal\features_ui\Form

Code

protected function diffOutput(Package $package, array $overrides, array $missing = []) {
  $element = [];
  $config = $this->featuresManager
    ->getConfigCollection();
  $components = array_merge($missing, $overrides);
  $header = [
    [
      'data' => '',
      'class' => 'diff-marker',
    ],
    [
      'data' => $this
        ->t('Active site config'),
      'class' => 'diff-context',
    ],
    [
      'data' => '',
      'class' => 'diff-marker',
    ],
    [
      'data' => $this
        ->t('Feature code config'),
      'class' => 'diff-context',
    ],
  ];
  foreach ($components as $name) {
    $rows[] = [
      [
        'data' => $name,
        'colspan' => 4,
        'header' => TRUE,
      ],
    ];
    if (!isset($config[$name])) {
      $details = [
        '#markup' => $this
          ->t('Component in feature missing from active config.'),
      ];
    }
    else {
      $active = $this->featuresManager
        ->getActiveStorage()
        ->read($name);
      $extension = $this->featuresManager
        ->getExtensionStorages()
        ->read($name);
      if (empty($extension)) {
        $details = [
          '#markup' => $this
            ->t('Dependency detected in active config but not exported to the feature.'),
        ];
      }
      else {
        $diff = $this->configDiff
          ->diff($active, $extension);
        $details = [
          '#type' => 'table',
          '#header' => $header,
          '#rows' => $this->diffFormatter
            ->format($diff),
          '#attributes' => [
            'class' => [
              'diff',
              'features-diff',
            ],
          ],
        ];
      }
    }
    $element[$name] = [
      'row' => [
        'data' => [
          '#type' => 'details',
          '#title' => Html::escape($name),
          '#open' => TRUE,
          '#description' => [
            'data' => $details,
          ],
        ],
      ],
      '#attributes' => [
        'class' => 'diff-' . $package
          ->getMachineName(),
      ],
    ];
  }
  return $element;
}