Friday, November 30, 2018

DRUPAL 8: Block of nodes referencing the current node


we have  contentype Publication and a contenttype Article
The contentype Article references the contenttype Publication
(the referencing field is f.i.  field_editie_s )
Multiple articles reference one Publication

Article --- fied_editie_s ---> Publication

Queste
Create a block view on anny  Publication page listing all nodes referencing that page


1.  create view
Administration > Structure > Views > Add a New View
1.1 Create a block view
1.2 Filter on the child element: Article

1.3 add relationship

choose: 'content referenced from field_editie_s'
click: 'add and configure'
select 'require this relationship'
save

1.4 add contextual filter

under relationship choose: field_editie_s: content
choose ID (content)
click 'add and configure contextual filter
select 'provide default value'
select 'Content ID from URL'
click save


test it by inserting a node is from a publication node in the preview with contectual filters

now show the block on the publicatiosn pages

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:

Captcha
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.)

Re-Capcha
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.
Honey


Honeypot
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
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)

Http:BL
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
type
Drupal
::configFactory()->getEditable('system.menu.devel')->delete();
push enter
some message appears like => Drupal\Core\Config\Config {#8157}
type
exit

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


EDIT sept 2023 (I stumbled onto my own blog running into this problem once again)

In drupal 9 use

php -d memory_limit=-1 vendor/drush/drush/drush config:delete 

system.menu.devel










edited sept 2023




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
(/admin/config/regional/language)
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>