Nested select with Drupals DataBase interface

I have the following SQL query and need to translate it to the drupal API:

SELECT
  *,
  (SELECT COUNT(*)
    FROM newsletter
    WHERE email = pupils.email
  ) AS newsletter_flag
FROM 
  memberdata.pupils
LEFT JOIN
  memberdata.pupil_profiles
ON
  memberdata.pupils.id = memberdata.pupil_profiles."pupils.id"
WHERE
  pupils.status != 'u'
ORDER BY
  pupils.timestamp DESC
LIMIT 10;

Background: There is a table with pupils (some basic info including mail adress) and a table newsletter containing the email addresses of pupils that registered for the newsletter. I need a list of all pupil with their fields and additionally the field newsletter_flag, indicating if the pupils email adress is in the newsletter table or not. Additionally I need a join to another table with primary foreign key. I’ve come this far:

$query = Database::getConnection('default', 'for_migration')
->select('memberdata.pupils', 'pupils')
->fields('pupils', array('id', 'firstname', 'lastname', 'birthday', 'gender'))
->condition('status', 'u', '!=')
->range(0, 10)
->orderBy('pupils.timestamp', 'DESC');

$alias = $query->leftjoin('newsletter', 'nl', 'pupils.email = nl.email');
$query->addExpression("COUNT($alias.email)", 'newsletter_flag');

But it does not what I want (the pupil_profiles join is still missing of course, but the newsletter flag is the bigger problem I guess). The source database is a PostgreSQL one and the query itself is part of a Migration subclass, in which a MigrateSourceSQL is used as source. Therefore the query needs to be a SelectQueryInterface.

how to debug drupal_http_request

I’m working on a module that takes a form submission and posts it to a rest api, using the webform validator module’s hooks. I’m trying to debug what’s going wrong, and I have the following code, which correctly displays $data and $url but nothing for $result (I’m assuming it’s null?).

I’m new to drupal and I wonder what I’m doing wrong, with the http_request that it comes back null, or what else I can do to debug.

      $options = array( data => $data,
                        method => 'POST');
      //verify $data
      $errors['item_2'] = $data;
      $errors['item_3'] = $url


      $result = drupal_http_request($url, $options);


      // display the returned JSON result as a form error
      $errors['item_1'] = json_decode($result);

How do I register a views_plugin_display_page path with Drupal?

I’m creating a new Views display plugin via extending views_plugin_display_page

The problem that I’m having is that the path I set for the display via the UI is not registered with Drupal, so Drupal cannot find it. I’ve looked through numerous classes extending the same plugin and none of them helped.

<?php

/**
 * The plugin that handles dashlet displays.
 */
class views_in_dashlets_plugin_display_page extends views_plugin_display_page {
  function option_definition() {
    $options = parent::option_definition();

    $options['is_fullscreen'] = array('default' => '');
    $options['is_active'] = array('default' => '');
    $options['weight'] = array('default' => '');
    $options['id'] = array('default' => '');

    return $options;
  }

  function has_path() { return TRUE; }

  /**
   * Provide the summary for page options in the views UI.
   *
   * This output is returned as an array.
   */
  function options_summary(&$categories, &$options) {
    // It is very important to call the parent function here:
    parent::options_summary($categories, $options);

    $is_fullscreen = $this->get_option('is_fullscreen');
    $is_active = $this->get_option('is_active');
    $weight = $this->get_option('weight');

    $categories['dashlet_view'] = array(
      'title' => t('CiviCRM Dashlet settings'),
      'column' => 'second',
      'build' => array(
        '#weight' => -11,
      ),
    );

    $options['is_fullscreen'] = array(
      'category' => 'dashlet_view',
      'title' => t('Is this dashlet fullscreen?'),
      'value' => empty($is_fullscreen) ? t('None') : $is_fullscreen,
    );

    $options['is_active'] = array(
      'category' => 'dashlet_view',
      'title' => t('Is this dashlet active?'),
      'value' => empty($is_active) ? t('None') : $is_active,
    );

    $options['weight'] = array(
      'category' => 'dashlet_view',
      'title' => t('Dashlet weight'),
      'value' => empty($weight) ? t('None') : $weight,
    );

  }

  /**
   * Provide the default form for setting options.
   */
  function options_form(&$form, &$form_state) {
    // It is very important to call the parent function here:
    parent::options_form($form, $form_state);

    switch ($form_state['section']) {
      case 'is_fullscreen':
        $form['#title'] .= t('Is fullscreen?');
        $form['is_fullscreen'] = array(
          '#type' => 'radios',
          '#required' => TRUE,
          '#options' => array('Yes' => t('Yes'), 'No' => t('No')),
          '#title' => t("Is this dashlet fullscreen?"),
        );
        break;

      case 'is_active':
        $form['#title'] .= t('Is active?');
        $form['is_active'] = array(
          '#type' => 'radios',
          '#required' => TRUE,
          '#options' => array('Yes' => t('Yes'), 'No' => t('No')),
          '#title' => t("Is this dashlet active?"),
        );
        break;

      case 'weight':
        $form['#title'] .= t('Dashlet weight');
        $form['weight'] = array(
          '#type' => 'textfield',
          '#required' => TRUE,
          '#title' => t("What is the weight of this dashlet?"),
        );
        break;
    }
  }

