1 comment.install comment_update_1001()

Move comment content type settings into configuration files.

Related topics

File

core/modules/comment/comment.install, line 352
Install, update and uninstall functions for the Comment module.

Code

function comment_update_1001() {
  // Ensure module-provided code is loaded.
  backdrop_load('module', 'node');
  backdrop_load('module', 'entity');

  $node_types = node_type_get_types();
  foreach ($node_types as $node_type) {
    // Move the comment variables into each node type's config.
    $settings = array(
      'comment_default' => update_variable_get('comment_' . $node_type->type, 2), // COMMENT_NODE_OPEN
      'comment_per_page' => update_variable_get('comment_default_per_page_' . $node_type->type, 50),
      'comment_mode' => update_variable_get('comment_default_mode_' . $node_type->type, 1), // COMMENT_MODE_THREADED
      'comment_anonymous' => update_variable_get('comment_anonymous_' . $node_type->type, 0), // COMMENT_ANONYMOUS_MAYNOT_CONTACT
      'comment_subject_field' => update_variable_get('comment_subject_field_' . $node_type->type, 0), // COMMENT_ANONYMOUS_MAYNOT_CONTACT
      'comment_user_picture' => update_variable_get('comment_user_picture_' . $node_type->type, 1),
      'comment_form_location' => update_variable_get('comment_form_location_' . $node_type->type, 1), // COMMENT_FORM_BELOW
      'comment_preview' => update_variable_get('comment_preview_' . $node_type->type, BACKDROP_OPTIONAL),
    );
    $node_type->settings = array_merge($node_type->settings, $settings);
    node_type_save($node_type);

    // Delete the migrated variables.
    update_variable_del('comment_' . $node_type->type);
    update_variable_del('comment_default_per_page_' . $node_type->type);
    update_variable_del('comment_default_mode_' . $node_type->type);
    update_variable_del('comment_anonymous_' . $node_type->type);
    update_variable_del('comment_subject_field_' . $node_type->type);
    update_variable_del('comment_user_picture_' . $node_type->type);
    update_variable_del('comment_form_location_' . $node_type->type);
    update_variable_del('comment_preview_' . $node_type->type);
  }
}