diff --git a/active_translation.module b/active_translation.module index 393950c..0e3269d 100644 --- a/active_translation.module +++ b/active_translation.module @@ -303,12 +303,16 @@ function active_translation_rebuild_on_submit() { * * Rewrite node queries so language selection options are enforced. */ -function active_translation_db_rewrite_sql($query, $primary_table, $primary_key) { +function active_translation_db_rewrite_sql($query, $primary_table, $primary_key, $args = array()) { global $language; switch ($primary_table) { case 'n': case 'node': + // Disable language conditions for views. + // If you want active_translation require the view 'relationship'. + if (array_key_exists('view', $args)) return; + // STOLE THISE FROM I18N, NEED TO MAKE SURE THEY'RE STILL VALID. // Ignore the admin pages. @@ -331,3 +335,13 @@ function active_translation_db_rewrite_sql($query, $primary_table, $primary_key) return $result; } } + +/** + * Implementation of hook_views_api(). + */ +function active_translation_views_api() { + return array( + 'api' => '2.0', + 'path' => drupal_get_path('module', 'active_translation') .'/includes', + ); +} diff --git a/includes/active_translation.views.inc b/includes/active_translation.views.inc new file mode 100644 index 0000000..63257cc --- /dev/null +++ b/includes/active_translation.views.inc @@ -0,0 +1,109 @@ + 'active_translation', + 'field' => '***CURRENT_LANGUAGE***', + 'left_field' => 'nid', + ); + + $data['active_translation']['translation'] = array( + 'group' => t('i18n'), + 'title' => t('Active Translation'), + 'help' => t('Relate node to the active translation current language field'), + 'relationship' => array( + 'relationship table' => 'node', + 'relationship field' => 'nid', + 'base' => 'active_translation', + 'base field' => '***CURRENT_LANGUAGE***', + 'handler' => 'active_translation_handler_relationship_node', + 'label' => t('Active translation'), + ), + ); + + if (module_exists('flag')) { + // @see flag.views.inc flag_views_data_alter(). + foreach (array_keys(flag_fetch_definition()) as $flag_type) { + $flag = flag_flag::factory_by_content_type($flag_type); + $info = $flag->get_views_info(); + + if ($info['views table'] == 'node') { + // Add the flag relationship. + $data['active_translation']['flag_content_rel'] = array( + 'group' => t('Flags'), + 'title' => $info['title'] . ' ' . t('translated'), + 'help' => $info['help'], + 'relationship' => array( + 'flag type' => $flag_type, + 'handler' => 'flag_handler_relationship_content', + 'label' => t('flag - translated'), + 'base' => 'flag_content', + 'base field' => 'content_id', + 'relationship field' => 'atid', + ), + ); + + // Add the flag counter relationship. + $data['active_translation']['flag_count_rel'] = array( + 'group' => t('Flags'), + 'title' => $info['counter title'] . ' ' . t('translated'), + 'help' => $info['counter help'], + 'relationship' => array( + 'flag type' => $flag_type, + 'handler' => 'flag_handler_relationship_counts', + 'label' => t('counter'), + 'base' => 'flag_counts', + 'base field' => 'content_id', + 'relationship field' => 'atid', + ), + ); + } + } + } + + if (module_exists('nodequeue')) { + // @see nodequeue.views.inc nodequeue_views_data_alter(). + $data['active_translation']['nodequeue_rel'] = array( + 'group' => t('Nodequeue'), + 'title' => t('Queue - translated'), + 'help' => t('Create a relationship to a nodequeue.'), + 'relationship' => array( + 'handler' => 'active_translation_handler_relationship_nodequeue', + 'base' => 'nodequeue_nodes', + 'base field' => 'nid', + 'relationship field' => 'atid', + 'label' => t('queue'), + ), + ); + } + + return $data; +} + +/** +* Implementation of hook_views_handlers(). +*/ +function active_translation_views_handlers() { + $handlers = array( + 'info' => array( + 'path' => drupal_get_path('module', 'active_translation') . '/includes', + ), + 'handlers' => array( + 'active_translation_handler_relationship_node' => array( + 'parent' => 'views_handler_relationship', + ), + ), + ); + if (module_exists('nodequeue')) { + $handlers['handlers']['active_translation_handler_relationship_nodequeue']['parent'] = 'nodequeue_handler_relationship_nodequeue'; + } + + return $handlers; +} diff --git a/includes/active_translation.views_default.inc b/includes/active_translation.views_default.inc new file mode 100644 index 0000000..4afb12c --- /dev/null +++ b/includes/active_translation.views_default.inc @@ -0,0 +1,140 @@ +name = 'at_frontpage'; + $view->description = 'Emulates the default Drupal front page with active translation.'; + $view->tag = 'default'; + $view->view_php = ''; + $view->base_table = 'node'; + $view->is_cacheable = FALSE; + $view->api_version = 2; + $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ + $handler = $view->new_display('default', 'Default', 'default'); + $handler->override_option('relationships', array( + 'translation' => array( + 'label' => 'Active translation', + 'required' => 1, + 'id' => 'translation', + 'table' => 'active_translation', + 'field' => 'translation', + 'relationship' => 'none', + ), + )); + $handler->override_option('sorts', array( + 'sticky' => array( + 'id' => 'sticky', + 'table' => 'node', + 'field' => 'sticky', + 'order' => 'DESC', + ), + 'created' => array( + 'id' => 'created', + 'table' => 'node', + 'field' => 'created', + 'order' => 'DESC', + 'relationship' => 'none', + 'granularity' => 'second', + ), + )); + $handler->override_option('filters', array( + 'promote' => array( + 'id' => 'promote', + 'table' => 'node', + 'field' => 'promote', + 'operator' => '=', + 'value' => '1', + 'group' => 0, + 'exposed' => FALSE, + 'expose' => array( + 'operator' => FALSE, + 'label' => '', + ), + ), + 'status' => array( + 'id' => 'status', + 'table' => 'node', + 'field' => 'status', + 'operator' => '=', + 'value' => '1', + 'group' => 0, + 'exposed' => FALSE, + 'expose' => array( + 'operator' => FALSE, + 'label' => '', + ), + ), + )); + $handler->override_option('access', array( + 'type' => 'none', + 'role' => array(), + 'perm' => '', + )); + $handler->override_option('cache', array( + 'type' => 'none', + )); + $handler->override_option('header_format', '1'); + $handler->override_option('footer_format', '1'); + $handler->override_option('empty_format', '1'); + $handler->override_option('use_pager', '1'); + $handler->override_option('row_plugin', 'node'); + $handler->override_option('row_options', array( + 'teaser' => 1, + 'links' => 1, + )); + $handler = $view->new_display('page', 'Page', 'page'); + $handler->override_option('path', 'frontpage'); + $handler->override_option('menu', array( + 'type' => 'none', + 'title' => '', + 'description' => '', + 'weight' => 0, + 'name' => 'navigation', + )); + $handler->override_option('tab_options', array( + 'type' => 'none', + 'title' => '', + 'description' => '', + 'weight' => 0, + 'name' => 'navigation', + )); + $handler = $view->new_display('feed', 'Feed', 'feed'); + $handler->override_option('title', 'Front page feed'); + $handler->override_option('style_plugin', 'rss'); + $handler->override_option('style_options', array( + 'mission_description' => 1, + 'description' => '', + )); + $handler->override_option('row_plugin', 'node_rss'); + $handler->override_option('row_options', array( + 'item_length' => 'default', + )); + $handler->override_option('path', 'rss.xml'); + $handler->override_option('menu', array( + 'type' => 'none', + 'title' => '', + 'description' => '', + 'weight' => 0, + 'name' => 'navigation', + )); + $handler->override_option('tab_options', array( + 'type' => 'none', + 'title' => '', + 'description' => '', + 'weight' => 0, + 'name' => 'navigation', + )); + $handler->override_option('displays', array( + 'default' => 'default', + 'page' => 'page', + )); + $handler->override_option('sitename_title', '1'); + + return array($view->name => $view); +} diff --git a/includes/active_translation_handler_relationship_node.inc b/includes/active_translation_handler_relationship_node.inc new file mode 100644 index 0000000..5071566 --- /dev/null +++ b/includes/active_translation_handler_relationship_node.inc @@ -0,0 +1,15 @@ +language); + $this->ensure_my_table(); + $join = new views_join(); + $join->construct('active_translation', $this->table_alias, 'nid', $field, array(), 'INNER'); + $this->query->ensure_table('active_translation', $this->relationship, $join); + } +} diff --git a/includes/active_translation_handler_relationship_nodequeue.inc b/includes/active_translation_handler_relationship_nodequeue.inc new file mode 100644 index 0000000..ef1d340 --- /dev/null +++ b/includes/active_translation_handler_relationship_nodequeue.inc @@ -0,0 +1,40 @@ +definition = array( + 'table' => 'nodequeue_nodes', + 'field' => 'nid', + 'left_table' => 'active_translation', + 'left_field' => 'atid', + ); + + if (!empty($this->options['required'])) { + $join->definition['type'] = 'INNER'; + } + + if (!empty($this->options['limit'])) { + $join->definition['extra'] = array(array( + 'field' => 'qid', + 'value' => array_filter($this->options['qids']), + 'numeric' => TRUE, + )); + } + + $join->construct(); + + $alias = $join->definition['table'] . '_' . $join->definition['left_table']; + + $this->query->ensure_table('active_translation'); + $this->alias = $this->query->add_relationship($alias, $join, 'nodequeue_nodes', $this->relationship); + } +}