theming – Get comments count in commerce product

I set up comments for a commerce product type called “produkt”. Now I want to get the comment count by preprocessing the product in my theme.theme file and get the comment count for the field “field_produktbewertungen”.

function theme_preprocess_commerce_product(&$variables) {
    $variables('ratings_count') = $variables('commerce_product')->get('field_produktbewertungen')->comment_count;
}

Is there anything different in preprocessing products instead of nodes?
Thank you very much!

theming – How do I change the Font for a “Title Field Label”

I have very little experience with coding but am a fast learner and need to make a change to my page regarding the title field label fonts. They are too small and needs to be bold face.

Can some one please direct me to a list of steps that will take me to the area in my theme (Bartik 8.6.2) so I can make the change. Thank you!

theming – Get the paragraph fields of a content type in a loop in another page drupal 9

I have added a paragraph in content type News.
I want the fields on this paragraph in my custom home page in a loop.
As The News Contents would be shown in a carousel in home page.
I am new to drupal. Can anyone help me?
I have tried using views. the content is rendered. but as the view has extra divs, the design breaks.
Drupal 9 using twig.

theming – full-width hero image in drupal

I am trying to implement a simple hero image feature for a site I am creating (using drupal 9). It seems that there are may ways to go about this, and I hope someone might be able to guide me to a good one. One important detail: on this site, each node will have its own hero; a single hero for multiple pages won’t work here.

I am using bootstrap 4 for my theming. And I’m able to get close to what I want by using the bootstrap jumbotron feature. The problem, though, is that with my jumbotron inside the content region of a page, I can’t get drupal to render the hero to the full window width–only the narrower width of the content element (which makes sense).

I’ve thought about trying to use some sort of block arrangement above the content. But then I can’t figure out how to get node-specific images to display. That is, I can get a nice hero to show up, but it’s the same for multiple pages.

Any thoughts on how to implement a node-specific, full-width hero would be a huge help. Thanks.

theming – What should be used instead of raw filter?

Drupal 9 theming documentation indicates that the Twig raw filter is deprecated in favor of verbatim.

The ds-field-expert.html.twig template uses raw to render the input in the prefix and suffix field, which is often HTML.

{{- settings['prefix']|raw -}}

verbatim in the Twig 2 documentation is not a filter, but instead wraps around content in the template, so wrapping the line of code does not actually go and get the prefix/suffix content. It just renders the twig.

What should I use instead of raw in this case so the markup I enter into the prefix and suffix field of a Display Suite expert field template renders as HTML and not plain text?
Will this template break in Drupal 9?

theming – How to override body field value in preprocess method?

If you mean that you wish to rewrite a field (in your case the body field) to something else other than what the user has inserted you can do this.

/**
 * Implements hook_entity_presave().
 */
function MODULENAME_entity_presave(EntityInterface $entity) {
// If entity type is Article.
  if ($entity->bundle() == 'article') {
    // Get the value of the custom field that the user has inserted.
    $title = $entity->field_custom_field->getValue();
    // If there is a result, rewrite the label with the first value.
    if (isset($title) && is_array($title)) {
      $title = $title(0)('value');
      $entity->set('label', $title);
    }
  }
}

Of course, you can just do this:

$entity->set('field_body', $value);

theming – What to use instead of raw filter for D9 in Display Suite templates?

Drupal 9 themeing documentation indicates that the Twig raw filter is deprecated in favor of verbatim. https://www.drupal.org/docs/upgrading-drupal/how-to-prepare-your-drupal-7-or-8-site-for-drupal-9/preparing-for-use-of-twig#s-template-facing-twig-2-changes

Twig 2 Verbatim: https://twig.symfony.com/doc/2.x/tags/verbatim.html

The ds-field-expert.html.twig template in Display Suite uses raw to render the input in the prefix and suffix field, which is often HTML. https://git.drupalcode.org/project/ds/-/blob/8.x-3.x/templates/ds-field-expert.html.twig#L16

{{- settings['prefix']|raw -}}

verbatim in the Twig 2 documentation is not a filter, but instead wraps around content in the template, so wrapping the line of code does not actually go and get the prefix/suffix content. It just renders the twig.

  1. What should I use instead of raw in this case so the HTML I enter into the prefix and suffix field of a Display Suite expert field template renders as HTML and not plain text?
  2. Will this template break in D9?

theming – Can I add pagination to individual blog posts in my twig file?

I have a views page which has all the blog articles, and you can click on a link to bring you to a single blog page.

On that single blog page I want to be able to add buttons for Previous and Next post. Something like

<a class="white-btn" href="{{ previous.href }}">Previous Article</a>
 <a class="white-btn" href="{{ next.href }}">Next Article</a>

