public function JoinIntoHouseholdAction::executeMultiple in CRM Core 8
Same name and namespace in other branches
- 8.3 modules/crm_core_contact/src/Plugin/Action/JoinIntoHouseholdAction.php \Drupal\crm_core_contact\Plugin\Action\JoinIntoHouseholdAction::executeMultiple()
- 8.2 modules/crm_core_contact/src/Plugin/Action/JoinIntoHouseholdAction.php \Drupal\crm_core_contact\Plugin\Action\JoinIntoHouseholdAction::executeMultiple()
Executes the plugin for an array of objects.
Parameters
array $objects: An array of entities.
Overrides ActionBase::executeMultiple
1 call to JoinIntoHouseholdAction::executeMultiple()
- JoinIntoHouseholdAction::execute in modules/
crm_core_contact/ src/ Plugin/ Action/ JoinIntoHouseholdAction.php - Executes the plugin.
File
- modules/
crm_core_contact/ src/ Plugin/ Action/ JoinIntoHouseholdAction.php, line 86
Class
- JoinIntoHouseholdAction
- Merges 2 or more contacts into household contact.
Namespace
Drupal\crm_core_contact\Plugin\ActionCode
public function executeMultiple(array $objects) {
if (!isset($this->configuration['household'])) {
$this->configuration['household'] = Contact::create([
'type' => 'household',
]);
}
// Saving household only now because user can click "Cancel" on confirmation
// page(if he/she will notice that selected wrong contacts).
$this->configuration['household']
->setOwnerId($this->currentUser
->id());
$this->configuration['household']
->save();
foreach ($objects as $member) {
$endpoints = [
0 => [
'entity_type' => $member
->getEntityTypeId(),
'entity_id' => $member
->id(),
],
1 => [
'entity_type' => 'crm_core_contact',
'entity_id' => $this->configuration['household']
->id(),
],
];
$relation = Relation::create([
'relation_type' => self::RELATION_TYPE_HOUSEHOLD,
'endpoints' => $endpoints,
]);
$relation
->save();
}
}