diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index 5fe1da8..5d5ff5f 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -572,12 +572,10 @@ function comment_update_8006(&$sandbox) { // Add a default comment field for existing node comments. $field_name = 'comment_node_' . $node_type; $field = array( - 'cardinality' => '1', // We need one per content type to match the existing comment bundles. 'id' => $field_name, - 'module' => 'comment', - 'translatable' => '0', 'type' => 'comment', + 'module' => 'comment', ); // Make sure field doesn't already exist. $index = 0; @@ -616,14 +614,14 @@ function comment_update_8006(&$sandbox) { 'preview' => update_variable_get('comment_preview_' . $node_type, 1), ); $instance = array( + 'id' => "node.$node_type." . $field['id'], + 'entity_type' => 'node', 'bundle' => $node_type, 'default_value' => array(array('status' => $default_value)), 'deleted' => '0', 'description' => '', - 'entity_type' => 'node', - 'id' => $field['id'], 'label' => 'Comment settings', - 'required' => 1, + 'required' => TRUE, 'settings' => $instance_settings, ); _update_8003_field_create_instance($field, $instance); @@ -657,13 +655,13 @@ function comment_update_8006(&$sandbox) { ->save(); // Clean up old variables. - variable_del('comment_' . $node_type); - variable_del('comment_default_mode_' . $node_type); - variable_del('comment_default_per_page_' . $node_type); - variable_del('comment_anonymous_' . $node_type); - variable_del('comment_subject_field_' . $node_type); - variable_del('comment_form_location_' . $node_type); - variable_del('comment_preview_' . $node_type); + update_variable_del('comment_' . $node_type); + update_variable_del('comment_default_mode_' . $node_type); + update_variable_del('comment_default_per_page_' . $node_type); + update_variable_del('comment_anonymous_' . $node_type); + update_variable_del('comment_subject_field_' . $node_type); + update_variable_del('comment_form_location_' . $node_type); + update_variable_del('comment_preview_' . $node_type); } } diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 9e41c42..6ef3609 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -540,7 +540,7 @@ function theme_comment_block($variables) { function comment_entity_view(EntityInterface $entity, EntityDisplay $display, $view_mode, $langcode) { if ($entity->entityType() != 'node') { // Comment links are only added to node entity type for backwards - // compatability. Should you require comment links for other entity types + // compatibility. Should you require comment links for other entity types // you can do-so by implementing a new field formatter. // @todo Make this configurable from the formatter see // http://drupal.org/node/1901110 @@ -548,8 +548,12 @@ function comment_entity_view(EntityInterface $entity, EntityDisplay $display, $v } $fields = Drupal::service('comment.manager')->getFields('node'); foreach ($fields as $field_name => $detail) { + // Skip fields that entity does not have. + if (!$entity->getPropertyDefinition($field_name)) { + continue; + } $links = array(); - $commenting_status = _comment_get_default_status(field_get_items($entity, $field_name)); + $commenting_status = $entity->get($field_name)->status; if ($commenting_status) { $instance = Drupal::service('field.info')->getInstance('node', $entity->bundle(), $field_name); // Entity have commenting open or close. @@ -624,7 +628,7 @@ function comment_entity_view(EntityInterface $entity, EntityDisplay $display, $v // But we don't want this link if we're building the entity for search // indexing or constructing a search result excerpt. if ($commenting_status == COMMENT_OPEN) { - $comment_form_location = $instance['settings']['form_location']; + $comment_form_location = $instance->getFieldSetting('form_location'); if (user_access('post comments')) { // Show the "post comment" link if the form is on another page, or // if there are existing comments that the link will skip past. @@ -874,7 +878,7 @@ function comment_view(CommentInterface $comment, $view_mode = 'full', $langcode */ function comment_links(CommentInterface $comment, EntityInterface $entity, $field_name) { $links = array(); - $status = _comment_get_default_status(field_get_items($entity, $field_name)); + $status = $entity->get($field_name)->status; if ($status == COMMENT_OPEN) { if ($comment->access('delete')) { $links['comment-delete'] = array( @@ -1149,7 +1153,7 @@ function comment_node_update_index(EntityInterface $node, $langcode) { $mode = $instance->getFieldSetting('default_mode'); $comments_per_page = $instance->getFieldSetting('per_page'); if (($items = field_get_items($node, $field_name)) && - _comment_get_default_status($items) && $cids = comment_get_thread($node, $field_name, $mode, $comments_per_page)) { + $items->status && $cids = comment_get_thread($node, $field_name, $mode, $comments_per_page)) { $comments = comment_load_multiple($cids); comment_prepare_thread($comments); $build = comment_view_multiple($comments); @@ -1901,26 +1905,6 @@ function comment_add_default_comment_field($entity_type, $bundle, $field_name = } /** - * Helper to get default value for field. - * - * @param array $values - * The field values array or NULL for field create with field UI. - * - * @return int - * The value when exists or COMMENT_OPEN. - * - * @todo Replace with field default value after http://drupal.org/node/1919834 - */ -function _comment_get_default_status($values) { - // We only ever process first value if any. - // @todo Remove when all entities are NG. - if (is_object($values)) { - $values = $values->getValue(); - } - return isset($values[0]['status']) ? $values[0]['status'] : COMMENT_OPEN; -} - -/** * Process callback to add submit handler for instance settings form. * * Attaches the required translation entity handlers for the instance which diff --git a/core/modules/comment/comment.pages.inc b/core/modules/comment/comment.pages.inc index dab20af..84dd97c 100644 --- a/core/modules/comment/comment.pages.inc +++ b/core/modules/comment/comment.pages.inc @@ -100,7 +100,7 @@ function comment_reply(EntityInterface $entity, $field_name, $pid = NULL) { } // Should we show the reply box? - $commenting_status = _comment_get_default_status(field_get_items($entity, $field_name)); + $commenting_status = $entity->get($field_name)->status; if ($commenting_status != COMMENT_OPEN) { drupal_set_message(t("This discussion is closed: you can't post new comments."), 'error'); $uri['options']['absolute'] = TRUE; diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/field/formatter/CommentDefaultFormatter.php b/core/modules/comment/lib/Drupal/comment/Plugin/field/formatter/CommentDefaultFormatter.php index c929061..a3dfe3d 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/field/formatter/CommentDefaultFormatter.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/field/formatter/CommentDefaultFormatter.php @@ -36,7 +36,7 @@ public function viewElements(EntityInterface $entity, $langcode, FieldInterface $field = $this->fieldDefinition; $field_name = $field->getFieldName(); - $commenting_status = _comment_get_default_status($items); + $commenting_status = $items->status; if ($commenting_status != COMMENT_HIDDEN && empty($entity->in_preview)) { $comment_settings = $this->getFieldSettings(); diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/field/widget/CommentWidget.php b/core/modules/comment/lib/Drupal/comment/Plugin/field/widget/CommentWidget.php index c57c89d..6ac74dc 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/field/widget/CommentWidget.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/field/widget/CommentWidget.php @@ -36,7 +36,7 @@ public function formElement(FieldInterface $items, $delta, array $element, $lang '#type' => 'radios', '#title' => t('Comments'), '#title_display' => 'invisible', - '#default_value' => _comment_get_default_status($items), + '#default_value' => $items[$delta]->status, '#options' => array( COMMENT_OPEN => t('Open'), COMMENT_CLOSED => t('Closed'), @@ -66,7 +66,8 @@ public function formElement(FieldInterface $items, $delta, array $element, $lang '#type' => 'details', // Collapse the advanced settings when they are the same // as the defaults for the instance. - '#collapsed' => (_comment_get_default_status($items) == _comment_get_default_status($field->default_value)), + // @todo Add $this->defaultStatus($field) and compare actual values. + '#collapsed' => ($items->getValue() == $field->getFieldDefaultValue($entity)), '#group' => 'advanced', '#attributes' => array( 'class' => array('comment-' . drupal_html_class($element['#entity_type']) . '-settings-form'),