theming – How to add multiple languages for hreflang

I’m trying to add multiple hreflang’s for my drupal site using the following:

$attachments('#attached')('html_head_link')(3) = array(
  '0'=> array(
    'rel' => 'alternate',
    'hreflang' => 'en-in',
    'href' => $frontpage_path
  ),
  '1' => false
);

i need to be able to add additional records but it keeps picking the last record for some reason and only displays only one hreflang tag.

theming – Content translation not working on my home page for 9.1.3

I have a translation problem on my site in drupal 9.1.3.

I have a content type for my homepage that contains two fields: field_slides which is an EntiyReferenceRevisionFieldItemList to a Paragraphs field and field_tabulations which is an EntityReferenceFieldItemList to a “tab” content type.

This type of content contains 4 fields including a Paragraphs field.

My configuration in admin / config / regional / content-language is correct. And I only enabled translation for child paragraphs fields as said in the documentation.

In the template I call the title field of the entity referenced by field_tabulations as follows:

{{ elements['field_tabulations']['# items'].0.entity.title.0.value }}

However, the home page node fields in my template front page are not translated. The blocks are, however as the main menu is.

theming – (Rookie Question) Set background picture only within the text field, not entire page on Drupal 7

How should i make the background image appear within the text field (in context type: basic page) but not the entire web page?

