/**
   * Returns a form element for the given overrides.
   *
   * @param array $package
   *   A package array.
   * @param array $overrides
   *   An array of overrides.
   * @param array $missing
   *   An array of missing config.
   *
   * @return array
   *   A form element.
   */
  protected function diffOutput($package, $overrides, $missing = array()) {
    $element = array();
    $config = $this->featuresManager->getConfigCollection();
    $components = array_merge($missing, $overrides);

    $header = array(
      array('data' => '', 'class' => 'diff-marker'),
      array('data' => t('Active site config'), 'class' => 'diff-context'),
      array('data' => '', 'class' => 'diff-marker'),
      array('data' => t('Feature code config'), 'class' => 'diff-context'),
    );

    foreach ($components as $name) {
      $rows[] = array(array('data' => $name, 'colspan' => 4, 'header' => TRUE));

      if (!isset($config[$name])) {
        $details = array(
          '#markup' => t('Component in feature missing from active config.'),
        );
      }
      else {
        $active = $this->featuresManager->getActiveStorage()->read($name);
        $extension = $this->featuresManager->getExtensionStorage()->read($name);
        if (empty($extension)) {
          $details = array(
            '#markup' => t('Dependency detected in active config but not exported to the feature.'),
          );
        }
        else {
          $diff = $this->configDiff->diff($active, $extension);
          $details = array(
            '#type' => 'table',
            '#header' => $header,
            '#rows' => $this->diffFormatter->format($diff),
            '#attributes' => array('class' => array('diff', 'features-diff')),
          );
        }
      }
      $element[$name] = array(
        'row' => array(
          'data' => array(
            '#type' => 'details',
            '#title' => SafeMarkup::checkPlain($name),
            '#open' => TRUE,
            '#description' => array(
              'data' => $details,
            ),
          ),
        ),
        '#attributes' => array(
          'class' => 'diff-' . $package['machine_name'],
        ),
      );
    }

    return $element;
  }
 /**
  * Shows the diff between active and provided configuration.
  *
  * @param string $config_type
  *   The type of configuration.
  * @param string $config_name
  *   The name of the config item, without the prefix.
  *
  * @return array
  *   Render array for page showing differences between them.
  */
 public function diff($config_type, $config_name)
 {
     $diff = $this->configDiff->diff($this->configRevert->getFromExtension($config_type, $config_name), $this->configRevert->getFromActive($config_type, $config_name));
     $build = array();
     $definition = $this->configList->getType($config_type);
     $config_type_label = $definition ? $definition->getLabel() : $this->t('Simple configuration');
     $build['#title'] = $this->t('Config difference for @type @name', array('@type' => $config_type_label, '@name' => $config_name));
     $build['#attached']['library'][] = 'system/diff';
     $build['diff'] = array('#type' => 'table', '#header' => array(array('data' => $this->t('Source config'), 'colspan' => '2'), array('data' => $this->t('Site config'), 'colspan' => '2')), '#rows' => $this->diffFormatter->format($diff), '#attributes' => array('class' => array('diff')));
     $url = new Url('config_update_ui.report');
     $build['back'] = array('#type' => 'link', '#attributes' => array('class' => array('dialog-cancel')), '#title' => $this->t("Back to 'Updates report' page."), '#url' => $url);
     return $build;
 }
 /**
  * Shows diff of specified configuration file.
  *
  * @param string $source_name
  *   The name of the configuration file.
  * @param string $target_name
  *   (optional) The name of the target configuration file if different from
  *   the $source_name.
  * @param string $collection
  *   (optional) The configuration collection name. Defaults to the default
  *   collection.
  *
  * @return string
  *   Table showing a two-way diff between the active and staged configuration.
  */
 public function diff($source_name, $target_name = NULL, $collection = NULL)
 {
     if (!isset($collection)) {
         $collection = StorageInterface::DEFAULT_COLLECTION;
     }
     $diff = $this->configManager->diff($this->targetStorage, $this->sourceStorage, $source_name, $target_name, $collection);
     $this->diffFormatter->show_header = FALSE;
     $build = array();
     $build['#title'] = t('View changes of @config_file', array('@config_file' => $source_name));
     // Add the CSS for the inline diff.
     $build['#attached']['library'][] = 'system/diff';
     $build['diff'] = array('#type' => 'table', '#header' => array(array('data' => t('Active'), 'colspan' => '2'), array('data' => t('Staged'), 'colspan' => '2')), '#rows' => $this->diffFormatter->format($diff));
     $build['back'] = array('#type' => 'link', '#attributes' => array('class' => array('dialog-cancel')), '#title' => "Back to 'Synchronize configuration' page.", '#url' => Url::fromRoute('config.sync'));
     return $build;
 }
 /**
  * Shows diff of specified configuration file.
  *
  * @param string $source_name
  *   The name of the configuration file.
  * @param string $target_name
  *   (optional) The name of the target configuration file if different from
  *   the $source_name.
  * @param string $collection
  *   (optional) The configuration collection name. Defaults to the default
  *   collection.
  *
  * @return string
  *   Table showing a two-way diff between the active and staged configuration.
  */
 public function diff($source_name, $target_name = NULL, $collection = NULL)
 {
     if (!isset($collection)) {
         $collection = StorageInterface::DEFAULT_COLLECTION;
     }
     $diff = $this->configManager->diff($this->targetStorage, $this->sourceStorage, $source_name, $target_name, $collection);
     $this->diffFormatter->show_header = FALSE;
     $build = array();
     $build['#title'] = t('View changes of @config_file', array('@config_file' => $source_name));
     // Add the CSS for the inline diff.
     $build['#attached']['css'][] = drupal_get_path('module', 'system') . '/css/system.diff.css';
     $build['diff'] = array('#type' => 'table', '#header' => array(array('data' => t('Old'), 'colspan' => '2'), array('data' => t('New'), 'colspan' => '2')), '#rows' => $this->diffFormatter->format($diff));
     $build['back'] = array('#type' => 'link', '#attributes' => array('class' => array('dialog-cancel')), '#title' => "Back to 'Synchronize configuration' page.", '#href' => 'admin/config/development/configuration');
     return $build;
 }
