Drupal StackExchange

How to configure htaccess to redirect ALL traffic through https?

4 days 12 hours ago

I'm looking for a way to redirect users to https://domain.com whether they type the www or not

I'm using a shared host for a drupal website so i don't have access to virtual host config files. A let's encrypt certificate if included with the hosting package
Right now the website can be accessed both with http and https depending on what you type in the browser.
In looking for a solution to force redirection to https i found this section in the in the .htaccess file that redirects users who type the www. to https://domain.com

# To redirect all users to access the site WITHOUT the 'www.' prefix, # (http://www.example.com/... will be redirected to http://example.com/...) # uncomment the following: RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^ https%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]

Now i'm looking for a way to redirect when typing http://domain.com without the www.

Do i need to put another rule somewhere in addition to the line i uncommented or is there some other way to do this ?

NSTK

Adding Theme Suggestions Programmatically For Views (Rows & Fields)

4 days 12 hours ago

For a site I'm currently building I've got a variety of views, all with multiple display modes for different pages.

For example, I have a venues view, one block is named listing which lists all of my venues content type. I have another block which has some more specific contextual filters.

My issue is, this different block is styled the same, and has the same markup as my listing block so I don't want to have to duplicate my Twig templates for the rows and fields, for each display mode I have.

What my idea was is to add a function to my .theme file that would allow me to list display modes for a certain view, and add a single theme suggestion off that back of that. This way I can rename my Twig templates, and re-use the same ones for row and field level, on as many display modes as I'd like.

As I'm not using a theme suggestions alter hook, I'm not sure how I actually add theme suggestions.

Here's what I've got so far:

/** * Theme suggestions for views. */ function spve_preprocess_views_view(&$variables) { $view = $variables['view']; $id = $view->storage->id(); // Venues if($id === 'venues') { // Venues grid switch($view->current_display) { case 'single_occasion_type_listing': $suggestion = 'views-view--venues-grid'; break; default: $suggestion = null; break; } } }

Obviously I'd need to replace either $suggestion with the correct function to add a theme suggestion, or add a bit at the end of my function to add a theme suggestion based of my $suggestion variable.

Daniel Dewhurst

How do I show the publishing date instead of the creation date?

4 days 13 hours ago

When I create an article and I don't publish it, so I could edit the article later and publish it when it's finished, I notice Drupal shows the creation date, not the publishing date.

Is there a way to change it so the items on the front page show their publishing date and not the creation date? Is there a different field in the database for that functionality?

I am using the Workbench module, which gives draft nodes. If nodes are not published, it will display them in a draft list.

steniya

No results behavior in Views not working when referencing another field after cache clear

4 days 14 hours ago

My Setup:

I am using Drupal 7.41 and Views / Views UI 3.11.

  1. I have a taxonomy named sermon series that includes a field called series image.
  2. I have a content type called sermons that has an image called sermon image and a term reference to the sermon series taxonomy.
  3. Lastly, I have a View called sermons that:
    • pulls in the most recent 1 node from the content type sermons
    • has a relationship to the taxonomy sermon series
    • has the first field in the fields list as the sermon series image (from taxonomy) and is set to "hide from display". The replacement pattern token for this field is [field_sermon_image_2]
    • has the second field in the fields list as the sermon image (from content type) and is set to show in the display.
      • this field has a no results behavior set to the token [field_sermon_image_2]

Expected Behavior:

If the most recent node has an image associated with it, that image will show. If there is no image associated with the node, it will show the image associated with the taxonomy sermon series.

Actual Behavior

When I create a node with the sermon image filled out, everything works as expected and the view shows the sermon image associated with the Node shows.

When I create a node without a sermon image filled out, the view correctly shows the sermon series image associated with the taxonomy sermon series.

Here's where it gets weird. If I create a node without a sermon image filled out, see the view correctly show the sermon series image from the taxonomy, then either clear cache or wait until cache expires, no image shows up at all. I know the fallback is working correctly as even the [field_sermon_image_2] has a no results behavior fallback to a generic image and that's what always shows up.

Through some testing, I found that unpublishing the node, viewing the view, then re-publishing the node will bring the correct image back (at least until the next cache flush).

I'm not sure where to look for this odd behavior. It seems like I have everything setup correctly in my view as I can get the correct images to show up, I just can't get them to show up consistently.

Any advice you can give would be appreciated. Thanks!

Cory Fischer

Crontab job for specific cron activity

4 days 14 hours ago

I'm trying to setup the Job Scheduler so that specific actions can be checked against cron every minute to allow for publishing content on a scheduled basis.

I'm working on part of an Acquia Cloud setup and whilst I've seen that there is documentation about setting up custom jobs, I don't want every cron activity to run, only the job_scheduler_cron, but I don't know how to write the script to only run that code

I've got Ultimate Cron ready to go into a new release but that would have to be rolled into all of the active sites, is there a way of writing a crontab job that only looks for the 'job_scheduler_cron' instead of just modifying the standard Drupal one to once per minute?

Andrew Morris

Make the Buy button send an email only [closed]

4 days 15 hours ago

I need to implement one of the following options, if possible: A) Make the BUY button only send an email or... B) When processing the cart items, only an email to be sent about the purchased items.

