class NameFieldHandler in CRM Core 8.3
Same name and namespace in other branches
- 8 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 uses StringTranslationTrait
Expanded class hierarchy of NameFieldHandler
File
- modules/
crm_core_match/ src/ Plugin/ crm_core_match/ field/ NameFieldHandler.php, line 15
Namespace
Drupal\crm_core_match\Plugin\crm_core_match\fieldView source
class NameFieldHandler extends FieldHandlerBase {
use StringTranslationTrait;
/**
* Configuration.
*
* @var array
*/
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' => $this
->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;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FieldHandlerBase:: |
protected | property | The plugin definition. | |
FieldHandlerBase:: |
protected | property | Entity type manager. | |
FieldHandlerBase:: |
protected | property | The field. | |
FieldHandlerBase:: |
protected | property | The plugin id. | |
FieldHandlerBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
FieldHandlerBase:: |
public | function |
Gets the property label. Overrides FieldHandlerInterface:: |
|
FieldHandlerBase:: |
public | function |
Gets the current selected operator. Overrides FieldHandlerInterface:: |
|
FieldHandlerBase:: |
public | function |
Gets the operator options. Overrides FieldHandlerInterface:: |
|
FieldHandlerBase:: |
public | function |
Gets the score. Overrides FieldHandlerInterface:: |
|
FieldHandlerBase:: |
public | function |
Gets the property status. Overrides FieldHandlerInterface:: |
|
FieldHandlerBase:: |
public | function |
Gets the field type. Overrides FieldHandlerInterface:: |
|
FieldHandlerBase:: |
public | function |
Gets the weight. Overrides FieldHandlerInterface:: |
|
FieldHandlerBase:: |
constant | The weight. | ||
FieldHandlerBase:: |
public | function | Constructs an plugin instance. | |
NameFieldHandler:: |
protected | property |
Configuration. Overrides FieldHandlerBase:: |
|
NameFieldHandler:: |
public | function |
Gets the operators. Overrides FieldHandlerInterface:: |
|
NameFieldHandler:: |
public | function |
Returns the names of the field's subproperties. Overrides FieldHandlerBase:: |
|
NameFieldHandler:: |
public | function |
Executes the match query. Overrides FieldHandlerBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |