Drupal StackExchange

How do I use hook_preprocess_page_title() on a Bootstrap subtheme?

1 month 3 weeks ago

I've just discovered that Drupal 8 Bootstrap theme doesn't implement all existent hooks. So, for example, hook_theme_suggestions_page_alter() works, but hook_theme_suggestions_node_alter() doesn't work.

I'm interested on hook_preprocess_page_title(&$variables) and I wonder if it's possible to incorporate this hook into my custom Bootstrap sub-theme. I have created the page-title.html.twig template and cleared the cache.

I saw https://drupal-bootstrap.org/api/bootstrap/docs!plugins!Preprocess.md/group/plugins_preprocess/8.x-3.x but it seems this is for extending an already existent hook in Bootstrap theme, not for adding a new one.

How do I add hook_preprocess_page_title() in a Bootstrap theme?

leandro713

History of nodes viewed by a user

1 month 3 weeks ago

I'm developing a site using Drupal 8.2 and I have to create a page where the user can see which nodes he or she has viewed in the last 30 days. The goal is to provide a per user "browsing history" view with the recently read content ordered by date (ideally filtered by content type).

I've checked other similar questions about this topic and I've found the following suggested modules:

Unfortunately these modules don't have Drupal 8 releases at the time of writing this question (except the Message module which has a pre-release/alpha version).

I've also reviewed the official docs and found there's a core History module that tracks which nodes have been viewed by each user and when. I have this module enabled (it was enabled by default) and I've checked that it's actually collecting user interactions in the history table. According to the docs:

In Drupal 8 and later, the History module is included in Drupal core. When enabled, the History module records which user has read which content.

This only applies to authenticated users. Entities older than 1 month will always be shown as "read".

There is no UI provided, but history data is exposed to the Views module. You can add history data as a field to show "new" or "updated" node marks. You can also use a filter to only show content that is new or updated.

this module provides some kind of interaction with Views, so I assume it should be posible to create a view to show a list with links to each node viewed by the user. I've reviewed all the options in Views (filters, contextual filters and so on) and haven't found anything related to this history.

Is it really posible to create such a view? Any pointers on how to do that? Is there any other way to do this? How would you implement this funcionality in Drupal 8?

Cheers.

Mikel

Getting fatal error when trying to install Umami test site

1 month 3 weeks ago

I'm using Windows 10. I have installed composer and PHP.

I run the command composer create-project drupal/recommended-project mysite to create a recommended project. That works with no errors. Then I try to run the command php web/core/scripts/drupal quick-start demo_umami to install a sample Drupal site using the Umami Maganize demo:

C:\drupal\mysite>php web/core/scripts/drupal quick-start demo_umami 9/17 [==============>-------------] Install site PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in C:\drupal\mysite\web\core\lib\Drupal\Core\TypedData\Plugin\DataType\ItemList.php on line 274 Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in C:\drupal\mysite\web\core\lib\Drupal\Core\TypedData\Plugin\DataType\ItemList.php on line 274 C:\drupal\mysite>

It makes no sense that I'm trying to allocate only 20480 bytes and that's causing it to throw a FatalError. How do I fix this?

MrSnrub

hook_cron(): PHP output does not appear

1 month 3 weeks ago

I am (finally) migrating our Drupal 7 sites to Drupal 10.

The one problem I have not been able to resolve is output from the hook_cron().

Everything appears to execute, whether running on the browser using the special link, clicking on the 'Run cron' button, or as a crontab job. (This is verified by the logger messages, or informational messages which will subsequently appear on the site.)

However, none of the PHP output (for example, echo or print_r()) which worked under Drupal 7 appear on the browser or as an external crontab task. The web page doesn't even refresh. This is problematic because our cronjobs output a lot of debug information that allow us to verify that the tasks ran correctly, and this output is redirected into an email which can be reviewed without accessing the Drupal site. So it is not practical to use the logger or other Drupal mechanisms.

Interestingly, there are scenarios where the output does appear, which might provide a clue as to what the problem is:

  • if I include a call to phpinfo()
  • on certain (but not all) PHP errors, which causes all preceding output to appear

Note that this issue also occurs with the example cron code (cron_example.module) if I try to add echo statements; I have found one other user (on the drupal forum) who also ran into this as part of other questions, but there was no any information on how to resolve it.

I tried flush() in case it's some sort of buffering issue, but to no avail.

