Chris@0: 'comment']); Chris@0: foreach ($fields as $field) { Chris@0: $field->delete(); Chris@0: } Chris@0: Chris@0: // Remove state setting. Chris@0: \Drupal::state()->delete('comment.node_comment_statistics_scale'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Implements hook_install(). Chris@0: */ Chris@0: function comment_install() { Chris@0: // By default, maintain entity statistics for comments. Chris@0: // @see \Drupal\comment\CommentStatisticsInterface Chris@0: \Drupal::state()->set('comment.maintain_entity_statistics', TRUE); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Implements hook_schema(). Chris@0: */ Chris@0: function comment_schema() { Chris@0: $schema['comment_entity_statistics'] = [ Chris@0: 'description' => 'Maintains statistics of entity and comments posts to show "new" and "updated" flags.', Chris@0: 'fields' => [ Chris@0: 'entity_id' => [ Chris@0: 'type' => 'int', Chris@0: 'unsigned' => TRUE, Chris@0: 'not null' => TRUE, Chris@0: 'default' => 0, Chris@0: 'description' => 'The entity_id of the entity for which the statistics are compiled.', Chris@0: ], Chris@0: 'entity_type' => [ Chris@0: 'type' => 'varchar_ascii', Chris@0: 'not null' => TRUE, Chris@0: 'default' => 'node', Chris@0: 'length' => EntityTypeInterface::ID_MAX_LENGTH, Chris@0: 'description' => 'The entity_type of the entity to which this comment is a reply.', Chris@0: ], Chris@0: 'field_name' => [ Chris@0: 'type' => 'varchar_ascii', Chris@0: 'not null' => TRUE, Chris@0: 'default' => '', Chris@0: 'length' => FieldStorageConfig::NAME_MAX_LENGTH, Chris@0: 'description' => 'The field_name of the field that was used to add this comment.', Chris@0: ], Chris@0: 'cid' => [ Chris@0: 'type' => 'int', Chris@0: 'not null' => TRUE, Chris@0: 'default' => 0, Chris@0: 'description' => 'The {comment}.cid of the last comment.', Chris@0: ], Chris@0: 'last_comment_timestamp' => [ Chris@0: 'type' => 'int', Chris@0: 'not null' => TRUE, Chris@0: 'default' => 0, Chris@0: 'description' => 'The Unix timestamp of the last comment that was posted within this node, from {comment}.changed.', Chris@0: ], Chris@0: 'last_comment_name' => [ Chris@0: 'type' => 'varchar', Chris@0: 'length' => 60, Chris@0: 'not null' => FALSE, Chris@0: 'description' => 'The name of the latest author to post a comment on this node, from {comment}.name.', Chris@0: ], Chris@0: 'last_comment_uid' => [ Chris@0: 'type' => 'int', Chris@0: 'unsigned' => TRUE, Chris@0: 'not null' => TRUE, Chris@0: 'default' => 0, Chris@0: 'description' => 'The user ID of the latest author to post a comment on this node, from {comment}.uid.', Chris@0: ], Chris@0: 'comment_count' => [ Chris@0: 'type' => 'int', Chris@0: 'unsigned' => TRUE, Chris@0: 'not null' => TRUE, Chris@0: 'default' => 0, Chris@0: 'description' => 'The total number of comments on this entity.', Chris@0: ], Chris@0: ], Chris@0: 'primary key' => ['entity_id', 'entity_type', 'field_name'], Chris@0: 'indexes' => [ Chris@0: 'last_comment_timestamp' => ['last_comment_timestamp'], Chris@0: 'comment_count' => ['comment_count'], Chris@0: 'last_comment_uid' => ['last_comment_uid'], Chris@0: ], Chris@0: 'foreign keys' => [ Chris@0: 'last_comment_author' => [ Chris@0: 'table' => 'users', Chris@0: 'columns' => [ Chris@0: 'last_comment_uid' => 'uid', Chris@0: ], Chris@0: ], Chris@0: ], Chris@0: ]; Chris@0: Chris@0: return $schema; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Clear caches to fix Comment entity list builder and operations Views field. Chris@0: */ Chris@0: function comment_update_8001() { Chris@0: // Empty update to cause a cache flush to rebuild comment entity handler Chris@0: // information, so that comment operation links work. Chris@0: } Chris@0: Chris@0: /** Chris@0: * Clear caches to fix Comment Views context filter. Chris@0: */ Chris@0: function comment_update_8002() { Chris@0: // Empty update to cause a cache flush. Chris@0: } Chris@0: Chris@0: /** Chris@0: * Add the 'view_mode' setting to displays having 'comment_default' formatter. Chris@0: */ Chris@0: function comment_update_8200() { Chris@0: $config_factory = \Drupal::configFactory(); Chris@0: $displays = []; Chris@0: // Iterate on all entity view displays. Chris@0: foreach ($config_factory->listAll('core.entity_view_display.') as $name) { Chris@0: $changed = FALSE; Chris@0: $display = $config_factory->getEditable($name); Chris@0: $components = $display->get('content') ?: []; Chris@0: foreach ($components as $field_name => $component) { Chris@0: if (isset($component['type']) && ($component['type'] === 'comment_default')) { Chris@0: if (empty($display->get("content.{$field_name}.settings.view_mode"))) { Chris@0: $display->set("content.{$field_name}.settings.view_mode", 'default'); Chris@0: $displays[] = $display->get('id'); Chris@0: $changed = TRUE; Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: if ($changed) { Chris@0: $display->save(TRUE); Chris@0: } Chris@0: } Chris@0: Chris@0: if ($displays) { Chris@0: return new PluralTranslatableMarkup(count($displays), '1 entity display updated: @displays.', '@count entity displays updated: @displays.', ['@displays' => implode(', ', $displays)]); Chris@0: } Chris@0: else { Chris@0: return new TranslatableMarkup('No entity view display updated.'); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Update status field. Chris@0: */ Chris@0: function comment_update_8300() { Chris@0: $entity_definition_update_manager = \Drupal::service('entity.definition_update_manager'); Chris@0: $field_definition = $entity_definition_update_manager->getFieldStorageDefinition('status', 'comment'); Chris@0: $field_definition->setDescription(new TranslatableMarkup('A boolean indicating the published state.')) Chris@0: ->setRevisionable(TRUE); Chris@0: $entity_definition_update_manager->updateFieldStorageDefinition($field_definition); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Set the 'published' entity key. Chris@0: */ Chris@0: function comment_update_8301() { Chris@0: $definition_update_manager = \Drupal::entityDefinitionUpdateManager(); Chris@0: $entity_type = $definition_update_manager->getEntityType('comment'); Chris@0: $keys = $entity_type->getKeys(); Chris@0: $keys['published'] = 'status'; Chris@0: $entity_type->set('entity_keys', $keys); Chris@0: $definition_update_manager->updateEntityType($entity_type); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Update the status field. Chris@0: */ Chris@0: function comment_update_8400() { Chris@0: // The status field was promoted to an entity key in comment_update_8301(), Chris@0: // which makes it NOT NULL in the default SQL storage, which means its storage Chris@0: // definition needs to be updated as well. Chris@0: $entity_definition_update_manager = \Drupal::service('entity.definition_update_manager'); Chris@0: $entity_definition_update_manager->updateFieldStorageDefinition($entity_definition_update_manager->getFieldStorageDefinition('status', 'comment')); Chris@0: } Chris@17: Chris@17: /** Chris@17: * Configure the comment hostname base field to use a default value callback. Chris@17: */ Chris@17: function comment_update_8600() { Chris@17: $entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager(); Chris@17: /** @var \Drupal\Core\Field\BaseFieldDefinition $field_storage_definition */ Chris@17: $field_storage_definition = $entity_definition_update_manager->getFieldStorageDefinition('hostname', 'comment'); Chris@17: $field_storage_definition->setDefaultValueCallback(Comment::class . '::getDefaultHostname'); Chris@17: $entity_definition_update_manager->updateFieldStorageDefinition($field_storage_definition); Chris@17: } Chris@18: Chris@18: /** Chris@18: * Set the 'owner' entity key and update the field. Chris@18: */ Chris@18: function comment_update_8700() { Chris@18: $definition_update_manager = \Drupal::entityDefinitionUpdateManager(); Chris@18: $entity_type = $definition_update_manager->getEntityType('comment'); Chris@18: $keys = $entity_type->getKeys(); Chris@18: $keys['owner'] = 'uid'; Chris@18: $entity_type->set('entity_keys', $keys); Chris@18: $definition_update_manager->updateEntityType($entity_type); Chris@18: $definition_update_manager->updateFieldStorageDefinition($definition_update_manager->getFieldStorageDefinition('uid', 'comment')); Chris@18: } Chris@18: Chris@18: /** Chris@18: * Make the 'entity_type' and 'field_name' comment fields required. Chris@18: */ Chris@18: function comment_update_8701() { Chris@18: $definition_update_manager = \Drupal::entityDefinitionUpdateManager(); Chris@18: $field_definition = $definition_update_manager->getFieldStorageDefinition('entity_type', 'comment'); Chris@18: $field_definition->setRequired(TRUE); Chris@18: $definition_update_manager->updateFieldStorageDefinition($field_definition); Chris@18: Chris@18: $field_definition = $definition_update_manager->getFieldStorageDefinition('field_name', 'comment'); Chris@18: $field_definition->setRequired(TRUE); Chris@18: $definition_update_manager->updateFieldStorageDefinition($field_definition); Chris@18: }