Skip to content

Instantly share code, notes, and snippets.

@alex-bukach
Last active May 9, 2018 22:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alex-bukach/75c13b674ea1a22bae43788d51326265 to your computer and use it in GitHub Desktop.
Save alex-bukach/75c13b674ea1a22bae43788d51326265 to your computer and use it in GitHub Desktop.
diff --git a/core/modules/block_content/block_content.info.yml b/core/modules/block_content/block_content.info.yml
index b9ae564..0dd5b56 100644
--- a/core/modules/block_content/block_content.info.yml
+++ b/core/modules/block_content/block_content.info.yml
@@ -6,6 +6,7 @@ version: VERSION
core: 8.x
dependencies:
- block
+ - entity
- text
- user
configure: entity.block_content.collection
diff --git a/core/modules/block_content/block_content.install b/core/modules/block_content/block_content.install
index 4279cde..db404ba 100644
--- a/core/modules/block_content/block_content.install
+++ b/core/modules/block_content/block_content.install
@@ -61,3 +61,24 @@ function block_content_update_8003() {
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('revision_user', 'block_content', 'block_content', $revision_user);
}
+
+/**
+ * Add 'revision_log_message' field to 'block_content' entities.
+ */
+function block_content_update_8004() {
+ $revision_log_message = BaseFieldDefinition::create('string_long')
+ ->setLabel(t('Revision log message'))
+ ->setDescription(t('Briefly describe the changes you have made.'))
+ ->setRevisionable(TRUE)
+ ->setDefaultValue('')
+ ->setDisplayOptions('form', [
+ 'type' => 'string_textarea',
+ 'weight' => 25,
+ 'settings' => [
+ 'rows' => 4,
+ ],
+ ]);
+
+ \Drupal::entityDefinitionUpdateManager()
+ ->installFieldStorageDefinition('revision_log_message', 'block_content', 'block_content', $revision_log_message);
+}
diff --git a/core/modules/block_content/src/Entity/BlockContent.php b/core/modules/block_content/src/Entity/BlockContent.php
index 13af342..48f7be1 100644
--- a/core/modules/block_content/src/Entity/BlockContent.php
+++ b/core/modules/block_content/src/Entity/BlockContent.php
@@ -9,6 +9,8 @@ use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\block_content\BlockContentInterface;
use Drupal\user\UserInterface;
+use Drupal\entity\Revision\RevisionableContentEntityBase;
+
/**
* Defines the custom block entity class.
@@ -29,6 +31,9 @@ use Drupal\user\UserInterface;
* "delete" = "Drupal\block_content\Form\BlockContentDeleteForm",
* "default" = "Drupal\block_content\BlockContentForm"
* },
+ * "route_provider" = {
+ * "revision" = "\Drupal\entity\Routing\RevisionRouteProvider",
+ * },
* "translation" = "Drupal\block_content\BlockContentTranslationHandler"
* },
* admin_permission = "administer blocks",
@@ -40,6 +45,9 @@ use Drupal\user\UserInterface;
* "delete-form" = "/block/{block_content}/delete",
* "edit-form" = "/block/{block_content}",
* "collection" = "/admin/structure/block/block-content",
+ * "revision" = "/block/{block_content}/revisions/{block_content_revision}/view",
+ * "revision-revert-form" = "/block/{block_content}/revisions/{block_content_revision}/revert",
+ * "version-history" = "/block/{block_content}/revisions",
* },
* translatable = TRUE,
* entity_keys = {
@@ -50,6 +58,7 @@ use Drupal\user\UserInterface;
* "langcode" = "langcode",
* "uuid" = "uuid"
* },
+ *
* bundle_entity_type = "block_content_type",
* field_ui_base_route = "entity.block_content_type.edit_form",
* render_cache = FALSE,
@@ -60,7 +69,7 @@ use Drupal\user\UserInterface;
* caching.
* See https://www.drupal.org/node/2284917#comment-9132521 for more information.
*/
-class BlockContent extends ContentEntityBase implements BlockContentInterface {
+class BlockContent extends RevisionableContentEntityBase implements BlockContentInterface {
use EntityChangedTrait;
@@ -237,7 +246,8 @@ class BlockContent extends ContentEntityBase implements BlockContentInterface {
* {@inheritdoc}
*/
public function getRevisionCreationTime() {
- return $this->get('revision_created')->value;
+ $timestamp = $this->get('revision_created')->value;
+ return $timestamp ?: 0;
}
/**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment