Our site uses the Address module (https://www.drupal.org/project/address).

Changes to addresses are not showing up in the Diff report.

How can we get this field type supported? Or am I doing something wrong?

Issue fork diff-3098867

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Cayenne created an issue. See original summary.

cayenne’s picture

WOW, can it have been as easy as this?

I wrote a quick plugin and it's working beautifully!

<?php

namespace Drupal\diff\Plugin\diff\Field;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\diff\DiffEntityParser;
use Drupal\diff\FieldDiffBuilderBase;
use Drupal\Core\Field\FieldItemListInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Plugin to diff address field types.
 *
 * @FieldDiffBuilder(
 *   id = "address_field_diff_builder",
 *   label = @Translation("Address Field Diff"),
 *   field_types = {"address"
 *   },
 * )
 */
class AddressFieldBuilder extends FieldDiffBuilderBase {

  /**
   * The renderer.
   *
   * @var \Drupal\Core\Render\RendererInterface
   */
  protected $renderer;

  /**
   * Constructs a CoreFieldBuilder object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config
   *   The configuration factory object.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\diff\DiffEntityParser $entity_parser
   *   The entity parser.
   * @param \Drupal\Core\Render\RendererInterface $renderer
   *   The renderer.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, DiffEntityParser $entity_parser, RendererInterface $renderer) {
    parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager, $entity_parser);
    $this->renderer = $renderer;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $container->get('entity_type.manager'),
      $container->get('diff.entity_parser'),
      $container->get('renderer')
    );
  }

  /**
   * {@inheritdoc}
   */
  public function build(FieldItemListInterface $field_items) {
    $result = array();
    // Every item from $field_items is of type FieldItemInterface.
    foreach ($field_items as $field_key => $field_item) { 
      if (!$field_item->isEmpty()) {
        $values = $field_item->getValue();
        $result[$field_key] = array(implode("\n",$values));
      }
    }
    return $result;
  }
}

hydra’s picture

Thx for sharing this, works perfectly if needed :)

sanket.addweb’s picture

Thanks @Cayenne, I have tested and created a patch for the revision differences in the address field.

sanket.addweb’s picture

Status: Active » Needs review
ikeigenwijs’s picture

.patch applies , but appears to be not exactly the same issue.

apache log after .patch

 PHP Fatal error:  Declaration of Drupal\\diff\\Plugin\\diff\\Field\\AddressFieldBuilder::build(Drupal\\Core\\Field\\FieldItemListInterface $field_items)
 must be compatible with Drupal\\diff\\FieldDiffBuilderInterface::build(Drupal\\Core\\Field\\FieldItemListInterface $field_items): 
 mixed in web/modules/contrib/diff/src/Plugin/diff/Field/AddressFieldBuilder.php on line 72, referer: /node/158564/revisions

acbramley’s picture

Version: 8.x-1.x-dev » 2.x-dev
Status: Needs review » Needs work

This needs a reroll and fixes as per #6 onto an MR against 2.x

acbramley’s picture

Status: Needs work » Closed (outdated)

The address module implements this itself https://git.drupalcode.org/project/address/-/blob/2.1.x/src/Plugin/diff/...

Note that there's currently a bug with it for Diff 2.x and the latest stable of address (2.0.4) https://www.drupal.org/project/address/issues/3460590#comment-16132112