<?php
function hook_entity_info(&$entity_info) {
$entity_info['node']['view_modes']['print'] = array(
'label' => t('Print'),
'custom_settings' => FALSE,
);
}
function hook_entity_info_alter(&$entity_info) {
$entity_info['node']['controller_class'] = 'Drupal\\mymodule\\MyCustomNodeStorageController';
}
function hook_entity_load($entities, $entity_type) {
foreach ($entities as $entity) {
$entity->foo = mymodule_add_something($entity);
}
}
function hook_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {
$entity->changed = REQUEST_TIME;
}
function hook_entity_insert(Drupal\Core\Entity\EntityInterface $entity) {
db_insert('example_entity')
->fields(array(
'type' => $entity
->entityType(),
'id' => $entity
->id(),
'created' => REQUEST_TIME,
'updated' => REQUEST_TIME,
))
->execute();
}
function hook_entity_update(Drupal\Core\Entity\EntityInterface $entity) {
db_update('example_entity')
->fields(array(
'updated' => REQUEST_TIME,
))
->condition('type', $entity
->entityType())
->condition('id', $entity
->id())
->execute();
}
function hook_entity_predelete(Drupal\Core\Entity\EntityInterface $entity) {
$id = $entity
->id();
$type = $entity
->entityType();
$count = db_select('example_entity_data')
->condition('type', $type)
->condition('id', $id)
->countQuery()
->execute()
->fetchField();
$ref_count_record = (object) array(
'count' => $count,
'type' => $type,
'id' => $id,
);
drupal_write_record('example_deleted_entity_statistics', $ref_count_record);
}
function hook_entity_delete(Drupal\Core\Entity\EntityInterface $entity) {
db_delete('example_entity')
->condition('type', $entity
->entityType())
->condition('id', $entity
->id())
->execute();
}
function hook_entity_query_alter(\Drupal\Core\Entity\Query\QueryInterface $query) {
}
function hook_entity_view(Drupal\Core\Entity\EntityInterface $entity, $view_mode, $langcode) {
$entity->content['my_additional_field'] = array(
'#markup' => $additional_field,
'#weight' => 10,
'#theme' => 'mymodule_my_additional_field',
);
}
function hook_entity_view_alter(&$build, Drupal\Core\Entity\EntityInterface $entity) {
if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) {
$build['an_additional_field']['#weight'] = -10;
$build['#post_render'][] = 'my_module_node_post_render';
}
}
function hook_entity_prepare_view($entities, $entity_type) {
if (!empty($entities) && $entity_type == 'user') {
$nodes = mymodule_get_user_nodes(array_keys($entities));
foreach ($entities as $uid => $entity) {
$entity->user_node = $nodes[$uid];
}
}
}
function hook_entity_view_mode_alter(&$view_mode, Drupal\Core\Entity\EntityInterface $entity, $context) {
if ($entity
->entityType() == 'node' && $view_mode == 'teaser') {
$view_mode = 'my_custom_view_mode';
}
}
function hook_entity_field_info($entity_type) {
if (mymodule_uses_entity_type($entity_type)) {
$info = array();
$info['definitions']['mymodule_text'] = array(
'type' => 'string_item',
'list' => TRUE,
'label' => t('The text'),
'description' => t('A text property added by mymodule.'),
'computed' => TRUE,
'class' => '\\Drupal\\mymodule\\EntityComputedText',
);
if ($entity_type == 'node') {
$info['optional']['mymodule_text_more'] = array(
'type' => 'string_item',
'list' => TRUE,
'label' => t('More text'),
'computed' => TRUE,
'class' => '\\Drupal\\mymodule\\EntityComputedMoreText',
);
$info['bundle map']['article'][0] = 'mymodule_text_more';
}
return $info;
}
}
function hook_entity_field_info_alter(&$info, $entity_type) {
if (!empty($info['definitions']['mymodule_text'])) {
$info['definitions']['mymodule_text']['class'] = '\\Drupal\\anothermodule\\EntityComputedText';
}
}