Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions contacts.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,9 @@ contact:
css:
theme:
css/contact.css: {}

# Styling for the dedup page
contacts_dedup_form:
css:
theme:
css/contacts.dedup.css: {}
9 changes: 9 additions & 0 deletions contacts.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,12 @@ contacts.manage.off_canvas_add:
type: entity:contact_tab
requirements:
_permission: 'manage contacts dashboard'

contacts.dedup:
path: '/admin/contacts/dedup'
defaults:
_form: '\Drupal\contacts\Form\DedupForm'
requirements:
_permission: 'manage contacts dashboard'
options:
theme: '' # Do not automatically apply the contacts theme (see DashboardNegotiator)
11 changes: 11 additions & 0 deletions css/contacts.dedup.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.contact-dedupe-match {
color: green;
}

.contact-dedupe-conflict {
color: red;
}

.contact-dedupe-link {
float: right;
}
111 changes: 111 additions & 0 deletions src/Event/GetPropertiesToShowOnDedupScreenEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php

namespace Drupal\contacts\Event;

use Drupal\Component\Utility\SortArray;
use Drupal\Core\Render\Element;
use Symfony\Component\EventDispatcher\Event;

/**
* Event raised to retrieve list of properties shown during merging.
*
* This event can be dispatched to retreive the properties that should be
* shown on the deduplication page.
*
* @package Drupal\contacts\Event
*/
class GetPropertiesToShowOnDedupScreenEvent extends Event {
const EVENT_NAME = 'contacts.dedup_property_info';


public $properties;

/**
* GetPropertiesToShowOnDedupScreenEvent constructor.
*/
public function __construct() {
$this->properties = [
NULL => [
'#weight' => -99,
'mail' => [
'render field' => TRUE,
'compare' => TRUE,
],
'profile_crm_indiv:entity:crm_gender' => [
'render field' => TRUE,
'compare' => TRUE,
],
],
];
}

/**
* Get a list of properties to show on the dedup verification page.
*
* @return array
* An array of properties to show in the comparison. Outer keys are group
* labels (NULL is no group). Keys are property strings (a chain of metadata
* wrapper properties separated by :). Values are arrays containing:
* - label: Optional string to override the normal label.
* - use label: Optionally attempt to use the EntityValueWrapper::label().
* - render field: If the property is a field, setting this to TRUE will
* render the property via the Field API.
* - compare: A boolean indicating whether to run a comparison or a callable
* for a custom comparison function (anonymous function recommended)
* - strip html: TRUE if HTML should be stripped from the basic comparison.
* Defaults to TRUE.
*/
public function getPropertiesByWeight() {
// Sort everything by weight.
$weight = 0;
$info = &$this->properties;

foreach ($this->properties as &$properties) {
// Set a default weight on the group.
$properties += ['#weight' => $weight++ / 100];

// Set up our defaults on the properties.
foreach (Element::children($properties) as $property) {
$properties[$property] += [
'#weight' => $weight++ / 100,
'use label' => FALSE,
'render field' => FALSE,
'compare' => TRUE,
'strip html' => TRUE,
];
}

// Sort the propreties.
uasort($properties, [SortArray::class, 'sortByWeightProperty']);

// Remove the weight.
foreach (Element::children($properties) as $property) {
unset($properties[$property]['#weight']);
}
}

// Sort the group.
uasort($info, [SortArray::class, 'sortByWeightProperty']);

// Remove group weights.
foreach ($info as &$properties) {
unset($properties['#weight']);
}

return $info;

}

/**
* Dispatches the event.
*
* @return static
*/
public static function dispatch() {
$dispatcher = \Drupal::service('event_dispatcher');
$event = new static();
$dispatcher->dispatch(GetPropertiesToShowOnDedupScreenEvent::EVENT_NAME, $event);
return $event;
}

}
Loading