Articles

Place Google Adsense or html/js code snippets into View results

When it comes to monetizing traffic on your websites, placing the Google Adsense code snippets has always been easy. Usually, the process is simple: the ad's code snippet has to be put into content block and then placed anywhere on site, or just hardcoded directly into site's templates.

However, if you have a list of posts built with a regular view and you want to periodically show some ad between them, the task requires some coding. As for me, it has always been a case, because I could not find any suitable simple Drupal module that would resolve this task.

So after all, in order to get rid of routine coding, I created a module called Views Row Insert.

Tools

The Issue

Some specific tasks on Drupal-based API development which involves processing third party data like incoming ajax calls or POST requests may require that you will have to deal with these POST params directly somewhere within your drupal code but they might be not be available at the point due to other modules acitions or whatever.

By default, when data flow containing POST or GET values comes to page callback function defined in hook menu, those variables are usually available and accessible.

Insert, replace or delete rows from a view display results programmatically

In some cases, you may want to dynamically insert a new row into your view results, or replace an existing one with the different entity.

Html markup example with the wrapped rows result
This article shows the process of creating custom view style plugin as a module for Drupal 7.x. The module modifies views output, it combines a user defined number of rows into sets, wrapped by chosen elements and attributes.
How to create custom view fields programmatically: Unfiltered header area field and content field plugins

If you ever tried to add custom styles or custom javascript to Unfiltered text field in Drupal 8 view, you had probably noticed that the style/script tags are always stripped out. Here is the example of how to programmatically create the unfiltered view header area custom field and the unfiltered view content field plugins where you can use <style> or <script> tags. 

Access entity field with custom token

Once working on the Drupal project, I faced a situation when I had to access the current loaded node fields in Rules. To be more specific, the content type had an email field and attached entity form. The task was to send the email using Rules to the email address which was set in a node field after submission the attached entity form.

The problem is that the only available fields I had were entity form fields and no fields from the node. So I came up to some custom and quick solution of creating custom Token which would contain the data from the node field.