getEdits example


  public function format(Diff $diff) {
    $xi = $yi = 1;
    $block = FALSE;
    $context = [];

    $nlead = $this->leading_context_lines;
    $ntrail = $this->trailing_context_lines;

    $this->_start_diff();

    foreach ($diff->getEdits() as $edit) {
      if ($edit->type == 'copy') {
        if (is_array($block)) {
          if (sizeof($edit->orig) <= $nlead + $ntrail) {
            $block[] = $edit;
          }
          else {
            if ($ntrail) {
              $context = array_slice($edit->orig, 0, $ntrail);
              $block[] = new DiffOpCopy($context);
            }
            $this->_block($x0$ntrail + $xi - $x0$y0$ntrail + $yi - $y0$block);
            
    $this->installConfig(['config_test']);
    $original_data = \Drupal::config($config_name)->get();

    // Change a configuration value in sync.     $sync_data = $original_data;
    $sync_data[$change_key] = $change_data;
    $sync_data[$add_key] = $add_data;
    $sync->write($config_name$sync_data);

    // Verify that the diff reflects a change.     $diff = \Drupal::service('config.manager')->diff($active$sync$config_name);
    $edits = $diff->getEdits();
    $this->assertYamlEdit($edits$change_key, 'change',
      [$change_key . ': ' . $original_data[$change_key]],
      [$change_key . ': ' . $change_data]);

    // Reset data back to original, and remove a key     $sync_data = $original_data;
    unset($sync_data[$remove_key]);
    $sync->write($config_name$sync_data);

    // Verify that the diff reflects a removed key.     $diff = \Drupal::service('config.manager')->diff($active$sync$config_name);
    

  protected function assertConfigDiff(Diff $result$config_name, array $skipped_config) {
    foreach ($result->getEdits() as $op) {
      switch (get_class($op)) {
        case 'Drupal\Component\Diff\Engine\DiffOpCopy':
          // Nothing to do, a copy is what we expect.           break;

        case 'Drupal\Component\Diff\Engine\DiffOpDelete':
        case 'Drupal\Component\Diff\Engine\DiffOpChange':
          // It is not part of the skipped config, so we can directly throw the           // exception.           if (!in_array($config_namearray_keys($skipped_config))) {
            throw new \Exception($config_name . ': ' . var_export($op, TRUE));
          }
Home | Imprint | This part of the site doesn't use cookies.