abstract class FieldHandlerBase in CRM Core 8.2
Same name and namespace in other branches
- 8.3 modules/crm_core_match/src/Plugin/crm_core_match/field/FieldHandlerBase.php \Drupal\crm_core_match\Plugin\crm_core_match\field\FieldHandlerBase
- 8 modules/crm_core_match/src/Plugin/crm_core_match/field/FieldHandlerBase.php \Drupal\crm_core_match\Plugin\crm_core_match\field\FieldHandlerBase
Class FieldHandlerBase.
@package Drupal\crm_core_match\Plugin\crm_core_match\field
Hierarchy
- class \Drupal\crm_core_match\Plugin\crm_core_match\field\FieldHandlerBase implements ContainerFactoryPluginInterface, FieldHandlerInterface
Expanded class hierarchy of FieldHandlerBase
File
- modules/
crm_core_match/ src/ Plugin/ crm_core_match/ field/ FieldHandlerBase.php, line 17
Namespace
Drupal\crm_core_match\Plugin\crm_core_match\fieldView source
abstract class FieldHandlerBase implements FieldHandlerInterface, ContainerFactoryPluginInterface {
/**
* The weight.
*
* @var integer
*/
const WEIGHT_DELTA = 25;
/**
* The plugin id.
*
* @var string
*/
protected $id;
/**
* The plugin definition.
*
* @var array
*/
protected $definition;
/**
* The settings.
*
* @var array
*/
protected $configuration;
/**
* The field.
*
* @var \Drupal\Core\Field\FieldDefinitionInterface
*/
protected $field;
/**
* A Contact query object.
*
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
protected $queryFactory;
/**
* Constructs an plugin instance.
*/
public function __construct(FieldDefinitionInterface $field, QueryFactory $query_factory, array $configuration, $id, $definition) {
$this->configuration = $configuration;
$this->definition = $definition;
$this->id = $id;
$this->field = $field;
$this->queryFactory = $query_factory;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$field = $configuration['field'];
unset($configuration['field']);
return new static($field, $container
->get('entity.query'), $configuration, $plugin_id, $plugin_definition);
}
/**
* {@inheritdoc}
*/
public function getPropertyNames() {
return array(
'value',
);
}
/**
* {@inheritdoc}
*/
public function getLabel($property = 'value') {
return $this->field
->getLabel();
}
/**
* {@inheritdoc}
*/
public function getStatus($property = 'value') {
return isset($this->configuration[$property]['status']) ? $this->configuration[$property]['status'] : FALSE;
}
/**
* {@inheritdoc}
*/
public function getType() {
return $this->field
->getType();
}
/**
* {@inheritdoc}
*/
public function getOperator($property = 'value') {
return isset($this->configuration[$property]['operator']) ? $this->configuration[$property]['operator'] : NULL;
}
/**
* {@inheritdoc}
*/
public function getOptions($property = 'value') {
return isset($this->configuration[$property]['options']) ? $this->configuration[$property]['options'] : '';
}
/**
* {@inheritdoc}
*/
public function getScore($property = 'value') {
return isset($this->configuration[$property]['score']) ? $this->configuration[$property]['score'] : 0;
}
/**
* {@inheritdoc}
*/
public function getWeight($property = 'value') {
return isset($this->configuration[$property]['weight']) ? $this->configuration[$property]['weight'] : 0;
}
/**
* {@inheritdoc}
*/
public function match(ContactInterface $contact, $property = 'value') {
$ids = array();
$field = $this->field
->getName();
$needle = $contact
->get($field)->{$property};
$query = $this->queryFactory
->get('crm_core_individual', 'AND');
if (!empty($needle)) {
$query
->condition('type', $contact
->bundle());
if ($contact
->id()) {
$query
->condition('individual_id', $contact
->id(), '<>');
}
if ($field instanceof FieldConfigInterface) {
$field .= '.' . $property;
}
$query
->condition($field, $needle, $this
->getOperator($property));
$ids = $query
->execute();
}
// Get the score for this field/propery.
$score = array(
$this->field
->getName() . '.' . $property => $this
->getScore($property),
);
// Returning an array holding the score as value and the contact id as key.
return array_fill_keys($ids, $score);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FieldHandlerBase:: |
protected | property | The settings. | 1 |
FieldHandlerBase:: |
protected | property | The plugin definition. | |
FieldHandlerBase:: |
protected | property | The field. | |
FieldHandlerBase:: |
protected | property | The plugin id. | |
FieldHandlerBase:: |
protected | property | A Contact query object. | |
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 |
Returns the names of the field's subproperties. Overrides FieldHandlerInterface:: |
1 |
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:: |
public | function |
Executes the match query. Overrides FieldHandlerInterface:: |
2 |
FieldHandlerBase:: |
constant | The weight. | ||
FieldHandlerBase:: |
public | function | Constructs an plugin instance. | |
FieldHandlerInterface:: |
public | function | Gets the operators. | 7 |