Is this possible?

theming – pass twig variable in drupal_entity() in drupal 8

The first assumption is that you already installed twig tweak module.

I believe the problem is in getting the form_name part, not in rendering.
first solution :

{% set form_name = node.field_c.0.value|trim|striptags %}
{{ drupal_entity('webform', form_name) }}

so if your field is a single value
I would suggest use twig field value module. then you can easily use

{% set form_name = content.field_c| field_value %}
{{ drupal_entity('webform', form_name) }}

another solution is :

{% set form_name = content.field_c| field_value %}
{{ { '#type': 'webform', '#webform': form_name } }}

theming – How to run view query incontroller drupal 8

I have a query formed in my view and I want to run this query to fetch result in controller. Basically I have create a title search with exposé filter and now i want on click search button i get desire result.

Below is my view query:

SELECT node_field_data.created AS node_field_data_created, node_field_data.nid AS nid, paragraphs_item_field_data_node__field_software_idas.id AS paragraphs_item_field_data_node__field_software_idas_id
        FROM
        {node_field_data} node_field_data
        LEFT JOIN {node__field_software_idas} node__field_software_idas ON node_field_data.nid = node__field_software_idas.entity_id AND node__field_software_idas.deleted = '0'
        LEFT JOIN {paragraphs_item_field_data} paragraphs_item_field_data_node__field_software_idas ON node__field_software_idas.field_software_idas_target_revision_id = paragraphs_item_field_data_node__field_software_idas.revision_id
        LEFT JOIN {node__field_secondary_banner} node__field_secondary_banner ON node_field_data.nid = node__field_secondary_banner.entity_id AND node__field_secondary_banner.deleted = '0' AND (node__field_secondary_banner.langcode = node_field_data.langcode OR node__field_secondary_banner.bundle = 'blog')
        LEFT JOIN {node__field_primary_banner} node__field_primary_banner ON node_field_data.nid = node__field_primary_banner.entity_id AND node__field_primary_banner.deleted = '0' AND (node__field_primary_banner.langcode = node_field_data.langcode OR node__field_primary_banner.bundle = 'blog')
        WHERE (node_field_data.status = '1') AND (node_field_data.type IN ('blog')) AND ((node_field_data.created < 1609396357+0)) AND (node_field_data.title LIKE '%fear%' ESCAPE '\') AND (node__field_secondary_banner.field_secondary_banner_value = '0') AND (node__field_primary_banner.field_primary_banner_value = '0')
        ORDER BY node_field_data_created DESC
        LIMIT 6 OFFSET 0

Below is my query in controller

$database = Drupal::database();

/*$markup = Drupal::service('renderer')->render(views_embed_view('blog_detail', 'block_1','fear'));
$response = new AjaxResponse();
$selector = '#publication_listing';
  $response->addCommand(new HtmlCommand($selector, $markup));

return $response;*/

$result = $database->query("SELECT node_field_data.created AS node_field_data_created, 
node_field_data.nid AS nid, paragraphs_item_field_data_node__field_software_idas.id AS 
paragraphs_item_field_data_node__field_software_idas_id
FROM
node_field_data.node_field_data
LEFT JOIN node__field_software_idas.node__field_software_idas ON node_field_data.nid = 
node__field_software_idas.entity_id
LEFT JOIN paragraphs_item_field_data.paragraphs_item_field_data_node__field_software_idas ON 
node__field_software_idas.field_software_idas_target_revision_id = 
paragraphs_item_field_data_node__field_software_idas.revision_id
LEFT JOIN node__field_secondary_banner.node__field_secondary_banner ON node_field_data.nid = 
node__field_secondary_banner.entity_id AND node__field_secondary_banner.deleted = '0' AND 
(node__field_secondary_banner.langcode = node_field_data.langcode OR 
node__field_secondary_banner.bundle = 'blog')
LEFT JOIN node__field_primary_banner.node__field_primary_banner ON node_field_data.nid = 
node__field_primary_banner.entity_id AND node__field_primary_banner.deleted = '0' AND 
(node__field_primary_banner.langcode = node_field_data.langcode OR node__field_primary_banner.bundle = 
'blog')
WHERE (node_field_data.status = '1') AND (node_field_data.type IN ('blog')) AND 
((node_field_data.created < 1609390539+0)) AND (node_field_data.title LIKE '%dgdfgf%' ESCAPE '\') AND 
(node__field_secondary_banner.field_secondary_banner_value = '0') AND 
(node__field_primary_banner.field_primary_banner_value = '0')
ORDER BY node_field_data_created DESC
LIMIT 6 OFFSET 0")->fetchAll();