diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index bb203bf..4fe7379 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -12,6 +12,7 @@ use Drupal\comment\CommentInterface; use Drupal\comment\Entity\CommentType; +use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\Core\Entity\Entity\EntityViewMode; @@ -136,6 +137,29 @@ function comment_entity_extra_field_info() { } /** + * Implements hook_entity_base_field_info_alter(). + */ +function comment_entity_base_field_info_alter(&$fields, EntityTypeInterface $entity_type) { + // Provide a better default value for the moderation state field if the + // content moderation is enabled for comments. + if (\Drupal::moduleHandler()->moduleExists('content_moderation') && \Drupal::service('content_moderation.moderation_information')->canModerateEntitiesOfEntityType($entity_type)) { + $fields['moderation_state']->setDefaultValueCallback('comment_get_default_moderation_state'); + } +} + +/** + * Default value callback for the 'moderation_state' base field definition. + * + * @return array + * An array of default values. + */ +function comment_get_default_moderation_state() { + $default_moderation_state = \Drupal::currentUser()->hasPermission('skip comment approval') ? 'published' : 'draft'; + + return [$default_moderation_state]; +} + +/** * Implements hook_theme(). */ function comment_theme() { diff --git a/core/modules/comment/src/Entity/Comment.php b/core/modules/comment/src/Entity/Comment.php index 3823363..dd8fd66 100644 --- a/core/modules/comment/src/Entity/Comment.php +++ b/core/modules/comment/src/Entity/Comment.php @@ -224,7 +224,6 @@ public function permalink() { public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { /** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */ $fields = parent::baseFieldDefinitions($entity_type); - $fields += static::publishedBaseFieldDefinitions($entity_type); $fields['cid']->setLabel(t('Comment ID')) ->setDescription(t('The comment ID.')); @@ -327,6 +326,11 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setSetting('is_ascii', TRUE) ->setSetting('max_length', FieldStorageConfig::NAME_MAX_LENGTH); + // Hide the revision log message field by default. + $fields['revision_log_message']->setDisplayOptions('form', [ + 'type' => 'hidden', + ]); + return $fields; }