pm-4.1.x-dev/modules/pm_project/pm_project.module
modules/pm_project/pm_project.module
<?php
/**
* @file
* Provides a pm project entity type.
*/
use Drupal\Core\Render\Element;
use Drupal\user\UserInterface;
/**
* Implements hook_theme().
*/
function pm_project_theme() {
return [
'pm_project' => [
'render element' => 'elements',
],
];
}
/**
* Prepares variables for pm project templates.
*
* Default template: pm-project.html.twig.
*
* @param array $variables
* An associative array containing:
* - elements: An associative array containing
* the pm project information and any
* fields attached to the entity.
* - attributes: HTML attributes for the containing element.
*/
function template_preprocess_pm_project(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_project_user_cancel($edit, UserInterface $account, $method) {
switch ($method) {
case 'user_cancel_reassign':
// Anonymize pm projects.
$storage = \Drupal::entityTypeManager()->getStorage('pm_project');
$pm_project_ids = $storage->getQuery()
->condition('uid', $account->id())
->accessCheck(FALSE)
->execute();
foreach ($storage->loadMultiple($pm_project_ids) as $pm_project) {
$pm_project->setOwnerId(0);
$pm_project->save();
}
break;
}
}
/**
* Implements hook_ENTITY_TYPE_predelete() for user entities.
*/
function pm_project_user_predelete(UserInterface $account) {
// Delete pm projects.
$storage = \Drupal::entityTypeManager()->getStorage('pm_project');
$pm_project_ids = $storage->getQuery()
->condition('uid', $account->id())
->accessCheck(FALSE)
->execute();
$pm_projects = $storage->loadMultiple($pm_project_ids);
$storage->delete($pm_projects);
}
