public function ChangeConnectionRole::execute in RedHen CRM 8
1 call to ChangeConnectionRole::execute()
- ChangeConnectionRole::executeMultiple in modules/
redhen_connection/ src/ Plugin/ Action/ ChangeConnectionRole.php
File
- modules/
redhen_connection/ src/ Plugin/ Action/ ChangeConnectionRole.php, line 137
Class
- ChangeConnectionRole
- Change the role of a Redhen Connection.
Namespace
Drupal\redhen_connection\Plugin\ActionCode
public function execute($connection = NULL) {
$role = $this->configuration['role'];
// Skip changing the role for the connection if already present,
// OR if the role is not available for the given connection.
$role_storage = \Drupal::service('entity_type.manager')
->getStorage('redhen_connection_role');
$roles = array_keys($role_storage
->loadByProperties([
'connection_type' => $connection
->getType(),
]));
if ($connection !== FALSE && $connection
->get('role')
->getString() != $role) {
if (in_array($role, $roles)) {
$connection->original = clone $connection;
$connection
->set('role', $role);
$connection
->save();
}
else {
// Increment mismatch value to indicate a role could not be applied.
$this->mismatch++;
}
}
}