Permalink
Browse files

Updated to Views 2.16

  • Loading branch information...
1 parent fe7791f commit 2dd33b455b666b691afea86f11f50e4dea5d7504 Shawn P. Duncan committed Dec 6, 2011
@@ -170,6 +170,7 @@ class views_handler_field extends views_handler {
$options['empty'] = array('default' => '', 'translatable' => TRUE);
$options['hide_empty'] = array('default' => FALSE);
$options['empty_zero'] = array('default' => FALSE);
+ $options['hide_alter_empty'] = array('default' => TRUE);
return $options;
}
@@ -427,7 +428,13 @@ If you would like to have the characters %5B and %5D please use the html entity
'#type' => 'checkbox',
'#title' => t('Hide if empty'),
'#default_value' => $this->options['hide_empty'],
- '#description' => t('Do not display anything for this field if it is empty. Note that the field label may still be displayed. Check style or row style settings to hide labels for empty fields.'),
+ '#description' => t('Enable to hide this field if it is empty. Note that the field label or rewritten output may still be displayed. To hide labels, check the style or row style settings for empty fields. To hide rewritten content, check the Hide rewriting if empty checkbox.'),
+ );
+
+ $form['hide_alter_empty'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Do not rewrite if empty'),
+ '#default_value' => $this->options['hide_alter_empty'],
);
}
@@ -524,7 +531,7 @@ If you would like to have the characters %5B and %5D please use the html entity
$value = $this->render_altered($alter, $tokens);
}
- if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) {
+ if ((($this->options['hide_empty'] && empty($value)) || ($this->options['hide_alter_empty'] && empty($this->original_value))) && ($value !== 0 || $this->options['empty_zero'])) {
return '';
}
@@ -28,7 +28,7 @@ class views_handler_field_custom extends views_handler_field {
}
function render($values) {
- // Nothing to render.
- return '';
+ // Return the text, so the code never thinks the value is empty.
+ return $this->options['alter']['text'];
}
}
@@ -50,7 +50,9 @@ <h2>The 'table' section</h2>
$data['foo']['table']['group'] = t('Foo');
</pre>
-<h3>Base table</h3>
+The other items in the 'table' section are described in the following sections.
+
+<h3>'base': Base table</h3>
If your table is a base table -- meaning it can be the primary, central table for a View to use, you can declare it to be a base table. This primarily provides UI information so that it can be selected.
For example:
<pre>
@@ -63,7 +65,7 @@ <h3>Base table</h3>
);
</pre>
-The following tags are available in the
+The following items are available in the base section :
<dl>
<dt>field</dt>
<dd>The primary key field for this table. For Views to treat any table as a base table, it <b>must</b> have a primary field. For node this is the 'nid', for users this is the 'uid', etc. <strong>Without a single primary key field (i.e. not a composite key), Views will not be able to utilize the table as a base table.</strong> If your table does not have a primary key field, it is not too difficult to just add a serial field to it, usually.</dd>
@@ -92,7 +94,7 @@ <h3>Base table</h3>
</dd>
</dl>
-<h3>Linking your table to existing base tables</h3>
+<h3>'join': Linking your table to existing base tables</h3>
For Views to use your table, it has to either be a base table, or know how to link to an existing base table. Or sometimes both. Views uses this information to create a path to the base table; when the table is added to the query, Views will walk along this path, adding all tables required into the query.
<div class="help-box" style="text-align:center">
@@ -852,7 +852,7 @@ function views_get_timezone() {
elseif ($GLOBALS['db_type'] == 'mysqli') {
db_query("SET @@session.time_zone = '$offset'");
}
- elseif ($GLOBALS['db_type'] == 'mysql' && version_compare(db_version, '4.1.3', '>=')) {
+ elseif ($GLOBALS['db_type'] == 'mysql' && version_compare(db_version(), '4.1.3', '>=')) {
db_query("SET @@session.time_zone = '$offset'");
}
@@ -1295,6 +1295,17 @@ class views_join {
}
$output = " $this->type JOIN $right_table $table[alias] ON $left_field = $table[alias].$this->field";
+
+ // Load query tokens replacements.
+ $view = views_get_current_view();
+ $replacements = array();
+ if (!empty($view)) {
+ $replacements = $view->substitutions();
+ }
+ else {
+ vpr('The current view is not set, maybe some code missed to execute $view->pre_execute()');
+ }
+
// Tack on the extra.
if (isset($this->extra)) {
if (is_array($this->extra)) {
@@ -1311,6 +1322,9 @@ class views_join {
$join_table = $info['table'] . '.';
}
+ // Apply query token replacements.
+ $info['value'] = str_replace(array_keys($replacements), $replacements, $info['value']);
+
// And now deal with the value and the operator. Set $q to
// a single-quote for non-numeric values and the
// empty-string for numeric values, then wrap all values in $q.
@@ -58,6 +58,11 @@ class view extends views_db_object {
*/
var $current_display;
+ /**
+ * Stores all the views substitutions.
+ */
+ var $substitutions = array();
+
/**
* Constructor
*/
@@ -394,6 +399,16 @@ class view extends views_db_object {
}
}
+ /**
+ * Get's all the substitutions and store them.
+ */
+ function substitutions($reset = FALSE) {
+ if ($reset || empty($this->substitutions)) {
+ $this->substitutions = module_invoke_all('views_query_substitutions', $this);
+ }
+ return $this->substitutions;
+ }
+
/**
* Attach all of the handlers for each type.
*
@@ -764,7 +779,7 @@ class view extends views_db_object {
else {
$items = array();
if ($query) {
- $replacements = module_invoke_all('views_query_substitutions', $this);
+ $replacements = $this->substitutions();
$query = str_replace(array_keys($replacements), $replacements, $query);
$count_query = 'SELECT COUNT(*) FROM (' . str_replace(array_keys($replacements), $replacements, $count_query) . ') count_alias';
@@ -457,14 +457,14 @@ function taxonomy_views_plugins() {
'path' => drupal_get_path('module', 'views') . '/modules/taxonomy',
),
),
-// 'argument default' => array(
-// 'taxonomy_tid' => array(
-// 'title' => t('Taxonomy Term ID from URL'),
-// 'handler' => 'views_plugin_argument_default_taxonomy_tid',
-// 'path' => drupal_get_path('module', 'views') . '/modules/taxonomy',
-// 'parent' => 'fixed',
-// ),
-// ),
+ 'argument default' => array(
+ 'taxonomy_tid' => array(
+ 'title' => t('Taxonomy Term ID from URL'),
+ 'handler' => 'views_plugin_argument_default_taxonomy_tid',
+ 'path' => drupal_get_path('module', 'views') . '/modules/taxonomy',
+ 'parent' => 'fixed',
+ ),
+ ),
);
}
@@ -5,33 +5,34 @@
*/
class views_plugin_argument_default_taxonomy_tid extends views_plugin_argument_default {
+ var $option_name = 'default_taxonomy_tid';
function option_definition() {
$options = parent::option_definition();
- $options['term_page'] = array('default' => TRUE);
- $options['node'] = array('default' => FALSE);
- $options['limit'] = array('default' => FALSE);
- $options['vids'] = array('default' => array());
+ $options[$this->options_name . '_term_page'] = array('default' => TRUE);
+ $options[$this->options_name . '_node'] = array('default' => FALSE);
+ $options[$this->options_name . '_limit'] = array('default' => FALSE);
+ $options[$this->options_name . '_vids'] = array('default' => array());
return $options;
}
function argument_form(&$form, &$form_state) {
- $form['term_page'] = array(
+ $form[$this->option_name . '_term_page'] = array(
'#type' => 'checkbox',
'#title' => t('Load default argument from term page'),
- '#default_value' => $this->argument->options['term_page'],
+ '#default_value' => $this->argument->options[$this->option_name . '_term_page'],
'#process' => array('views_process_dependency'),
'#dependency' => array(
'radio:options[default_action]' => array('default'),
'radio:options[default_argument_type]' => array($this->id)
),
'#dependency_count' => 2,
);
- $form['node'] = array(
+ $form[$this->option_name . '_node'] = array(
'#type' => 'checkbox',
- '#title' => t('Load default argument from node page. Good for related taxonomy blocks.'),
- '#default_value' => $this->argument->options['node'],
+ '#title' => t('Load default argument from node page, thats good for related taxonomy blocks'),
+ '#default_value' => $this->argument->options[$this->option_name . '_node'],
'#process' => array('views_process_dependency'),
'#dependency' => array(
'radio:options[default_action]' => array('default'),
@@ -40,15 +41,15 @@ class views_plugin_argument_default_taxonomy_tid extends views_plugin_argument_d
'#dependency_count' => 2,
);
- $form['limit'] = array(
+ $form[$this->option_name . '_limit'] = array(
'#type' => 'checkbox',
'#title' => t('Limit terms by vocabulary'),
- '#default_value'=> $this->argument->options['limit'],
+ '#default_value'=> $this->argument->options[$this->option_name . '_limit'],
'#process' => array('views_process_dependency'),
'#dependency' => array(
'radio:options[default_action]' => array('default'),
'radio:options[default_argument_type]' => array($this->id),
- 'edit-options-node' => array(1)
+ 'edit-options-default-taxonomy-tid-node' => array(1),
),
'#dependency_count' => 3,
);
@@ -59,39 +60,34 @@ class views_plugin_argument_default_taxonomy_tid extends views_plugin_argument_d
$options[$voc->vid] = check_plain($voc->name);
}
- $form['vids'] = array(
- '#prefix' => '<div><div id="edit-options-vids">',
+ $form[$this->option_name . '_vids'] = array(
+ '#prefix' => '<div><div id="edit-options-default-taxonomy-tid-vids-wrapper">',
'#suffix' => '</div></div>',
'#type' => 'checkboxes',
'#title' => t('Vocabularies'),
'#description' => t('If you wish to limit terms for specific vocabularies, check them; if none are checked, all terms will be included.'),
'#options' => $options,
- '#default_value' => isset($this->argument->options['vids']) ? $this->argument->options['vids'] : array(),
+ '#default_value' => isset($this->argument->options[$this->option_name . '_vids']) ? $this->argument->options[$this->option_name . '_vids'] : array(),
'#process' => array('expand_checkboxes', 'views_process_dependency'),
'#dependency' => array(
'radio:options[default_action]' => array('default'),
'radio:options[default_argument_type]' => array($this->id),
- 'edit-options-node' => array(1),
- 'edit-options-limit' => array(1)
+ 'edit-options-default-taxonomy-tid-limit' => array(1),
+ 'edit-options-default-taxonomy-tid-node' => array(1),
),
'#dependency_count' => 4,
);
}
- function options_submit(&$form, &$form_state, &$options) {
- // Clear checkbox values.
- $options['vids'] = array_filter($options['vids']);
- }
-
function get_argument() {
// Load default argument from taxonomy page.
- if (!empty($this->argument->options['term_page'])) {
+ if (!empty($this->argument->options[$this->option_name . '_term_page'])) {
if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
return arg(2);
}
}
// Load default argument from node.
- if (!empty($this->argument->options['node'])) {
+ if (!empty($this->argument->options[$this->option_name . '_node'])) {
foreach (range(1, 3) as $i) {
$node = menu_get_object('node', $i);
if (!empty($node)) {
@@ -100,11 +96,11 @@ class views_plugin_argument_default_taxonomy_tid extends views_plugin_argument_d
}
// Just check, if a node could be detected.
if ($node) {
- if (!empty($this->argument->options['limit'])) {
+ if (!empty($this->argument->options[$this->option_name . '_limit'])) {
$tids = array();
// Filter by vid.
foreach ($node->taxonomy as $tid => $term) {
- if (!empty($this->argument->options['vids'][$term->vid])) {
+ if (!empty($this->argument->options[$this->option_name . '_vids'][$term->vid])) {
$tids[] = $tid;
}
}
@@ -116,6 +112,13 @@ class views_plugin_argument_default_taxonomy_tid extends views_plugin_argument_d
}
}
}
+
+ // If the current page is a view that takes tid as an argument,
+ // find the tid argument and return it.
+ $views_page = views_get_page_view();
+ if ($views_page && isset($views_page->view->argument['tid'])) {
+ return $views_page->view->argument['tid']->argument;
+ }
}
}
@@ -3,9 +3,9 @@ description = Create customized lists and queries from your database.
package = Views
core = 6.x
-; Information added by drupal.org packaging script on 2011-11-02
-version = "6.x-2.14"
+; Information added by drupal.org packaging script on 2011-11-14
+version = "6.x-2.16"
core = "6.x"
project = "views"
-datestamp = "1320268836"
+datestamp = "1321305946"
@@ -5,9 +5,9 @@ package = "Views"
dependencies[] = views
core = 6.x
-; Information added by drupal.org packaging script on 2011-11-02
-version = "6.x-2.14"
+; Information added by drupal.org packaging script on 2011-11-14
+version = "6.x-2.16"
core = "6.x"
project = "views"
-datestamp = "1320268836"
+datestamp = "1321305946"
@@ -4,9 +4,9 @@ package = Views
core = 6.x
dependencies[] = views
-; Information added by drupal.org packaging script on 2011-11-02
-version = "6.x-2.14"
+; Information added by drupal.org packaging script on 2011-11-14
+version = "6.x-2.16"
core = "6.x"
project = "views"
-datestamp = "1320268836"
+datestamp = "1321305946"

0 comments on commit 2dd33b4

Please sign in to comment.