Exemple #5
0
 /**
  * Builds the notification and diff for source changes for a data item.
  *
  * @param array $item_element
  *   The form element for the data item.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The form state.
  * @param string $field_name
  *   The name of the form element.
  * @param string $key
  *   The data item key for the given structure.
  * @param string $ajax_id
  *   The ID used for ajax replacements.
  *
  * @return array
  *   The form element for the data item.
  */
 protected function buildChangedSource($item_element, FormStateInterface $form_state, $field_name, $key, $ajax_id)
 {
     // Check for source changes and offer actions.
     if (isset($form_state->get('source_changed')[$key])) {
         // Show diff if requested.
         if ($form_state->get('show_diff:' . $key)) {
             $keys = \Drupal::service('tmgmt.data')->ensureArrayKey($field_name);
             try {
                 $new_data = \Drupal::service('tmgmt.data')->flatten($this->entity->getSourceData());
             } catch (TMGMTException $e) {
                 $new_data = [];
             }
             $current_data = $this->entity->getData($keys);
             $diff_header = ['', t('Current text'), '', t('New text')];
             $current_lines = explode("\n", $current_data['#text']);
             $new_lines = explode("\n", isset($new_data[$key]) ? $new_data[$key]['#text'] : '');
             $diff_formatter = new DiffFormatter($this->configFactory());
             $diff = new Diff($current_lines, $new_lines);
             $diff_rows = $diff_formatter->format($diff);
             // Unset start block.
             unset($diff_rows[0]);
             $item_element['below']['source_changed']['diff'] = ['#type' => 'table', '#header' => $diff_header, '#rows' => $diff_rows, '#empty' => $this->t('No visible changes'), '#attributes' => ['class' => ['diff']]];
             $item_element['below']['source_changed']['#attached']['library'][] = 'system/diff';
             $item_element['below_actions']['resolve-diff'] = ['#type' => 'submit', '#value' => t('Resolve'), '#attributes' => ['title' => t('Apply the changes of the source.')], '#name' => 'resolve-diff-' . $field_name, '#data_item_key' => $key, '#submit' => ['::resolveDiff'], '#ajax' => ['callback' => '::ajaxReviewForm', 'wrapper' => $ajax_id]];
         } else {
             $item_element['below']['source_changed'] = ['#type' => 'container', '#attributes' => ['class' => ['tmgmt_source_changed', 'messages', 'messages--warning']]];
             // Display changed message.
             $item_element['below']['source_changed']['message'] = ['#markup' => '<span>' . $form_state->get('source_changed')[$key] . '</span>', '#attributes' => ['class' => ['tmgmt-review-message-inline']]];
             if (!isset($form_state->get('source_removed')[$key])) {
                 // Offer diff action.
                 $item_element['below']['source_changed']['diff_button'] = ['#type' => 'submit', '#value' => t('Show change'), '#name' => 'diff-button-' . $field_name, '#data_item_key' => $key, '#submit' => ['::showDiff'], '#attributes' => ['class' => ['tmgmt-review-message-inline']], '#ajax' => ['callback' => '::ajaxReviewForm', 'wrapper' => $ajax_id]];
             }
         }
     }
     return $item_element;
 }