Skip to content
Snippets Groups Projects
Commit 001b6f5c authored by Scott Carpenter's avatar Scott Carpenter
Browse files

Issue #3424121 by skaught. fix empty count and ensure tab always has title content.

parent 2b2dc3cc
Branches
Tags
1 merge request!19Issue #3424121 by skaught. fix empty count and ensure tab always has title content.
......@@ -113,8 +113,25 @@ function sshop_preprocess_commerce_product(&$vars) {
$product = $vars['elements']['#commerce_product'];
/** @var \Drupal\comment\CommentFieldItemList $reviews */
if ($product->hasField('field_reviews') && $reviews = $product->get('field_reviews')) {
$vars['reviews_count'] = $reviews->comment_count;
$reviews = NULL;
$variables["published_reviews"] = NULL;
/** @var \Drupal\comment\CommentFieldItemList $reviews */
if ($product->hasField('field_reviews')){
if ( !$product->get('field_reviews')->isEmpty() ){
$vars['reviews_count'] = $product->get('field_reviews')->comment_count;
}
$current_user = \Drupal::currentUser();
$vars['reviews_tab'] = 0; // Or handle as appropriate
if ($current_user->hasPermission('access comments')) {
// Additionally, check if the user has access to view the field_reviews field
if ($product->get('field_reviews')->access('view', $current_user)) {
$vars['reviews_tab'] = 1;
}
}
}
$vars['title'] = strip_tags($product->getTitle());
......
......@@ -33,17 +33,16 @@
<li class="active">
<a data-toggle="tab" href="#description">{{ 'Description'|t }}</a>
</li>
{% if reviews_count %}
<li>
{% if reviews_tab == 1 and reviews_count is not empty %}
<li>
<a data-toggle="tab" href="#reviews">
{{ 'Reviews'|t }}
{% if reviews_count > 0 %}
<span class="reviews-count">({{ reviews_count }})</span>
{% endif %}
</a>
</li>
</li>
{% endif %}
</ul>
......@@ -54,7 +53,6 @@
{{ product.body }}
</div>
</div>
{% if reviews_count %}
<div id="reviews" name="reviews" class="tab-pane fade">
<h3 class="tab-title">
{% if reviews_count>0 %}
......@@ -67,6 +65,10 @@
{{ reviews_count }} reviews for {{ title }}
{% endtrans %}
{% endif %}
{% else %}
{% trans with {'context': 'product reviews title' } %}
No Reviews for {{ title }}
{% endtrans %}
{% endif %}
</h3>
......@@ -74,7 +76,7 @@
{{ product.field_reviews }}
</div>
</div>
{% endif %}
</div>
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment