class NameFieldHandler in CRM Core 8
Same name and namespace in other branches
- 8.3 modules/crm_core_match/src/Plugin/crm_core_match/field/NameFieldHandler.php \Drupal\crm_core_match\Plugin\crm_core_match\field\NameFieldHandler
- 8.2 modules/crm_core_match/src/Plugin/crm_core_match/field/NameFieldHandler.php \Drupal\crm_core_match\Plugin\crm_core_match\field\NameFieldHandler
Class for evaluating name fields.
@CrmCoreMatchFieldHandler ( id = "name" )
Hierarchy
- class \Drupal\crm_core_match\Plugin\crm_core_match\field\FieldHandlerBase implements ContainerFactoryPluginInterface, FieldHandlerInterface
- class \Drupal\crm_core_match\Plugin\crm_core_match\field\NameFieldHandler
Expanded class hierarchy of NameFieldHandler
File
- modules/
crm_core_match/ src/ Plugin/ crm_core_match/ field/ NameFieldHandler.php, line 14
Namespace
Drupal\crm_core_match\Plugin\crm_core_match\fieldView source
class NameFieldHandler extends FieldHandlerBase {
protected $configuration = [
'title' => [
'score' => 3,
],
'given' => [
'score' => 10,
],
'middle' => [
'score' => 1,
],
'family' => [
'score' => 10,
],
'generational' => [
'score' => 1,
],
'credentials' => [
'score' => 1,
],
];
/**
* {@inheritdoc}
*/
public function getPropertyNames() {
return [
'title',
'given',
'middle',
'family',
'generational',
'credentials',
];
}
/**
* {@inheritdoc}
*/
public function getOperators($property = 'value') {
return [
'CONTAINS' => t('Contains'),
];
}
/**
* {@inheritdoc}
*/
public function match(ContactInterface $contact, $property = 'family') {
$field_name = $this->field
->getName();
$valid_parts = [];
if ($contact
->get($field_name)->{$property}) {
$valid_parts[$property] = $contact
->get($field_name)->{$property};
}
// Get the matches.
$matches = [];
foreach ($valid_parts as $property => $value) {
$query = $this->entityTypeManager
->getStorage('crm_core_individual')
->getQuery();
$query
->condition('type', $contact
->bundle());
if ($contact
->id()) {
$query
->condition('individual_id', $contact
->id(), '<>');
}
$query
->condition($field_name . '.' . $property, $value, 'CONTAINS');
$ids = $query
->execute();
foreach ($ids as $id) {
$matches[$id] = $this
->getScore($property);
}
}
arsort($matches);
$result = [];
foreach ($matches as $id => $score) {
$result[$id] = [
$this->field
->getName() . '.' . $property => $score,
];
}
return $result;
}
}