function cron_daily_cron() { // This output is not shown. echo "cron_daily_cron started..."; // The messenger message is shown. \Drupal::logger('cron_daily')->notice('cron_daily_cron started'); \Drupal::messenger()->addMessage('cron_daily_cron started...', 'info'); \Drupal::logger('cron_daily')->notice('cron_daily_cron exited'); // The error output caused by the following line is shown. inexistentfunctioncall(); // This message is not shown. echo "cron_daily_cron exited"; }

thank you!

backtothefuture

How can I rename uploaded files?

1 month 3 weeks ago

Using Drupal 8, I want to rename and clean all the uploaded filenames. I want to convert all the spaces to dashes and make all the characters lowercase. A file named Screen Shot 2016-03-29 at 1.13.21 PM.jpg would become screen-shot-2016-03-29-at-1.13.21-pm.jpg.

I want to do this on the image upload dialog form used by CkEditor.

otarza

Use ajax to save modal / dialog form instead of page reload

1 month 3 weeks ago

I'm looking for a way to save modal & dialog forms through ajax instead of redirecting the user after the form submit. Ajax is quite unknown territory to me.

I've found several interesting topics here already:

jQuery UI Dialog attempt to submit a form using AJAX redirects me to the actual form page instead of AJAX submitting

How to close modal after form submit?

I tried all answers shown there, but without luck. I'm using Drupal 9 and it seems that the code can be slightly different between 8 & 9 versions. I tried digging in the documentation pages on drupal.org but can't seem to find anything useful to my case.

Apoc

How can I return a different number of results per page for a view if a user is accessing the site with a mobile device?

1 month 3 weeks ago

I have a large number of views that show member profiles. Right now, I only show 8 members per page, because on a mobile device it takes a very long time to scroll.

However, for the desktop, I could easily show 20 members per page.

Since there are a large number of views, I don't want to do this if I have to duplicate all of them and change the pager settings. Is there another way to return a different number of results per page if the user is on a mobile device?

Patrick Kenny

Exposed filters in Block for Page View do not filter results

1 month 3 weeks ago

I have below content types with following related fields setup in a Drupal7 setup.

Activity Fields: Name, Body and Image.

Event Fields:

  • Date
  • Location: Term Reference for Taxonomy Location
  • Activity : Term Reference for Taxonomy Location
  • Organiser: Entity Reference for Organizer node (as 1 event will have only 1 organizer)

Organiser Fields:

  • Location: Term reference for Location taxonomy
  • Activity: Entity Reference for node Activity.

I have setup a Page View named Experience, with Listing of Events on right sidebar and on left sidebar i want to display the Filters.

I have managed to Expose the filter with BEF, however these filters don't give any result after changing value. Though they are set to Use Ajax.

Also other filters like Organiser and Location are autocomplete fields, these fields do not show-up any value on entering text.

Kindly help

UPDATE: Here's the SQL Query

SELECT node.nid AS nid, node.title AS node_title, node.created AS node_created, 'node' AS field_data_field_event_date_node_entity_type, 'node' AS field_data_field_event_image_node_entity_type, 'node' AS field_data_field_event_location_node_entity_type, 'node' AS field_data_field_event_amount_node_entity_type FROM {node} node LEFT JOIN {field_data_field_event_club} field_data_field_event_club ON node.nid = field_data_field_event_club.entity_id AND (field_data_field_event_club.entity_type = 'node' AND field_data_field_event_club.deleted = '0') WHERE (( (node.status = '1') AND (node.type IN ('event')) AND (field_data_field_event_club.field_event_club_target_id IS NOT NULL ) )) ORDER BY node_created DESC LIMIT 12 OFFSET 0
SNaushadS

Altering ImageField Widget with FUpload enabled

1 month 3 weeks ago

I need to alter the ImageField Widget so that I can add some fields other than the Description, Alt and Title fields. I'm able to do this when I select the file field widget type as Image Uplaod, but when I select the FUpload widget type, the changes don't take effect. Here's the code I'm using:

function bridge_widgets_imagefield_extended_widget($element, $extra_values) { // If you need the field or widget to conditionally add a FAPI field, use these. $field = content_fields($element['#field_name'], $element['#type_name']); $widget = $field['widget']; if( $element['#type_name'] == 'property_gallery' ){ global $user; user_load($user); return array( //This will Replace the Textfield with dropdown select for the description 'revise' => array( '#type' => 'checkbox', '#title' => t('Revise This Description'), '#default_value' => isset($extra_values['revise']) ? $extra_values['revise'] : 0, '#attributes'=>array('class' => 'revise-check') ), 'revisedby' => array( '#type' => 'textfield', '#maxlength' => 64, '#title' => t('Revsied By'), '#default_value' => ($extra_values['revise']==0) ? NULL : $extra_values['revisedby'] , ), 'revisedon' => array( '#type' => 'date', '#title' => t('Date'), '#default_value' => ($extra_values['revise']==0) ? NULL : $extra_values['revisedon'] , ), ); } }
user2014