class NodeStorageController extends DatabaseStorageControllerNG {
public function create(array $values) {
if (empty($values['created'])) {
$values['created'] = REQUEST_TIME;
}
return parent::create($values)
->getBCEntity();
}
protected function attachLoad(&$queried_entities, $load_revision = FALSE) {
$nodes = $this
->mapFromStorageRecords($queried_entities, $load_revision);
$typed_nodes = array();
foreach ($nodes as $id => $node) {
$queried_entities[$id] = $node
->getBCEntity();
$typed_nodes[$node
->bundle()][$id] = $queried_entities[$id];
}
if ($load_revision) {
field_attach_load_revision($this->entityType, $queried_entities);
}
else {
field_attach_load($this->entityType, $queried_entities);
}
foreach ($typed_nodes as $node_type => $nodes_of_type) {
if ($function = node_hook($node_type, 'load')) {
$function($nodes_of_type);
}
}
$argument = array_keys($typed_nodes);
$this->hookLoadArguments = array(
$argument,
);
foreach (module_implements('entity_load') as $module) {
$function = $module . '_entity_load';
$function($queried_entities, $this->entityType);
}
$args = array_merge(array(
$queried_entities,
), $this->hookLoadArguments);
foreach (module_implements($this->entityType . '_load') as $module) {
call_user_func_array($module . '_' . $this->entityType . '_load', $args);
}
}
protected function invokeHook($hook, EntityInterface $node) {
$node = $node
->getBCEntity();
if ($hook == 'insert' || $hook == 'update') {
node_invoke($node, $hook);
}
else {
if ($hook == 'predelete') {
node_invoke($node, 'delete');
}
}
$function = 'field_attach_' . $hook;
if ($function == 'field_attach_revision_delete') {
$function = 'field_attach_delete_revision';
}
if (!empty($this->entityInfo['fieldable']) && function_exists($function)) {
$function($node);
}
module_invoke_all($this->entityType . '_' . $hook, $node);
module_invoke_all('entity_' . $hook, $node, $this->entityType);
}
protected function mapToDataStorageRecord(EntityInterface $entity, $langcode) {
$record = parent::mapToDataStorageRecord($entity, $langcode);
$record->comment = isset($record->comment) ? intval($record->comment) : 0;
return $record;
}
protected function preSave(EntityInterface $node) {
$node->changed->value = REQUEST_TIME;
}
protected function preSaveRevision(\stdClass $record, EntityInterface $entity) {
if ($entity
->isNewRevision()) {
if (!isset($record->log)) {
$record->log = '';
}
}
elseif (isset($entity->original) && (!isset($record->log) || $record->log === '')) {
$record->log = $entity->original->log;
}
}
public function postSave(EntityInterface $node, $update) {
if ($node
->isDefaultRevision()) {
node_access_acquire_grants($node
->getBCEntity(), $update);
}
}
public function preDelete($entities) {
if (module_exists('search')) {
foreach ($entities as $id => $entity) {
search_reindex($entity->nid->value, 'node');
}
}
}
protected function postDelete($nodes) {
$ids = array_keys($nodes);
db_delete('node_access')
->condition('nid', $ids, 'IN')
->execute();
}
public function baseFieldDefinitions() {
$properties['nid'] = array(
'label' => t('Node ID'),
'description' => t('The node ID.'),
'type' => 'integer_field',
'read-only' => TRUE,
);
$properties['uuid'] = array(
'label' => t('UUID'),
'description' => t('The node UUID.'),
'type' => 'string_field',
'read-only' => TRUE,
);
$properties['vid'] = array(
'label' => t('Revision ID'),
'description' => t('The node revision ID.'),
'type' => 'integer_field',
'read-only' => TRUE,
);
$properties['type'] = array(
'label' => t('Type'),
'description' => t('The node type.'),
'type' => 'string_field',
'read-only' => TRUE,
);
$properties['langcode'] = array(
'label' => t('Language code'),
'description' => t('The node language code.'),
'type' => 'language_field',
);
$properties['title'] = array(
'label' => t('Title'),
'description' => t('The title of this node, always treated as non-markup plain text.'),
'type' => 'string_field',
);
$properties['uid'] = array(
'label' => t('User ID'),
'description' => t('The user ID of the node author.'),
'type' => 'entity_reference_field',
'settings' => array(
'target_type' => 'user',
),
);
$properties['status'] = array(
'label' => t('Publishing status'),
'description' => t('A boolean indicating whether the node is published.'),
'type' => 'boolean_field',
);
$properties['created'] = array(
'label' => t('Created'),
'description' => t('The time that the node was created.'),
'type' => 'integer_field',
);
$properties['changed'] = array(
'label' => t('Changed'),
'description' => t('The time that the node was last edited.'),
'type' => 'integer_field',
);
$properties['comment'] = array(
'label' => t('Comment'),
'description' => t('Whether comments are allowed on this node: 0 = no, 1 = closed (read only), 2 = open (read/write).'),
'type' => 'integer_field',
);
$properties['promote'] = array(
'label' => t('Promote'),
'description' => t('A boolean indicating whether the node should be displayed on the front page.'),
'type' => 'boolean_field',
);
$properties['sticky'] = array(
'label' => t('Sticky'),
'description' => t('A boolean indicating whether the node should be displayed at the top of lists in which it appears.'),
'type' => 'boolean_field',
);
$properties['tnid'] = array(
'label' => t('Translation set ID'),
'description' => t('The translation set id for this node, which equals the node id of the source post in each set.'),
'type' => 'integer_field',
);
$properties['translate'] = array(
'label' => t('Translate'),
'description' => t('A boolean indicating whether this translation page needs to be updated.'),
'type' => 'boolean_field',
);
$properties['revision_timestamp'] = array(
'label' => t('Revision timestamp'),
'description' => t('The time that the current revision was created.'),
'type' => 'integer_field',
'queryable' => FALSE,
);
$properties['revision_uid'] = array(
'label' => t('Revision user ID'),
'description' => t('The user ID of the author of the current revision.'),
'type' => 'entity_reference_field',
'settings' => array(
'target_type' => 'user',
),
'queryable' => FALSE,
);
$properties['log'] = array(
'label' => t('Log'),
'description' => t('The log entry explaining the changes in this version.'),
'type' => 'string_field',
);
return $properties;
}
}