I have created a custom Entity for blogs. I am not using nodes. The way my entity works is that all languages are stored in a single Entity. The only way to determine if a language has been submitted is if there is a title for that language. As the title is a field, the data for the titles is stores in {field_data_field_blog_title}. The way to determine whether an English version of the Entity in question exists, is to check if there is a row in the {field_data_field_blog_title} table for the current Entity ID and language.

So in hook_views_data_alter() I have added the following code:

function ba_views_data_alter(&$data)
{
	$data['j_blog']['language'] = array
	(
		'title' => t('Blog language'),
		'help' => t('The language of the blog'),
		'filter' => array
		(
			'handler' => 'views_handler_filter_ba_blog_language',
		),
	);
}

And in my handler, views_handler_filter_ba_blog_language.inc, I have the following:

<?php

/**
* Filter by current_language (bundle)
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_ba_blog_language extends views_handler_filter
{
	function value_form(&$form, &$form_state)
	{
		parent::value_form($form, $form_state);
		
		$languages = language_list();
		foreach($languages as $l)
		{
			$options[$l->language] = $l->name;
		}
		$options['current'] = t('Current language');
		
		$form['blog_language'] = array
		(
			'#type' => 'radios',
			'#title' => t('Language'),
			'#options' => $options,
		);
	}

	function value_submit($form, &$form_state)
	{
		$form_state['values']['options']['value'] = $form_state['values']['options']['blog_language'];
	}

	function query()
	{
		global $language;
		
		if (empty($this->value))
		{
			return;
		}
		$this->ensure_my_table();
		
		$value = ($this->value == 'current') ? $language->language : $this->value;

		// THIS IS WHERE I WANT TO ADD MY JOIN
	}
}

Basically, I want to force something like this in my query:
JOIN {field_data_field_blog_title} ON {field_data_field_blog_title}.id = blog.id AND {field_data_field_blog_title}.language = :language

By forcing a join where a row exists with the language, it will ensure that only blogs with the given language are returned.

The problem is that I don't know how to add my table with a join. Can someone give me some assistance with this?

Comments

jaypan’s picture

Issue summary: View changes
Status: Active » Fixed

Well, I never received acknowledgement of this post, but if anyone else is ever looking to do this, I received help on how to do this here: https://drupal.org/node/2049051

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.