Commit 0932270a authored by alexpott's avatar alexpott

Issue #2048897 by Les Lim: Fixed Views Grid style: tokens not replaced in...

Issue #2048897 by Les Lim: Fixed Views Grid style: tokens not replaced in custom row/column classes.
parent 1aebdc73
......@@ -104,4 +104,28 @@ public function buildOptionsForm(&$form, &$form_state) {
}
}
/**
* Return the token-replaced row or column classes for the specified result.
*
* @param int $result_index
* The delta of the result item to get custom classes for.
* @param string $type
* The type of custom grid class to return, either "row" or "col".
*
* @return string
* A space-delimited string of classes.
*/
public function getCustomClass($result_index, $type) {
$class = $this->options[$type . '_class_custom'];
if ($this->usesFields() && $this->view->field) {
$class = strip_tags($this->tokenizeValue($class, $result_index));
}
$classes = explode(' ', $class);
foreach ($classes as &$class) {
$class = drupal_clean_css_identifier($class);
}
return implode(' ', $classes);
}
}
......@@ -102,6 +102,11 @@ protected function assertGrid(ViewExecutable $view, $alignment, $columns) {
// Ensure no extra columns were generated.
$result = $this->xpath('//div[contains(@class, "views-col") and contains(@class, :columns)]', array(':columns' => 'col-' . ($columns + 1)));
$this->assertFalse(count($result), ucfirst($alignment) . " $columns column grid: no extraneous columns exist.");
// Ensure tokens are being replaced in custom row/column classes.
$result = $this->xpath('//div[contains(@class, "views-col") and contains(@class, "name-John")]');
$this->assertTrue(count($result), ucfirst($alignment) . " $columns column grid: Token replacement verified in custom column classes.");
$result = $this->xpath('//div[contains(@class, "views-row") and contains(@class, "age-25")]');
$this->assertTrue(count($result), ucfirst($alignment) . " $columns column grid: Token replacement verified in custom row classes.");
}
}
......@@ -50,9 +50,9 @@ display:
automatic_width: '1'
alignment: horizontal
col_class_default: '1'
col_class_custom: ''
col_class_custom: 'name-[name]'
row_class_default: '1'
row_class_custom: ''
row_class_custom: 'age-[age]'
row:
type: fields
display_plugin: default
......
......@@ -772,7 +772,7 @@ function template_preprocess_views_view_grid(&$variables) {
$num_rows = floor(count($variables['rows']) / $options['columns']);
// Iterate over each rendered views result row.
foreach ($variables['rows'] as $item) {
foreach ($variables['rows'] as $result_index => $item) {
// Add the item.
if ($horizontal) {
......@@ -794,7 +794,7 @@ function template_preprocess_views_view_grid(&$variables) {
}
}
// Add custom row classes.
$row_class = array_filter(explode(' ', $options['row_class_custom']));
$row_class = array_filter(explode(' ', $variables['view']->style_plugin->getCustomClass($result_index, 'row')));
if (!empty($row_class)) {
$row_attributes['class'] = array_merge($row_attributes['class'], $row_class);
}
......@@ -819,7 +819,7 @@ function template_preprocess_views_view_grid(&$variables) {
}
}
// Add custom column classes.
$col_class = array_filter(explode(' ', $options['col_class_custom']));
$col_class = array_filter(explode(' ', $variables['view']->style_plugin->getCustomClass($result_index, 'col')));
if (!empty($col_class)) {
$col_attributes['class'] = array_merge($col_attributes['class'], $col_class);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment