function redhen_connection_entity_update in RedHen CRM 8
Implements hook_entity_update().
File
- modules/
redhen_connection/ redhen_connection.module, line 126 - Contains redhen_connection.module..
Code
function redhen_connection_entity_update(EntityInterface $entity) {
// @todo replace with event dispatcher/subscribers.
// When updating contacts and orgs, check if they've been made inactive and
// set their associated connections to inactive.
if (in_array($entity
->getEntityTypeId(), [
'redhen_contact',
'redhen_org',
]) && \Drupal::config('redhen_connection.settings')
->get('auto_disable_connections') == TRUE) {
$original = $entity->original;
if (!$entity
->isActive() && $original
->isActive()) {
// Get active connections for this entity.
$connections = \Drupal::service('redhen_connection.connections')
->getConnections($entity, NULL, NULL, TRUE);
foreach ($connections as $connection) {
/** @var \Drupal\redhen_connection\ConnectionInterface $connection */
$connection
->setActive(FALSE);
$connection
->save();
}
}
}
}