  function options_submit(&$form, &$form_state) {
    // It is very important to call the parent function here:
    parent::options_submit($form, $form_state);

    switch ($form_state['section']) {
      case 'is_fullscreen':
        $this->set_option('is_fullscreen', $form_state['values']['is_fullscreen']);
        break;
      case 'is_active':
        $this->set_option('is_active', $form_state['values']['is_active']);
        break;
      case 'weight':
        $this->set_option('weight', $form_state['values']['weight']);
        break;
    }
  }

  function validate() {

    $errors = parent::validate();
    return $errors;
  }

   /*
   * We have to run token replacement before the arguments are used.
   */
  function pre_execute() {
    // Call the parent setup function so we do not lose data.
    parent::pre_execute();
  }


   /*
   * The display block handler returns the structure necessary for a block.
   */
  function execute() {
    // Prior to this being called, the $view should already be set to this
    // display, and arguments should be set on the view.

    parent::execute();
  }

 /**
  * Provide a preview
  */
  function preview(){

    return $this->view->render();
  }

}

Cannot alter title on user profile page

I’ve created a custom module called renameprofile to alter the title on my user page, but it doesn’t seem to be working. Any idea what is causing this issue? Btw this is on the ?q=user page.

renameprofile.module

<?php
function renameprofile_page_alter() {  

  global $user;  

  if(drupal_get_title() === isset($user->name)) {  
    drupal_set_title('My Sharecab');  
  }  
}
?>

renameprofile.info

name = Rename user profile page title
description = This module renames the profile page title
core = 7.x

Taxonomy view links do not link to page

I’ve created a view that displays the node count values for taxonomy terms. After implementing it into my Drupal site, I found that I cannot access the taxonomy term page from the links provided, all it does is redirect me to the home page.

My settings are as follows:

enter image description here

It produces the following view, and I click the links I cannot access the taxonomy term page:

enter image description here

I’ve tested the links manually and they work, they are:

/?q=tags/expansion
/?q=tags/opportunity
/?q=tags/press
/?q=tags/product-update

Any reasons why this isn’t working as expected? I’d greatly appreciate your help.

UPDATE #1 – rendered output

<ul class="views-summary">
      <li><a href="/home/">expansion</a>
              (2)
          </li>
      <li><a href="/home/">opportunity</a>
              (4)
          </li>
      <li><a href="/home/">press</a>
              (1)
          </li>
      <li><a href="/home/">product update</a>
              (1)
          </li>
    </ul>

UPDATE 2 – Configure field: Taxonomy term: Name

enter image description here

UPDATE 3 – Configure contextual filter: Taxonomy term: Name

enter image description here

View AJAX Refresh causing multiple refreshes

In attempting an AJAX refresh on several views contained in separate blocks on a single page, I seem to be coming across a problem. This is running on D7.34

The idea is for the page to contain 4 blocks, each with a view sorting by random – then using a simple click() on the block title to
activate a refresh of any given view allowing the user to view a new random item. I am using the common:

var selector = '.view-dom-id-' + dom_id;
jQuery(selector).triggerHandler('RefreshView');

to achieve this, which works perfectly. The trouble I am having is in increasing multiples of refreshes:

clicking on one view refresh does refresh the view, but it seems to create a counter, when a different view
is refreshed, that second view refreshes twice. Then going back to the first, the view would refresh 3 times, and so on.
It doesn’t happen if clicking on the same view multiple times – in this case it only refreshes once as expected, it only
occurs when switching between refreshing different views, however it continues to “count” these refreshes which then effect
the number of times a different view is refreshed when the other refresh is triggered.

  • I have confirmed that the selector is correct and obtains the unique dom_id for that view
  • I have confirmed that the call jQuery(selector).triggerHandler(‘RefreshView’); only occurs once per click
  • this occurs in Drupal.Behaviours, drupal_add_js, and straight JS added to a tpl file – they all “work” but with the same refresh issue
  • I have used once() in the call as well with no perceived effect

It seems like when the triggerHandler triggers the refresh, the view itself is refreshing multiple times for reasons I can’t seem to
figure out. I have tried dozens of permutations now without any change in behaviour. I can’t post of all the code from my attempts, but here
is the last attempt which “works” but still refreshes multiple times – this is a straight JS addition to page.tpl, layed out for easier reading:

<script>
  jQuery(document).ready(function()
  {
    jQuery('#block-views-random-cat-block h2').click(function()
    {
      jQuery.each(Drupal.views.instances, function(i, view)
      {
        if (view.settings.view_name == "random_cat")
        {
          var selector = '.view-dom-id-' + view.settings.view_dom_id;
          jQuery(selector).triggerHandler('RefreshView');
        }
      });
    });

    jQuery('#block-views-random-dog-block h2').click(function()
    {
      jQuery.each(Drupal.views.instances, function(i, view)
      {
        if (view.settings.view_name == "random_dog")
        {
          var selector = '.view-dom-id-' + view.settings.view_dom_id;
          jQuery(selector).triggerHandler('RefreshView');
        }
      });
    });
  });
</script>

If I limit the page to one view only, it seems to work fine – it’s only in the fact that there are multiple views that I see this effect.

Why's my icecream jelly like?

I was following this recipe to make some French Vanilla Icecream. I had to prepare some home-made cream from scratch, for I was very short on ingredients. After completing the cooking, during the freezing time, the mix became more jelly like – wobbly and rubbery. I kept stirring and breaking the mixture every 30 mins for the past 4 Hrs. I’ve followed the recipe as accurate as I could, but the home-made cream might be the trouble. Not only is it not setting, but is still in a runny consistency. Could it be the case? Is there anything that can be done right now?