I don't need a real credit card purchase on the site, once we get the email we can process the items manually. This is for an organization that don't sell items but gives them away.

Any suggestion would be appreciated.

Pendres Chkednes

Overriding radio button rendering

4 days 15 hours ago

I have a List (text) field on a comment type. This field is required and only one option may be chosen, so a radio button is how it will be rendered. I would now like to change the way the radio buttons are rendered to allow for additional necessary styling. I have never done this before.

Currently each element is styled as such:

<div id="edit-field-list" class="form-radios"><div class="js-form-item form-item js-form-type-radio form-type-radio js-form-item-field-list form-item-field-list"> <input data-drupal-selector="edit-field-list-1" type="radio" id="edit-field-list-1" name="field_list" value="1" class="form-radio"> <label for="edit-field-list-1" class="option">Item #1</label> </div>

But, let's say that I wanted to add an HTML element inside this <div> or move one around. I have created a module which adds a widget for this field type. Once this widget is selected, I have tried modifying the field using a number of different methods, but to no avail. I have been making sure to regularly clear the cache since I have been using the .module file and a template.

I've tried using a template file, radios.html.twig and adding it using various hooks, such as hook_theme_registry_alter() and hook_theme(). I've tried using hook_form_alter().

I have never modified the rendering of an element like this before and the documentation all seems to be different enough from what I am trying to do so as to only add confusion.

Could anyone please tell me how to accomplish this? I'm happy to add clarification as needed.

Additionally, is using a Field Widget the best way to accomplish this? It seems the correct way to me, since I only want it to affect the input element on the comment creation/edit form, but I'm open to being wrong.

Travis

Deleting entities takes forever [closed]

4 days 16 hours ago

I'm facing an issue where deleting entities is extremely slow, taking several minutes to delete just one entity. I am having this problem when trying to delete it programmaticaly, but just discovered it also happens when trying to delete the entity in the drupal backend. This issue does not exist on nodes, just on the custom entities.

I have checked the SQL SHOW FULL PROCESSLIST, but didn't see any deleting process in action.

/** * Delete applications older then $days that have successfully been transfered to MySolution * * @param int $days * @return int Number of applications deleted */ public function cleanup(int $days = 14): int { $storage = \Drupal::entityTypeManager()->getStorage('sollicitaties'); $ids = \Drupal::entityQuery('sollicitaties') ->condition('sync_status', 'done') ->condition('application_date', time() - $days * 24 * 60 * 60, '<') ->execute(); $apps = $storage->loadMultiple($ids); $count = 0; foreach ($apps as $app) { dump('I receive this instantly'); $app->delete(); dump('Receive this several minutes later'); $count++; } return $count; }

If there is any more info you would like me to provide, please feel free. I just don't see any more ways to debug this.

Senna Oudshoorn

Is there a way to add a persistent querystring across multiple pages?

4 days 16 hours ago

I want to add a persistent query string to pages once it is introduced (for the context module to maintain a page layout inside an iframe). At the moment, I'm checking the http referer for the string and redirecting to the current url + query string.
This works fine, except:

  1. It's an extra page load. Not a big issue as it's an admin page inside an iframe that's not used much.
  2. It breaks batch pages. I think I can get around this by checking if arg(0) is "batch" and then add the referer to $_session and then check for it.

This seems really convoluted, hacky and prone to breaking the site for a user if I don't get the session variable deleted straight away.

hook_url_outbound_alter() doesn't work for forms unfortunately so is there a better way?

Niall Murphy