Tuesday, September 4, 2018

Drupal 8 And Spam....

The most annoying thing on this web is those people running around and sending you long russian texts about dehydrators or viagra or whatever.... The web is like a city where half the population consists of naked or partly naked whores, the other half are salesman trying to sell you stuff you don't need or did not even know it existed and the last 1 percent or so is real information.

Some of my sites keep being attacked by spambots posting this nonsense. I leaned heavily on the Aquia service Mollom, which was a great module, but that service unexplainably stopped in april 2018.

So, what to use on Drupal 8 sites to stop this useless salesy bantering and pointless digital screaming on our sites:

The first module you can deploy is captcha. This is the simple Stop and frisk module to see if you are human.
ImageCaptcha, is the Stop and frisk and ask some more questions version of the above. You have to interpret an image before you can send in a form. (I always find this one very annoying.)

This is the user friendly update of the above two modules, it simply asks you to check a box  titled: I am not a robot.
As long as the artificial intelligence is on the current level this module will suffice.

This is a module that requires no user interaction at all, so it is my first choice to use. Depending on the user interaction times it decides whether you are a human or a bot. Furthermore it does a hide and seek action with fields that the bot thinks it needs to answer but the humans do not see. This module worked great, but of course the bot priogrammers are not stupid so they are finding ways to fool this one......

Antibot uses some of the same techniques as honeypot, user interaction time and hidden fields, but seems to when honeypot... And the other way around. It is purely based on javascript/css, but prohibits users without javascript to send forms. (So you have to make an extra form for users without javascript with one of the above modules connected and another mailadres attached on which you will receive the old amount of spam)

This one is not yet available for Drupal 8, but it seems to provide the same functionality as Mollom did.

Human Presence
This one is rather affordable for drupal: 5 euros per month and seems to provide the same functionality as Mollom did, but also seems to use more advanced technologies... (Or they know how to present their products in a sexy way). I did not try this one out yet, and update here as soon as I did...

Thursday, November 23, 2017

Drupal 8: Add custom classes to pages using a field value

I have many projects where one special page needs a totally different design than the other pages. So in the css you need a different setup, for instance no right bar with a menu.
I always write the pathname and the node-id to the body classes, but oftentimes you need to change the path of the pages, or you want to add other similarily designed pages to the set and then you need to add those path-classes to the css also, and this all apart from the fact that paths and node ids sometimes diverge in the development environment and the production environment.

The class is strong with this one
So I made a very simple theme preprocess function which simply writes the field value of a custom
field to the bodyclass. This way you can add pages to this special design by simply writing the same class value in that field.
I added a text field 'field_bodyclass' tot the contentypes, and hidden it in the visibility settings for these contentypes. And using this preproces fs function:

function MyModuleOrMyTheme_preprocess_html(&$variables) {
  $node = \Drupal::routeMatch()->getParameter('node');
  if($node) {
     $variables['attributes']['class'][] = $node->field_bodyclass->value;
 .... other code.....

Sunday, April 10, 2016

Drupal 8 - Unable to install Devel, system.menu.devel already exists in active configuration.

To protect and to serve....
Well life is shit sometimes.
I migrated a Drupal 6 site to Drupal 8.
All I wanted is to install devel and then develop like mad.
But  Devel won't install. It says:
Unable to install Devel, system.menu.devel already exists in active configuration.
Diving into Drupal 8 I solved it, but I must honestly tell you that I do not really understand all consequences. It has something to do with the dependencies. The old site had Devel running, so maybe that caused the problem....

Solution (providing you have drush installed)
Open terminal and navigate to the root folder of your website
$ drush php
Wait till the drush php prompt (>>>) appears
push enter
some message appears like => Drupal\Core\Config\Config {#8157}

After that I had no problem installing Devel (and develop like hell....)

Wednesday, January 7, 2015

Drupal 7 - changing overall site language

So, as I am used to read and install everything in english, half of the sites we build are actually only in Dutch. That is, overall site language including the admin interface. I rather like to have the admin interface in english, cause you can more easily google the web on any problems using the english system messages.
So then: All the time I start drushing a site install, enabling my module sets, running some features, focusing on the technical design and the custom functionalities we have to build,  and then suddenly realize that the whole lot has to be in Dutch. Or German. Or Latin, or French or Klingon.

Let's all Klingon

So, how did we change the site language again?

1. Enable the Locale module
2. Download Localization update
3. Enable Localization update
(didn't expect that eh?)
4. Go to Configuration > Languages
5. Add the language of your choice
(The module will then import the Drupal translation files for the core and all installed modules)
6. Change the default language and Voila, as the French say, your site language has changed.

Monday, October 27, 2014

Drupal - Rebuild permissions

Because I always forget where to find the rebuild permissions button in Drupal, this is my reminder

drupal 6   /admin/content/node-settings/rebuild
drupal 7   /admin/reports/status/rebuild

I actually do not have permission to use this image....

Thursday, October 16, 2014

Drupal 7 - apache solr - how to add an total results count to your results

Somehow I naturally expected a total results entry somewhere in the arrays solr sends me, but I could not find it.
So, what is so weird about wanting to show the number of results?

The solution is of course rather simple, like everything is simple in hindsight, but nevertheless it took me hours to come up with it. Mostly because I was googling through endless hits more or less about this problem and maybe I should try to catch some more sleep....

The solution is to lift the value from the GLOBALS array.  Add  $GLOBALS['pager_total_items'][0] somewhere to a variable in a preprocess hook or simply print in in your template file like thus:

<div class="counter"><?php print $GLOBALS['pager_total_items'][0].' results'; ?></div>

Thursday, September 18, 2014

Drupal 7 - Picture - Adding captions to responsive images

I've setup an D7 site (a D6 upgrade) with Picture and Breakpoint where I want to show a caption for some of the images. In the  D6 version used the title attributes as captions for some of the images with a phptemplate_imagecache function. (Depending on the image style used.)

Oh caption, my caption
There are some modules (https://www.drupal.org/project/image_caption, https://www.drupal.org/project/image_field_caption, https://www.drupal.org/project/caption_filter, etc) which give you the possibility of adding a caption field, but as I do not want to build another module to convert all existing title tags to these caption attributes, and also need a solution for non javascript browsers, I needed something more basic.

Based on the specific imagestyle or specific picture mapping, decide to render or not render a caption. The content of the caption is the content of the title attribute.

Add a theme function to your theme's template.php
The idea is to simply override the theming function in picture (which is the module I use for my responsive images)

// this theming function assumes that the picture module is installed
function THEMENAME_picture($variables) {
  // first produce the  standard picture output
  // we only add titles to the images where a specific picture mapping is defined
  if (array_key_exists('breakpoints', $variables) && array_key_exists('title', $variables)){
     if ($variables[breakpoints]['custom.user.normal']['1x'][image_style] =='rsp_adviesplaatjecustom_user_normal_1x'){
        if ($variables['title'] !=''){
           $output=$output.'<div class="image-caption"><div class="image-caption-text">'.$variables['title'].'</div></div>';
  return $output;