<?php
namespace Drupal\custom_block;
use Drupal\Core\Entity\DatabaseStorageControllerNG;
use Drupal\Core\Entity\EntityInterface;
class CustomBlockStorageController extends DatabaseStorageControllerNG {
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->value;
}
}
protected function attachLoad(&$blocks, $load_revision = FALSE) {
foreach ($blocks as $id => $entity) {
$types[$entity->type] = $entity->type;
}
$this->hookLoadArguments = array(
$types,
);
parent::attachLoad($blocks, $load_revision);
}
protected function postSave(EntityInterface $block, $update) {
drupal_container()
->get('plugin.manager.block')
->clearCachedDefinitions();
}
public function baseFieldDefinitions() {
$properties['id'] = array(
'label' => t('ID'),
'description' => t('The custom block ID.'),
'type' => 'integer_field',
'read-only' => TRUE,
);
$properties['uuid'] = array(
'label' => t('UUID'),
'description' => t('The custom block UUID.'),
'type' => 'string_field',
);
$properties['revision_id'] = array(
'label' => t('Revision ID'),
'description' => t('The revision ID.'),
'type' => 'integer_field',
);
$properties['langcode'] = array(
'label' => t('Language code'),
'description' => t('The comment language code.'),
'type' => 'language_field',
);
$properties['info'] = array(
'label' => t('Subject'),
'description' => t('The custom block name.'),
'type' => 'string_field',
);
$properties['type'] = array(
'label' => t('Block type'),
'description' => t('The block type.'),
'type' => 'string_field',
);
$properties['log'] = array(
'label' => t('Revision log message'),
'description' => t('The revision log message.'),
'type' => 'string_field',
);
return $properties;
}
}