Drupal StackExchange

Overwriting Module Template?

1 month 3 weeks ago

I'm trying to override the following template file:

modules/contrib/feed_block/templates/feed-block-rss-item.html.twig

I've tried:

custom/my_theme/feed-block-rss-item.html.twig custom/my_theme/feed-block/feed-block-rss-item.html.twig custom/my_theme/feed_block/feed-block-rss-item.html.twig custom/my_theme/feed_block.html.twig

No template hints are given.

Documentation simply suggests the template be placed in /template.

Sam

Why can't I modify my comment form using hook_form_alter

1 month 3 weeks ago

I have enabled comments for a custom node type.

I am trying to theme that comment form using hook_form_alter(&$form, &$form_state) (For example, I'd like to remove the label of the comment_body form field)

To do that, I use the following function:

function MYTHEME_form_comment_form_alter(&$form, &$form_state) { $form['comment_body']['und']['#title'][0] = ''; }

However in the output the title of the form field is still there:

Here's the markup:

The value of $form does not correspond to what I am used to see. Here's a screenshot from my debugger:

Silvan Mühlemann

How to add at least one CSS class to a twig region?

1 month 3 weeks ago

I am trying to add CSS classes to a new region {{ page.example }} in page.html.twig

In the start of page.html.twig, I have added a set of CSS classes:

{% set classes = [ 'region--content', 'grid-full', 'layout--pass--content-medium', ] %}

When I try to apply them to an element as follows, this element just disappears from my node.

{{ page.example.addClass(classes) }}

What have I done wrong?

osi

Get block_content from block

1 month 3 weeks ago

What is the correct way to check if a block has an associated block_content instance, and if so, get the block_content object? What I have does not feel particularly intuitive or efficient:

/** @var \Drupal\block\Entity\Block $block */ $block; $block_plugin = $block->getPlugin(); if ($block_plugin->getBaseId() == 'block_content') { /** @var \Drupal\block_content\Entity\BlockContent $block_content */ $block_content = $block->getPlugin()->build()['#block_content']; }

It feels weird to build the render array for the $block_plugin just to get access to the block content, but there doesn't seem to be a more helpful method on $block or $block_plugin.

For context: I'm conditionally updating block configuration in a deploy hook based on the block_content bundle, so I'm not rendering anything. Given that, it feels like I shouldn't be using the render array.

miwayha

Views math expression or Computed field to find date difference in views

1 month 3 weeks ago

I have two content type, Bill (Type1) and Cash Receipts (Type2), Type2 referencing Type1 when cash is received.

In Type1 I have date field called (Bill Issue date), and Type2 I have date field cash receipt date.

So I want to calculate, different between those two dates. I was trying by creating views with two date (by entity reference relationship), then subtract two filed with math expression field, but it return zero.

Actually, I have no idea whether I was wrong or Its not possible to calculate different between dates with views math expression field?

I think, it can be done with Computed Field, I did one within same content type, but I don’t know how to access a field from different content type, please help.

Code that I was used to calculate date for same content type, but how I can access a field from other content type?

If the Machine name of your date-field is 'field_example_date', then the Computed Code (PHP) would be

$startdate = $entity->field_example_date['und'][0]['value']; // Value of start-date $enddate = $entity->field_example_date['und'][0]['value2']; // Value of end-date $datediff = strtotime($enddate) - strtotime($startdate); /* The PHP Function STRTOTIME parses the english textual datetime description * into a Unix timestamp */ $num_leaves = $datediff/(60*60*24); /* Since we need the number of days IN-BETWEEN, * we divide the resultant difference by 60*60*24 . * * Incase of counting no.of days "FROM" to "TO" days, add 1 to the above result. * $num_leaves = $datediff/(60*60*24) + 1; */ $entity_field[0]['value'] = $num_leaves; The Display Code (PHP) will have $display_output = $entity_field_item['value'];
Md. Jakaria

How to allow users to log in by multiple email addresses?

1 month 3 weeks ago

I'm trying to find a way to allow users to log in by email address when they have multiple email addresses registered on my site.

I'm using the Email Registration module to allow users to register with an email address.

Then I can use the Alternative User Emails module to save all the old email addresses when users change their email addresses. These old email addresses are stored in a separate database table.

The email registration module uses user_load_by_mail() to get the user account when logging in. I think that overriding this is probably the simplest way, but there is no hook_user_load_by_mail() as far as I can tell.

So it looks like my options are:

  • Hacking core to override user_load_by_mail()
  • Patching the Email Registration module to check the table added by the Alternative User Emails module

Is there a way to glue these together in a custom module without hacking any module?
Ideally, I'd be able to write my own custom module that builds on top of core and contributed modules.

Patrick Kenny

Unlimited field collection pagination in node edit page

1 month 3 weeks ago

In my node I have a field collection which is set to unlimited. How to enable pagination for node edit page, where all items from that field collection are displayed? For display there are couple possibilities - pagination modules, views etc. but how to do it for node edit page?

dmk.i-t

Drupal Planet

Salsa Digital: DrupalSouth 2024 day 2 wrap-up

1 month 3 weeks ago
Beyond buzzwords: demystifying diversity and inclusion Suchi : Amazing talk! Panel discussion of three panelists and one moderator, all from Girls in Tech.  They shared their experiences of not feeling included at different points in their lives and what people can do to make sure that diversity, equity, and inclusion (DEI) is not just a buzzword (phrase) but is actually embraced in organisations.  Paul : Great discussion on diversity and inclusion.  While the theme was girls in tech and the examples of unconscious gender bias and real-world challenges of the panel members made it all real, the most powerful takeaways were actually more generally about inclusion and providing every person an opportunity to be heard and succeed.  Very simple message on driving inclusion, “Ask people!

Drupal Core News: Drupal 11.0 will require PHP 8.3 and MySQL 8.0

1 month 3 weeks ago

Drupal 11 development has reached a point where the system requirements are being raised in the development branch. To prepare core developers for this and to inform the community at large, we are announcing the following requirements for Drupal 11.

Webserver

We announced in mid-February that there is an RFC to remove support for Windows in production. Other webserver requirements are unchanged.

PHP

Drupal 11 will require PHP 8.3 and older versions of PHP are not supported. Note that as of Drupal 9.4, a policy was adopted to automatically drop support for PHP versions no longer supported by the PHP maintainers, so future minor versions of Drupal 11 will increase the requirement further.

Database

The minimum database requirements for backends supported by Drupal 11 are MySQL 8.0, MariaDB 10.6, PostgreSQL 16 and SQLite 3.45.

Composer

Similar to Drupal 10.2, Drupal 11 will require Composer 2.7.0 or newer; this change was made for the Composer security fix released in February 2024.

Browsers

The existing browser policy has not changed and there was no need to update it for Drupal 11. Drupal already drops support for older versions of browsers as new ones get released.

PHP and JavaScript dependencies

Drupal 11 will depend on Symfony 7, PHPUnit 10 and jQuery 4, work is ongoing to update to these versions'.

Drupal 10 will receive long term support

Drupal 10 will continue to be supported until mid-late 2026 and the release of Drupal 12.