I am using Background Image Formatter, running on Drupal 7 with Bootstrap 3.
Module url: (https://www.drupal.org/project/bg_image_formatter)(1)
currentimage

I would like to appear within the text field
expectedoutput

This is my current config
config1
config2
I am extremely new to web development and Drupal. Apologies if such question offends you. Any answer is appreciated!

theming – How to know a page whether has a class named ‘test’ element in drupal?

Stack Exchange Network


Stack Exchange network consists of 176 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

views – Adding for loop in Drupal 8 theming

I would need a small help to get the output by adding the for loop. I have a view which has a image field.
And I would like to theme it, I have created two view templates called “views-view-list–image-article.html.twig” and “views-view-fields–image-article.html.twig”

I want to achieve the output in the below format. Here “wrap clearfix” div is repeating and the inner divs “lhs-img” and “rhs-img” are also repeating.

<div class="inner-content">
  <div class="container">
    <h2>Heading</h2>
    <div class="wrap-slider owl-carousel owl-loaded owl-drag" aria-label="Latest Articles" tabindex="0">
      <div class="wrap clearfix">
        <div class="lhs-img">
          <a href="../images/image-one.jpg"><img src="../images/image-one.jpg" alt=""></a>
          <a href="../images/image-two.jpg"><img src="../images/image-two.jpg" alt=""></a>
          <a href="../images/image-three.jpg"><img src="../images/image-three.jpg" alt=""></a>
        </div>
        <div class="rhs-img">
          <a href="../images/image-four.jpg"><img src="../images/image-four.jpg" alt=""></a>
          <a href="../images/image-five.jpg"><img src="../images/image-five.jpg" alt=""></a>
          <a href="../images/image-six.jpg"><img src="../images/image-six.jpg" alt=""></a>
        </div>
      </div>
      <div class="wrap clearfix">
        <div class="lhs-img">
          <a href="../images/image-four.jpg"><img src="../images/image-four.jpg" alt=""></a>
          <a href="../images/image-five.jpg"><img src="../images/image-five.jpg" alt=""></a>
          <a href="../images/image-six.jpg"><img src="../images/image-six.jpg" alt=""></a>
        </div>
        <div class="rhs-img">
          <a href="../images/image-one.jpg"><img src="../images/image-one.jpg" alt=""></a>
          <a href="../images/image-two.jpg"><img src="../images/image-two.jpg" alt=""></a>
          <a href="../images/image-three.jpg"><img src="../images/image-three.jpg" alt=""></a>
        </div>
      </div>
      <div class="wrap clearfix">
        <div class="lhs-img">
          <a href="../images/image-one.jpg"><img src="../images/image-one.jpg" alt=""></a>
          <a href="../images/image-two.jpg"><img src="../images/image-two.jpg" alt=""></a>
          <a href="../images/image-three.jpg"><img src="../images/image-three.jpg" alt=""></a>
        </div>
        <div class="rhs-img">
          <a href="../images/image-four.jpg"><img src="../images/image-four.jpg" alt=""></a>
          <a href="../images/image-five.jpg"><img src="../images/image-five.jpg" alt=""></a>
          <a href="../images/image-six.jpg"><img src="../images/image-six.jpg" alt=""></a>
        </div>
      </div>
    </div>
  </div>
</div>

In my “views-view-fields–image-article.html.twig”, I have added this code

<a href="{{ fields.field_media_image.content }}"><img src="{{ fields.field_media_image.content }}" alt="{{ fields.thumbnail__alt.content }}"></a>

Need help on looping the “wrap clearfix”, “lhs-img” and “rhs_img” divs.

Thanks in advance

theming – How do I test for an empty Address webform element?

Using Drupal 9.1.3 : Webform 6.0.0

I have 4 composite address elements in a webform that may or may not be filled, depending on the user’s other selections within the form.

I can use the default email Body format, selecting the checkbox: Exclude empty elements, but this outputs a list of the Element Title, followed by the Element data.

I would like to display the output using twig markup, with a custom title on the left and the element data on the right as below:

Title Data
Address 123 The Street
The Town
County, Post Code

Using the webforms debug submission when testing the form it displays the address: element as null when the form is submitted without any data in the address element of the form.

I have used the code below to check for the null attribute.

{% if webform_token('(webform_submission:values:address)', webform_submission, (), options) == '' %}
  <div>Address Element is EMPTY using the '' test</div>
{% elseif webform_token('(webform_submission:values:address)', webform_submission, (), options) == null %}
  <div>Address Element is EMPTY using the null test</div>
{% else %}
  <div>Address Element is EMPTY</div>
{% endif %}

This always displays ‘Address Element is EMPTY’

If I test other Webform elements that results in a empty string eg. ” when no data is entered, the above twig code works with the correct (webform_submission:values:element) and I can elimate the empty custom Title and element using twig code.

theming – CSS problems styling the search box block created by Search API Pages module

I’m using Search API and Search API Pages on Drupal 9 and I’m trying to style the Search API Pages search block. The problem is that when placed anywhere but bottom in the sidebar, the search block overlaps with the block below as seen in the attached pics. This makes the blocks visually too close and also (in Firefox) disables the overlapped part of the search box from being clicked in, which is really annoying. Any suggestions for resolving this?

The other issue I’m having is that the fontawesome search icon only appears within the search box in Firefox. In Chrome and Safari the icon is placed at the top left of the page, relative to the body instead of to the search block. What am I missing here?

Overlap between search block and block below

Another view of the overlap

.search-api-page-block-form-search input {
  width: 100%;
}
.search-api-page-block-form-search .form-item {
  width: 70%;
  float: left;
}
.search-api-page-block-form-search .form-actions {
  width: 30%;
  float: right;
}
.search-api-page-block-form-search .form-type-search input {
  border-right: none !important;
  text-indent: 25px;
  background-color: transparent;
  position: relative;
}
.search-api-page-block-form-search .form-type-search:before {
  content: "f002";
  font-family: FontAwesome;
  position: absolute;
  top: 25px;
  left: 35px;
  background-color: transparent;
}
.search-api-page-block-form-search .form-item,
.search-api-page-block-form-search .form-actions {
  margin: 5px auto!important;
  display: inline-block;
  font-family: Consolas, "courier new";
}
.search-api-page-block-form-search .form-actions input {
  font-family: FontAwesome;
  margin: 0 !important;
}

I don’t know whether I’m allowed to provide a link but you can see the problem here: https://verygomez.com/theatre.
Before downvoting this please note that I’m not a coder. I’m trying my best but I’m making this up as I go along.

Thanks!

theming – Adding Drupal 8/9 Commerce Wishlist Share Mail Template Variables from Form

I am trying to add 2 additional form fields to the Wishlist Share form where the user input will be rendered in the email. I have been able to add the fields to the form, but I am not sure how to add the user’s input in the email twig template.

Here is how I have updated the form() function:

  public function form(array $form, FormStateInterface $form_state) {
    $form('#tree') = TRUE;
    $form('#attached')('library')() = 'core/drupal.dialog.ajax';
    // Workaround for core bug #2897377.
    $form('#id') = Html::getId($form_state->getBuildInfo()('form_id'));

    $form('to') = (
      '#type' => 'email',
      '#title' => $this->t('Recipient Email'),
      '#required' => TRUE,
    );

// COMBAK my edit

    $form('sender_name') = (
      '#type' => 'textfield',
      '#title' => $this->t('Your Name'),
      '#required' => FALSE,
    );

    $form('sender_message') = (
      '#type' => 'textarea',
      '#title' => $this->t('Your Message'),
      '#required' => FALSE,
    );

// COMBAK eo my edit

    return $form;
  }

  /**
   * {@inheritdoc}
   */
  protected function actions(array $form, FormStateInterface $form_state) {
    $actions('submit') = (
      '#type' => 'submit',
      '#value' => $this->t('Send email'),
      '#submit' => ('::submitForm'),
    );
    if ($this->isAjax()) {
      $actions('submit')('#ajax')('callback') = '::ajaxSubmit';
    }

    return $actions;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    /** @var Drupalcommerce_wishlistEntityWishlistInterface $wishlist */
    $wishlist = $this->entity;
    $to = $form_state->getValue('to');

    // COMBAK: my added vars
    $sender_name = $form_state->getValue('sender_name');
    $sender_message = $form_state->getValue('sender_message');

    $this->wishlistShareMail->send($wishlist, $to, $sender_name, $sender_message);

    $this->messenger()->addStatus($this->t('Shared the wishlist to @recipient.', (
      '@recipient' => $to,
    )));
    $form_state->setRedirectUrl($wishlist->toUrl('user-form'));
  }

This is the function that calls the mailHandler that I have updated:

public function send(WishlistInterface $wishlist, $to, $sender_name, $sender_message) {
    $owner = $wishlist->getOwner();

    $subject = $this->t('Check out my @site-name wishlist', (
      '@site-name' => $this->configFactory->get('system.site')->get('name'),
    ));
    $body = (
      '#theme' => 'commerce_wishlist_share_mail',
      '#wishlist_entity' => $wishlist,
      // COMBAK: my added vars
      '#sender_name' => $sender_name,
      '#sender_message' => $sender_message,
    );
    $params = (
      'id' => 'wishlist_share',
      'from' => $owner->getEmail(),
      'wishlist' => $wishlist,
    );

    return $this->mailHandler->sendMail($to, $subject, $body, $params);
  }

And this is the preprocees function provided by the commerce wishlist module:

function template_preprocess_commerce_wishlist_share_mail(array &$variables) {
  /** @var Drupalcommerce_wishlistEntityWishlistInterface $wishlist */
  $wishlist = $variables('wishlist_entity');
  $wishlist_url = $wishlist->toUrl('canonical', ('absolute' => TRUE));

  $variables('wishlist_url') = $wishlist_url->toString();

  // COMBAK: my added vars
  //$sender_name = $variables('sender_name');
}

And finally the twig template for the email itself:

{#
/**
 * @file
 * Template for the wishlist share email.
 *
 * Available variables:
 * - wishlist_entity: The wishlist entity.
 * - wishlist_url: The wishlist url.
 *
 * @ingroup themeable
 */
#}
<p>
  {% trans %}Check out my wishlist!{% endtrans %}
</p>

<p>
  {% trans %}I use my wishlist for keeping track of items I am interested in.{% endtrans %} <br>
  {% trans %}To see the list in the store and buy items from it, <a href="{{ wishlist_url }}">click here</a>.{% endtrans %}
</p>

<p>
  {% trans %}Thanks for having a look!{% endtrans %}
</p>

I haven’t been able to figure out how to access the variables I added to the body() array in the twig template.

Any help would be greatly appreciated.

Thanks!

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!