pm-4.1.x-dev/modules/pm_organization/pm_organization.module
modules/pm_organization/pm_organization.module
<?php
/**
* @file
* Provides a pm organization entity type.
*/
use Drupal\Core\Render\Element;
use Drupal\user\UserInterface;
/**
* Implements hook_theme().
*/
function pm_organization_theme() {
return [
'pm_organization' => [
'render element' => 'elements',
],
];
}
/**
* Prepares variables for pm organization templates.
*
* Default template: pm-organization.html.twig.
*
* @param array $variables
* An associative array containing:
* - elements: An associative array containing
* the pm organization information and any
* fields attached to the entity.
* - attributes: HTML attributes for the containing element.
*/
function template_preprocess_pm_organization(array &$variables) {
$variables['view_mode'] = $variables['elements']['#view_mode'];
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
}
/**
* Implements hook_user_cancel().
*/
function pm_organization_user_cancel($edit, UserInterface $account, $method) {
switch ($method) {
case 'user_cancel_reassign':
// Anonymize pm organizations.
$storage = \Drupal::entityTypeManager()->getStorage('pm_organization');
$pm_organization_ids = $storage->getQuery()
->condition('uid', $account->id())
->accessCheck(FALSE)
->execute();
foreach ($storage->loadMultiple($pm_organization_ids) as $pm_organization) {
$pm_organization->setOwnerId(0);
$pm_organization->save();
}
break;
}
}
/**
* Implements hook_ENTITY_TYPE_predelete() for user entities.
*/
function pm_organization_user_predelete(UserInterface $account) {
// Delete pm organizations.
$storage = \Drupal::entityTypeManager()->getStorage('pm_organization');
$pm_organization_ids = $storage->getQuery()
->condition('uid', $account->id())
->accessCheck(FALSE)
->execute();
$pm_organizations = $storage->loadMultiple($pm_organization_ids);
$storage->delete($pm_organizations);
}
