Commit 7ec9480e authored by webchick's avatar webchick

Issue #2220765 by xjm, alexpott: View names can be 255 characters long but this breaks stuff.

parent 240392cc
......@@ -1126,7 +1126,7 @@ public function optionsSummary(&$categories, &$options) {
$options['title'] = array(
'category' => 'title',
'title' => t('Title'),
'value' => $title,
'value' => views_ui_truncate($title, 32),
'desc' => t('Change the title that this display will use.'),
);
......@@ -1429,6 +1429,7 @@ public function buildOptionsForm(&$form, &$form_state) {
'#type' => 'textfield',
'#description' => t('This title will be displayed with the view, wherever titles are normally displayed; i.e, as the page title, block title, etc.'),
'#default_value' => $this->getOption('title'),
'#maxlength' => 255,
);
break;
case 'css_class':
......
......@@ -381,6 +381,8 @@ public function buildOptionsForm(&$form, &$form_state) {
'#field_prefix' => '<span dir="ltr">' . url(NULL, array('absolute' => TRUE)),
'#field_suffix' => '</span>&lrm;',
'#attributes' => array('dir' => 'ltr'),
// Account for the leading backslash.
'#maxlength' => 254,
);
break;
}
......
......@@ -241,11 +241,14 @@ public function buildForm(array $form, array &$form_state) {
$form['displays']['page']['options']['title'] = array(
'#title' => t('Page title'),
'#type' => 'textfield',
'#maxlength' => 255,
);
$form['displays']['page']['options']['path'] = array(
'#title' => t('Path'),
'#type' => 'textfield',
'#field_prefix' => $path_prefix,
// Account for the leading backslash.
'#maxlength' => 254,
);
$form['displays']['page']['options']['style'] = array(
'#type' => 'fieldset',
......@@ -332,6 +335,8 @@ public function buildForm(array $form, array &$form_state) {
'#title' => t('Feed path'),
'#type' => 'textfield',
'#field_prefix' => $path_prefix,
// Account for the leading backslash.
'#maxlength' => 254,
);
// This will almost never be visible.
$form['displays']['page']['options']['feed_properties']['row_plugin'] = array(
......@@ -385,6 +390,7 @@ public function buildForm(array $form, array &$form_state) {
$form['displays']['block']['options']['title'] = array(
'#title' => t('Block title'),
'#type' => 'textfield',
'#maxlength' => 255,
);
$form['displays']['block']['options']['style'] = array(
'#type' => 'fieldset',
......
......@@ -82,7 +82,7 @@
* Prepopulates a form field based on the view name.
*
* @param $target
* A jQuery object representing the form field to prepopulate.
* A jQuery object representing the form field or fields to prepopulate.
* @param exclude
* Optional. A regular expression representing characters to exclude from the
* target field.
......@@ -132,7 +132,7 @@
if (this.exclude) {
from = from.toLowerCase().replace(this.exclude, this.replace);
}
return from + this.suffix;
return from;
},
/**
......@@ -140,7 +140,12 @@
*/
_populate: function () {
var transliterated = this.getTransliterated();
this.target.val(transliterated);
var suffix = this.suffix;
this.target.each( function (i) {
// Ensure that the maxlength is not exceeded by prepopulating the field.
var maxlength = $(this).attr('maxlength') - suffix.length;
$(this).val(transliterated.substr(0, maxlength) + suffix);
});
},
/**
......
<?php
/**
* @file
* Contains \Drupal\views_ui\Tests\WizardTest.
*/
namespace Drupal\views_ui\Tests;
use Drupal\views\Tests\Wizard\WizardTestBase;
/**
* Tests the wizard.
*
* @see \Drupal\views\Plugin\views\display\DisplayPluginBase
* @see \Drupal\views\Plugin\views\display\PathPluginBase
* @see \Drupal\views\Plugin\views\wizard\WizardPluginBase
*/
class WizardTest extends WizardTestBase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Views UI: Wizard',
'description' => 'Tests the wizard.',
'group' => 'Views Wizard',
);
}
/**
* Tests filling in the wizard with really long strings.
*/
public function testWizardFieldLength() {
$view = array();
$view['label'] = $this->randomName(256);
$view['id'] = strtolower($this->randomName(129));
$view['page[create]'] = TRUE;
$view['page[path]'] = $this->randomName(255);
$view['page[title]'] = $this->randomName(256);
$view['page[feed]'] = TRUE;
$view['page[feed_properties][path]'] = $this->randomName(255);
$view['block[create]'] = TRUE;
$view['block[title]'] = $this->randomName(256);
$this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
$this->assertText('Machine-readable name cannot be longer than 128 characters but is currently 129 characters long.');
$this->assertText('Path cannot be longer than 254 characters but is currently 255 characters long.');
$this->assertText('Page title cannot be longer than 255 characters but is currently 256 characters long.');
$this->assertText('View name cannot be longer than 255 characters but is currently 256 characters long.');
$this->assertText('Feed path cannot be longer than 254 characters but is currently 255 characters long.');
$this->assertText('Block title cannot be longer than 255 characters but is currently 256 characters long.');
$view['label'] = $this->randomName(255);
$view['id'] = strtolower($this->randomName(128));
$view['page[create]'] = TRUE;
$view['page[path]'] = $this->randomName(254);
$view['page[title]'] = $this->randomName(255);
$view['page[feed]'] = TRUE;
$view['page[feed_properties][path]'] = $this->randomName(254);
$view['block[create]'] = TRUE;
$view['block[title]'] = $this->randomName(255);
$this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
$this->assertUrl('admin/structure/views/view/' . $view['id'], array(), 'Make sure the view saving was successful and the browser got redirected to the edit page.');
// Assert that the page title is correctly truncated.
$this->assertText(views_ui_truncate($view['page[title]'], 32));
}
}
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