updated core and modules
This commit is contained in:
@@ -41,8 +41,8 @@ use Drupal\Core\Url;
|
||||
* array('dynamic_content', 'section') for this parameter.
|
||||
*/
|
||||
function views_ui_add_ajax_trigger(&$wrapping_element, $trigger_key, $refresh_parents) {
|
||||
$seen_ids = &drupal_static(__FUNCTION__ . ':seen_ids', array());
|
||||
$seen_buttons = &drupal_static(__FUNCTION__ . ':seen_buttons', array());
|
||||
$seen_ids = &drupal_static(__FUNCTION__ . ':seen_ids', []);
|
||||
$seen_buttons = &drupal_static(__FUNCTION__ . ':seen_buttons', []);
|
||||
|
||||
// Add the AJAX behavior to the triggering element.
|
||||
$triggering_element = &$wrapping_element[$trigger_key];
|
||||
@@ -60,28 +60,28 @@ function views_ui_add_ajax_trigger(&$wrapping_element, $trigger_key, $refresh_pa
|
||||
// should be displayed next to the triggering element on the form.
|
||||
$button_key = $trigger_key . '_trigger_update';
|
||||
$element_info = \Drupal::service('element_info');
|
||||
$wrapping_element[$button_key] = array(
|
||||
$wrapping_element[$button_key] = [
|
||||
'#type' => 'submit',
|
||||
// Hide this button when JavaScript is enabled.
|
||||
'#attributes' => array('class' => array('js-hide')),
|
||||
'#submit' => array('views_ui_nojs_submit'),
|
||||
'#attributes' => ['class' => ['js-hide']],
|
||||
'#submit' => ['views_ui_nojs_submit'],
|
||||
// Add a process function to limit this button's validation errors to the
|
||||
// triggering element only. We have to do this in #process since until the
|
||||
// form API has added the #parents property to the triggering element for
|
||||
// us, we don't have any (easy) way to find out where its submitted values
|
||||
// will eventually appear in $form_state->getValues().
|
||||
'#process' => array_merge(array('views_ui_add_limited_validation'), $element_info->getInfoProperty('submit', '#process', array())),
|
||||
'#process' => array_merge(['views_ui_add_limited_validation'], $element_info->getInfoProperty('submit', '#process', [])),
|
||||
// Add an after-build function that inserts a wrapper around the region of
|
||||
// the form that needs to be refreshed by AJAX (so that the AJAX system can
|
||||
// detect and dynamically update it). This is done in #after_build because
|
||||
// it's a convenient place where we have automatic access to the complete
|
||||
// form array, but also to minimize the chance that the HTML we add will
|
||||
// get clobbered by code that runs after we have added it.
|
||||
'#after_build' => array_merge($element_info->getInfoProperty('submit', '#after_build', array()), array('views_ui_add_ajax_wrapper')),
|
||||
);
|
||||
'#after_build' => array_merge($element_info->getInfoProperty('submit', '#after_build', []), ['views_ui_add_ajax_wrapper']),
|
||||
];
|
||||
// Copy #weight and #access from the triggering element to the button, so
|
||||
// that the two elements will be displayed together.
|
||||
foreach (array('#weight', '#access') as $property) {
|
||||
foreach (['#weight', '#access'] as $property) {
|
||||
if (isset($triggering_element[$property])) {
|
||||
$wrapping_element[$button_key][$property] = $triggering_element[$property];
|
||||
}
|
||||
@@ -92,25 +92,25 @@ function views_ui_add_ajax_trigger(&$wrapping_element, $trigger_key, $refresh_pa
|
||||
// key and it may be a TranslatableMarkup.
|
||||
$button_title = !empty($triggering_element['#title']) ? (string) $triggering_element['#title'] : $trigger_key;
|
||||
if (empty($seen_buttons[$button_title])) {
|
||||
$wrapping_element[$button_key]['#value'] = t('Update "@title" choice', array(
|
||||
$wrapping_element[$button_key]['#value'] = t('Update "@title" choice', [
|
||||
'@title' => $button_title,
|
||||
));
|
||||
]);
|
||||
$seen_buttons[$button_title] = 1;
|
||||
}
|
||||
else {
|
||||
$wrapping_element[$button_key]['#value'] = t('Update "@title" choice (@number)', array(
|
||||
$wrapping_element[$button_key]['#value'] = t('Update "@title" choice (@number)', [
|
||||
'@title' => $button_title,
|
||||
'@number' => ++$seen_buttons[$button_title],
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
// Attach custom data to the triggering element and submit button, so we can
|
||||
// use it in both the process function and AJAX callback.
|
||||
$ajax_data = array(
|
||||
$ajax_data = [
|
||||
'wrapper' => $triggering_element['#ajax']['wrapper'],
|
||||
'trigger_key' => $trigger_key,
|
||||
'refresh_parents' => $refresh_parents,
|
||||
);
|
||||
];
|
||||
$seen_ids[$triggering_element['#ajax']['wrapper']] = TRUE;
|
||||
$triggering_element['#views_ui_ajax_data'] = $ajax_data;
|
||||
$wrapping_element[$button_key]['#views_ui_ajax_data'] = $ajax_data;
|
||||
@@ -132,7 +132,7 @@ function views_ui_add_limited_validation($element, FormStateInterface $form_stat
|
||||
// Limit this button's validation to the AJAX triggering element, so it can
|
||||
// update the form for that change without requiring that the rest of the
|
||||
// form be filled out properly yet.
|
||||
$element['#limit_validation_errors'] = array($ajax_triggering_element['#parents']);
|
||||
$element['#limit_validation_errors'] = [$ajax_triggering_element['#parents']];
|
||||
|
||||
// If we are in the process of a form submission and this is the button that
|
||||
// was clicked, the form API workflow in \Drupal::formBuilder()->doBuildForm()
|
||||
@@ -165,10 +165,10 @@ function views_ui_add_ajax_wrapper($element, FormStateInterface $form_state) {
|
||||
// The HTML ID that AJAX expects was also stored in a property on the
|
||||
// element, so use that information to insert the wrapper <div> here.
|
||||
$id = $element['#views_ui_ajax_data']['wrapper'];
|
||||
$refresh_element += array(
|
||||
$refresh_element += [
|
||||
'#prefix' => '',
|
||||
'#suffix' => '',
|
||||
);
|
||||
];
|
||||
$refresh_element['#prefix'] = '<div id="' . $id . '" class="views-ui-ajax-wrapper">' . $refresh_element['#prefix'];
|
||||
$refresh_element['#suffix'] .= '</div>';
|
||||
|
||||
@@ -213,16 +213,16 @@ function views_ui_standard_display_dropdown(&$form, FormStateInterface $form_sta
|
||||
|
||||
// @todo Move this to a separate function if it's needed on any forms that
|
||||
// don't have the display dropdown.
|
||||
$form['override'] = array(
|
||||
$form['override'] = [
|
||||
'#prefix' => '<div class="views-override clearfix form--inline views-offset-top" data-drupal-views-offset="top">',
|
||||
'#suffix' => '</div>',
|
||||
'#weight' => -1000,
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
// Add the "2 of 3" progress indicator.
|
||||
if ($form_progress = $view->getFormProgress()) {
|
||||
$form['progress']['#markup'] = '<div id="views-progress-indicator" class="views-progress-indicator">' . t('@current of @total', array('@current' => $form_progress['current'], '@total' => $form_progress['total'])) . '</div>';
|
||||
$form['progress']['#markup'] = '<div id="views-progress-indicator" class="views-progress-indicator">' . t('@current of @total', ['@current' => $form_progress['current'], '@total' => $form_progress['total']]) . '</div>';
|
||||
$form['progress']['#weight'] = -1001;
|
||||
}
|
||||
|
||||
@@ -247,17 +247,17 @@ function views_ui_standard_display_dropdown(&$form, FormStateInterface $form_sta
|
||||
}
|
||||
|
||||
$display_dropdown['default'] = ($section_overrides ? t('All displays (except overridden)') : t('All displays'));
|
||||
$display_dropdown[$display_id] = t('This @display_type (override)', array('@display_type' => $current_display->getPluginId()));
|
||||
$display_dropdown[$display_id] = t('This @display_type (override)', ['@display_type' => $current_display->getPluginId()]);
|
||||
// Only display the revert option if we are in a overridden section.
|
||||
if (!$section_defaulted) {
|
||||
$display_dropdown['default_revert'] = t('Revert to default');
|
||||
}
|
||||
|
||||
$form['override']['dropdown'] = array(
|
||||
$form['override']['dropdown'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => t('For'), // @TODO: Translators may need more context than this.
|
||||
'#options' => $display_dropdown,
|
||||
);
|
||||
];
|
||||
if ($current_display->isDefaulted($section)) {
|
||||
$form['override']['dropdown']['#default_value'] = 'defaults';
|
||||
}
|
||||
|
||||
@@ -170,9 +170,9 @@ details.box-padding {
|
||||
margin-bottom: 6px;
|
||||
margin-top: 6px;
|
||||
}
|
||||
.views-ui-view-title {
|
||||
.views-ui-view-name h3 {
|
||||
font-weight: bold;
|
||||
margin-top: 0;
|
||||
margin: 0.25em 0;
|
||||
}
|
||||
.view-changed {
|
||||
margin-bottom: 21px;
|
||||
@@ -183,22 +183,33 @@ details.box-padding {
|
||||
margin-bottom: 0;
|
||||
margin-top: 18px;
|
||||
}
|
||||
.views-ui-view-displays ul {
|
||||
margin-left: 0; /* LTR */
|
||||
padding-left: 0; /* LTR */
|
||||
list-style: none;
|
||||
}
|
||||
[dir="rtl"] .views-ui-view-displays ul {
|
||||
margin-right: 0;
|
||||
padding-right: 0;
|
||||
margin-left: inherit;
|
||||
padding-left: inherit;
|
||||
}
|
||||
|
||||
/* These header classes are ambiguous and should be scoped to th elements */
|
||||
.views-ui-name {
|
||||
width: 18%;
|
||||
width: 20%;
|
||||
}
|
||||
.views-ui-description {
|
||||
width: 26%;
|
||||
width: 30%;
|
||||
}
|
||||
.views-ui-tag {
|
||||
width: 8%;
|
||||
.views-ui-machine-name {
|
||||
width: 15%;
|
||||
}
|
||||
.views-ui-path {
|
||||
width: auto;
|
||||
.views-ui-displays {
|
||||
width: 25%;
|
||||
}
|
||||
.views-ui-operations {
|
||||
width: 24%;
|
||||
width: 10%;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -187,13 +187,12 @@
|
||||
// Bind AJAX behaviors to all items showing the class.
|
||||
$('a.views-ajax-link', context).once('views-ajax').each(function () {
|
||||
var element_settings = base_element_settings;
|
||||
element_settings.base = base;
|
||||
element_settings.base = $(this).attr('id');
|
||||
element_settings.element = this;
|
||||
// Set the URL to go to the anchor.
|
||||
if ($(this).attr('href')) {
|
||||
element_settings.url = $(this).attr('href');
|
||||
}
|
||||
var base = $(this).attr('id');
|
||||
Drupal.ajax(element_settings);
|
||||
});
|
||||
|
||||
@@ -213,9 +212,8 @@
|
||||
|
||||
element_settings.wrapper = 'views-preview-wrapper';
|
||||
element_settings.method = 'replaceWith';
|
||||
element_settings.base = base;
|
||||
element_settings.base = $(this).attr('id');
|
||||
element_settings.element = this;
|
||||
var base = $(this).attr('id');
|
||||
Drupal.ajax(element_settings);
|
||||
});
|
||||
|
||||
@@ -239,10 +237,9 @@
|
||||
element_settings.wrapper = 'views-preview-wrapper';
|
||||
element_settings.method = 'replaceWith';
|
||||
element_settings.event = 'click';
|
||||
element_settings.base = base;
|
||||
element_settings.base = $(this).attr('id');
|
||||
element_settings.element = this;
|
||||
|
||||
var base = $(this).attr('id');
|
||||
Drupal.ajax(element_settings);
|
||||
});
|
||||
|
||||
|
||||
@@ -483,18 +483,18 @@
|
||||
* An array of all the filterable options.
|
||||
*/
|
||||
getOptions: function ($allOptions) {
|
||||
var $label;
|
||||
var $title;
|
||||
var $description;
|
||||
var $option;
|
||||
var options = [];
|
||||
var length = $allOptions.length;
|
||||
for (var i = 0; i < length; i++) {
|
||||
$option = $($allOptions[i]);
|
||||
$label = $option.find('label');
|
||||
$title = $option.find('.title');
|
||||
$description = $option.find('.description');
|
||||
options[i] = {
|
||||
// Search on the lowercase version of the label text + description.
|
||||
searchText: $label.text().toLowerCase() + ' ' + $description.text().toLowerCase(),
|
||||
// Search on the lowercase version of the title text + description.
|
||||
searchText: $title.text().toLowerCase() + ' ' + $description.text().toLowerCase(),
|
||||
// Maintain a reference to the jQuery object for each row, so we don't
|
||||
// have to create a new object inside the performance-sensitive keyup
|
||||
// handler.
|
||||
@@ -708,6 +708,7 @@
|
||||
// When the link is clicked, dynamically click the hidden form button
|
||||
// for adding a new filter group.
|
||||
.once('views-rearrange-filter-handler')
|
||||
.find('#views-add-group-link')
|
||||
.on('click.views-rearrange-filter-handler', $.proxy(this, 'clickAddGroupButton'));
|
||||
|
||||
// Find each (visually hidden) button for removing a filter group and
|
||||
@@ -733,12 +734,7 @@
|
||||
* The event triggered.
|
||||
*/
|
||||
clickAddGroupButton: function (event) {
|
||||
// Due to conflicts between Drupal core's AJAX system and the Views AJAX
|
||||
// system, the only way to get this to work seems to be to trigger both
|
||||
// the mousedown and submit events.
|
||||
this.addGroupButton
|
||||
.trigger('mousedown')
|
||||
.trigger('submit');
|
||||
this.addGroupButton.trigger('mousedown');
|
||||
event.preventDefault();
|
||||
},
|
||||
|
||||
@@ -750,7 +746,7 @@
|
||||
* form button that should be clicked.
|
||||
*/
|
||||
clickRemoveGroupButton: function (event) {
|
||||
this.table.find('#' + event.data.buttonId).trigger('mousedown').trigger('submit');
|
||||
this.table.find('#' + event.data.buttonId).trigger('mousedown');
|
||||
event.preventDefault();
|
||||
},
|
||||
|
||||
|
||||
@@ -32,10 +32,10 @@ class SetFormCommand implements CommandInterface {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render() {
|
||||
return array(
|
||||
return [
|
||||
'command' => 'viewsSetForm',
|
||||
'url' => $this->url,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class ViewsUIController extends ControllerBase {
|
||||
/**
|
||||
* Constructs a new \Drupal\views_ui\Controller\ViewsUIController object.
|
||||
*
|
||||
* @param \Drupal\views\ViewsData views_data
|
||||
* @param \Drupal\views\ViewsData $views_data
|
||||
* The Views data cache object.
|
||||
*/
|
||||
public function __construct(ViewsData $views_data) {
|
||||
@@ -58,7 +58,7 @@ class ViewsUIController extends ControllerBase {
|
||||
|
||||
// Fetch all fieldapi fields which are used in views
|
||||
// Therefore search in all views, displays and handler-types.
|
||||
$fields = array();
|
||||
$fields = [];
|
||||
$handler_types = ViewExecutable::getHandlerTypes();
|
||||
foreach ($views as $view) {
|
||||
$executable = $view->getExecutable();
|
||||
@@ -81,12 +81,12 @@ class ViewsUIController extends ControllerBase {
|
||||
}
|
||||
}
|
||||
|
||||
$header = array(t('Field name'), t('Used in'));
|
||||
$rows = array();
|
||||
$header = [t('Field name'), t('Used in')];
|
||||
$rows = [];
|
||||
foreach ($fields as $field_name => $views) {
|
||||
$rows[$field_name]['data'][0]['data']['#plain_text'] = $field_name;
|
||||
foreach ($views as $view) {
|
||||
$rows[$field_name]['data'][1][] = $this->l($view, new Url('entity.view.edit_form', array('view' => $view)));
|
||||
$rows[$field_name]['data'][1][] = $this->l($view, new Url('entity.view.edit_form', ['view' => $view]));
|
||||
}
|
||||
$item_list = [
|
||||
'#theme' => 'item_list',
|
||||
@@ -98,12 +98,12 @@ class ViewsUIController extends ControllerBase {
|
||||
|
||||
// Sort rows by field name.
|
||||
ksort($rows);
|
||||
$output = array(
|
||||
$output = [
|
||||
'#type' => 'table',
|
||||
'#header' => $header,
|
||||
'#rows' => $rows,
|
||||
'#empty' => t('No fields have been used in views yet.'),
|
||||
);
|
||||
];
|
||||
|
||||
return $output;
|
||||
}
|
||||
@@ -120,7 +120,7 @@ class ViewsUIController extends ControllerBase {
|
||||
$views = [];
|
||||
// Link each view name to the view itself.
|
||||
foreach ($row['views'] as $row_name => $view) {
|
||||
$views[] = $this->l($view, new Url('entity.view.edit_form', array('view' => $view)));
|
||||
$views[] = $this->l($view, new Url('entity.view.edit_form', ['view' => $view]));
|
||||
}
|
||||
unset($row['views']);
|
||||
$row['views']['data'] = [
|
||||
@@ -132,12 +132,12 @@ class ViewsUIController extends ControllerBase {
|
||||
|
||||
// Sort rows by field name.
|
||||
ksort($rows);
|
||||
return array(
|
||||
return [
|
||||
'#type' => 'table',
|
||||
'#header' => array(t('Type'), t('Name'), t('Provided by'), t('Used in')),
|
||||
'#header' => [t('Type'), t('Name'), t('Provided by'), t('Used in')],
|
||||
'#rows' => $rows,
|
||||
'#empty' => t('There are no enabled views.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,7 +180,7 @@ class ViewsUIController extends ControllerBase {
|
||||
* A JSON response containing the autocomplete suggestions for Views tags.
|
||||
*/
|
||||
public function autocompleteTag(Request $request) {
|
||||
$matches = array();
|
||||
$matches = [];
|
||||
$string = $request->query->get('q');
|
||||
// Get matches from default views.
|
||||
$views = $this->entityManager()->getStorage('view')->loadMultiple();
|
||||
@@ -223,8 +223,8 @@ class ViewsUIController extends ControllerBase {
|
||||
}
|
||||
$build['#title'] = $name;
|
||||
|
||||
$build['edit'] = $this->entityFormBuilder()->getForm($view, 'edit', array('display_id' => $display_id));
|
||||
$build['preview'] = $this->entityFormBuilder()->getForm($view, 'preview', array('display_id' => $display_id));
|
||||
$build['edit'] = $this->entityFormBuilder()->getForm($view, 'edit', ['display_id' => $display_id]);
|
||||
$build['preview'] = $this->entityFormBuilder()->getForm($view, 'preview', ['display_id' => $display_id]);
|
||||
return $build;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,52 +32,52 @@ class AdvancedSettingsForm extends ConfigFormBase {
|
||||
$form = parent::buildForm($form, $form_state);
|
||||
|
||||
$config = $this->config('views.settings');
|
||||
$form['cache'] = array(
|
||||
$form['cache'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Caching'),
|
||||
'#open' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
$form['cache']['skip_cache'] = array(
|
||||
$form['cache']['skip_cache'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Disable views data caching'),
|
||||
'#description' => $this->t("Views caches data about tables, modules and views available, to increase performance. By checking this box, Views will skip this cache and always rebuild this data when needed. This can have a serious performance impact on your site."),
|
||||
'#default_value' => $config->get('skip_cache'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['cache']['clear_cache'] = array(
|
||||
$form['cache']['clear_cache'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t("Clear Views' cache"),
|
||||
'#submit' => array('::cacheSubmit'),
|
||||
);
|
||||
'#submit' => ['::cacheSubmit'],
|
||||
];
|
||||
|
||||
$form['debug'] = array(
|
||||
$form['debug'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Debugging'),
|
||||
'#open' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
$form['debug']['sql_signature'] = array(
|
||||
$form['debug']['sql_signature'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Add Views signature to all SQL queries'),
|
||||
'#description' => $this->t("All Views-generated queries will include the name of the views and display 'view-name:display-name' as a string at the end of the SELECT clause. This makes identifying Views queries in database server logs simpler, but should only be used when troubleshooting."),
|
||||
|
||||
'#default_value' => $config->get('sql_signature'),
|
||||
);
|
||||
];
|
||||
|
||||
$options = Views::fetchPluginNames('display_extender');
|
||||
if (!empty($options)) {
|
||||
$form['extenders'] = array(
|
||||
$form['extenders'] = [
|
||||
'#type' => 'details',
|
||||
'#open' => TRUE,
|
||||
);
|
||||
$form['extenders']['display_extenders'] = array(
|
||||
];
|
||||
$form['extenders']['display_extenders'] = [
|
||||
'#title' => $this->t('Display extenders'),
|
||||
'#default_value' => array_filter($config->get('display_extenders')),
|
||||
'#options' => $options,
|
||||
'#type' => 'checkboxes',
|
||||
'#description' => $this->t('Select extensions of the views interface.')
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
return $form;
|
||||
@@ -90,7 +90,7 @@ class AdvancedSettingsForm extends ConfigFormBase {
|
||||
$this->config('views.settings')
|
||||
->set('skip_cache', $form_state->getValue('skip_cache'))
|
||||
->set('sql_signature', $form_state->getValue('sql_signature'))
|
||||
->set('display_extenders', $form_state->getValue('display_extenders', array()))
|
||||
->set('display_extenders', $form_state->getValue('display_extenders', []))
|
||||
->save();
|
||||
|
||||
parent::submitForm($form, $form_state);
|
||||
|
||||
@@ -49,16 +49,16 @@ class AddHandler extends ViewsFormBase {
|
||||
$display_id = $form_state->get('display_id');
|
||||
$type = $form_state->get('type');
|
||||
|
||||
$form = array(
|
||||
'options' => array(
|
||||
'#theme_wrappers' => array('container'),
|
||||
'#attributes' => array('class' => array('scroll'), 'data-drupal-views-scroll' => TRUE),
|
||||
),
|
||||
);
|
||||
$form = [
|
||||
'options' => [
|
||||
'#theme_wrappers' => ['container'],
|
||||
'#attributes' => ['class' => ['scroll'], 'data-drupal-views-scroll' => TRUE],
|
||||
],
|
||||
];
|
||||
|
||||
$executable = $view->getExecutable();
|
||||
if (!$executable->setDisplay($display_id)) {
|
||||
$form['markup'] = array('#markup' => $this->t('Invalid display id @display', array('@display' => $display_id)));
|
||||
$form['markup'] = ['#markup' => $this->t('Invalid display id @display', ['@display' => $display_id])];
|
||||
return $form;
|
||||
}
|
||||
$display = &$executable->displayHandlers->get($display_id);
|
||||
@@ -71,7 +71,7 @@ class AddHandler extends ViewsFormBase {
|
||||
$type = $types[$type]['type'];
|
||||
}
|
||||
|
||||
$form['#title'] = $this->t('Add @type', array('@type' => $ltitle));
|
||||
$form['#title'] = $this->t('Add @type', ['@type' => $ltitle]);
|
||||
$form['#section'] = $display_id . 'add-handler';
|
||||
|
||||
// Add the display override dropdown.
|
||||
@@ -82,36 +82,36 @@ class AddHandler extends ViewsFormBase {
|
||||
$options = Views::viewsDataHelper()->fetchFields(array_keys($base_tables), $type, $display->useGroupBy(), $form_state->get('type'));
|
||||
|
||||
if (!empty($options)) {
|
||||
$form['override']['controls'] = array(
|
||||
'#theme_wrappers' => array('container'),
|
||||
$form['override']['controls'] = [
|
||||
'#theme_wrappers' => ['container'],
|
||||
'#id' => 'views-filterable-options-controls',
|
||||
'#attributes' => ['class' => ['form--inline', 'views-filterable-options-controls']],
|
||||
);
|
||||
$form['override']['controls']['options_search'] = array(
|
||||
];
|
||||
$form['override']['controls']['options_search'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Search'),
|
||||
);
|
||||
];
|
||||
|
||||
$groups = array('all' => $this->t('- All -'));
|
||||
$form['override']['controls']['group'] = array(
|
||||
$groups = ['all' => $this->t('- All -')];
|
||||
$form['override']['controls']['group'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Type'),
|
||||
'#options' => array(),
|
||||
);
|
||||
'#title' => $this->t('Category'),
|
||||
'#options' => [],
|
||||
];
|
||||
|
||||
$form['options']['name'] = array(
|
||||
$form['options']['name'] = [
|
||||
'#prefix' => '<div class="views-radio-box form-checkboxes views-filterable-options">',
|
||||
'#suffix' => '</div>',
|
||||
'#type' => 'tableselect',
|
||||
'#header' => array(
|
||||
'#header' => [
|
||||
'title' => $this->t('Title'),
|
||||
'group' => $this->t('Category'),
|
||||
'help' => $this->t('Description'),
|
||||
),
|
||||
],
|
||||
'#js_select' => FALSE,
|
||||
);
|
||||
];
|
||||
|
||||
$grouped_options = array();
|
||||
$grouped_options = [];
|
||||
foreach ($options as $key => $option) {
|
||||
$group = preg_replace('/[^a-z0-9]/', '-', strtolower($option['group']));
|
||||
$groups[$group] = $option['group'];
|
||||
@@ -136,50 +136,50 @@ class AddHandler extends ViewsFormBase {
|
||||
|
||||
foreach ($grouped_options as $group => $group_options) {
|
||||
foreach ($group_options as $key => $option) {
|
||||
$form['options']['name']['#options'][$key] = array(
|
||||
'#attributes' => array(
|
||||
'class' => array('filterable-option', $group),
|
||||
),
|
||||
'title' => array(
|
||||
'data' => array(
|
||||
$form['options']['name']['#options'][$key] = [
|
||||
'#attributes' => [
|
||||
'class' => ['filterable-option', $group],
|
||||
],
|
||||
'title' => [
|
||||
'data' => [
|
||||
'#title' => $option['title'],
|
||||
'#plain_text' => $option['title'],
|
||||
),
|
||||
'class' => array('title'),
|
||||
),
|
||||
],
|
||||
'class' => ['title'],
|
||||
],
|
||||
'group' => $option['group'],
|
||||
'help' => array(
|
||||
'help' => [
|
||||
'data' => $option['help'],
|
||||
'class' => array('description'),
|
||||
),
|
||||
);
|
||||
'class' => ['description'],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$form['override']['controls']['group']['#options'] = $groups;
|
||||
}
|
||||
else {
|
||||
$form['options']['markup'] = array(
|
||||
'#markup' => '<div class="js-form-item form-item">' . $this->t('There are no @types available to add.', array('@types' => $ltitle)) . '</div>',
|
||||
);
|
||||
$form['options']['markup'] = [
|
||||
'#markup' => '<div class="js-form-item form-item">' . $this->t('There are no @types available to add.', ['@types' => $ltitle]) . '</div>',
|
||||
];
|
||||
}
|
||||
// Add a div to show the selected items
|
||||
$form['selected'] = array(
|
||||
$form['selected'] = [
|
||||
'#type' => 'item',
|
||||
'#markup' => '<span class="views-ui-view-title">' . $this->t('Selected:') . '</span> ' . '<div class="views-selected-options"></div>',
|
||||
'#theme_wrappers' => array('form_element', 'views_ui_container'),
|
||||
'#attributes' => array(
|
||||
'class' => array('container-inline', 'views-add-form-selected', 'views-offset-bottom'),
|
||||
'#theme_wrappers' => ['form_element', 'views_ui_container'],
|
||||
'#attributes' => [
|
||||
'class' => ['container-inline', 'views-add-form-selected', 'views-offset-bottom'],
|
||||
'data-drupal-views-offset' => 'bottom',
|
||||
),
|
||||
);
|
||||
$view->getStandardButtons($form, $form_state, 'views_ui_add_handler_form', $this->t('Add and configure @types', array('@types' => $ltitle)));
|
||||
],
|
||||
];
|
||||
$view->getStandardButtons($form, $form_state, 'views_ui_add_handler_form', $this->t('Add and configure @types', ['@types' => $ltitle]));
|
||||
|
||||
// Remove the default submit function.
|
||||
$form['actions']['submit']['#submit'] = array_filter($form['actions']['submit']['#submit'], function($var) {
|
||||
return !(is_array($var) && isset($var[1]) && $var[1] == 'standardSubmit');
|
||||
});
|
||||
$form['actions']['submit']['#submit'][] = array($view, 'submitItemAdd');
|
||||
$form['actions']['submit']['#submit'][] = [$view, 'submitItemAdd'];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
@@ -36,11 +36,11 @@ class Analyze extends ViewsFormBase {
|
||||
$analyzer = Views::analyzer();
|
||||
$messages = $analyzer->getMessages($view->getExecutable());
|
||||
|
||||
$form['analysis'] = array(
|
||||
$form['analysis'] = [
|
||||
'#prefix' => '<div class="js-form-item form-item">',
|
||||
'#suffix' => '</div>',
|
||||
'#markup' => $analyzer->formatMessages($messages),
|
||||
);
|
||||
];
|
||||
|
||||
// Inform the standard button function that we want an OK button.
|
||||
$form_state->set('ok_button', TRUE);
|
||||
|
||||
@@ -54,17 +54,17 @@ class ConfigHandler extends ViewsFormBase {
|
||||
$type = $form_state->get('type');
|
||||
$id = $form_state->get('id');
|
||||
|
||||
$form = array(
|
||||
'options' => array(
|
||||
$form = [
|
||||
'options' => [
|
||||
'#tree' => TRUE,
|
||||
'#theme_wrappers' => array('container'),
|
||||
'#attributes' => array('class' => array('scroll'), 'data-drupal-views-scroll' => TRUE),
|
||||
),
|
||||
);
|
||||
'#theme_wrappers' => ['container'],
|
||||
'#attributes' => ['class' => ['scroll'], 'data-drupal-views-scroll' => TRUE],
|
||||
],
|
||||
];
|
||||
$executable = $view->getExecutable();
|
||||
$save_ui_cache = FALSE;
|
||||
if (!$executable->setDisplay($display_id)) {
|
||||
$form['markup'] = array('#markup' => $this->t('Invalid display id @display', array('@display' => $display_id)));
|
||||
$form['markup'] = ['#markup' => $this->t('Invalid display id @display', ['@display' => $display_id])];
|
||||
return $form;
|
||||
}
|
||||
$item = $executable->getHandler($display_id, $type, $id);
|
||||
@@ -72,7 +72,7 @@ class ConfigHandler extends ViewsFormBase {
|
||||
if ($item) {
|
||||
$handler = $executable->display_handler->getHandler($type, $id);
|
||||
if (empty($handler)) {
|
||||
$form['markup'] = array('#markup' => $this->t("Error: handler for @table > @field doesn't exist!", array('@table' => $item['table'], '@field' => $item['field'])));
|
||||
$form['markup'] = ['#markup' => $this->t("Error: handler for @table > @field doesn't exist!", ['@table' => $item['table'], '@field' => $item['field']])];
|
||||
}
|
||||
else {
|
||||
$types = ViewExecutable::getHandlerTypes();
|
||||
@@ -88,7 +88,7 @@ class ConfigHandler extends ViewsFormBase {
|
||||
// A whole bunch of code to figure out what relationships are valid for
|
||||
// this item.
|
||||
$relationships = $executable->display_handler->getOption('relationships');
|
||||
$relationship_options = array();
|
||||
$relationship_options = [];
|
||||
|
||||
foreach ($relationships as $relationship) {
|
||||
// relationships can't link back to self. But also, due to ordering,
|
||||
@@ -118,7 +118,7 @@ class ConfigHandler extends ViewsFormBase {
|
||||
// it to none.
|
||||
$base_fields = Views::viewsDataHelper()->fetchFields($view->get('base_table'), $type, $executable->display_handler->useGroupBy());
|
||||
if (isset($base_fields[$item['table'] . '.' . $item['field']])) {
|
||||
$relationship_options = array_merge(array('none' => $this->t('Do not use a relationship')), $relationship_options);
|
||||
$relationship_options = array_merge(['none' => $this->t('Do not use a relationship')], $relationship_options);
|
||||
}
|
||||
$rel = empty($item['relationship']) ? 'none' : $item['relationship'];
|
||||
if (empty($relationship_options[$rel])) {
|
||||
@@ -133,30 +133,30 @@ class ConfigHandler extends ViewsFormBase {
|
||||
$handler->init($executable, $executable->display_handler, $item);
|
||||
}
|
||||
|
||||
$form['options']['relationship'] = array(
|
||||
$form['options']['relationship'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Relationship'),
|
||||
'#options' => $relationship_options,
|
||||
'#default_value' => $rel,
|
||||
'#weight' => -500,
|
||||
);
|
||||
];
|
||||
}
|
||||
else {
|
||||
$form['options']['relationship'] = array(
|
||||
$form['options']['relationship'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => 'none',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$form['#title'] = $this->t('Configure @type: @item', array('@type' => $types[$type]['lstitle'], '@item' => $handler->adminLabel()));
|
||||
$form['#title'] = $this->t('Configure @type: @item', ['@type' => $types[$type]['lstitle'], '@item' => $handler->adminLabel()]);
|
||||
|
||||
if (!empty($handler->definition['help'])) {
|
||||
$form['options']['form_description'] = array(
|
||||
$form['options']['form_description'] = [
|
||||
'#markup' => $handler->definition['help'],
|
||||
'#theme_wrappers' => array('container'),
|
||||
'#attributes' => array('class' => array('js-form-item form-item description')),
|
||||
'#theme_wrappers' => ['container'],
|
||||
'#attributes' => ['class' => ['js-form-item form-item description']],
|
||||
'#weight' => -1000,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$form['#section'] = $display_id . '-' . $type . '-' . $id;
|
||||
@@ -170,13 +170,13 @@ class ConfigHandler extends ViewsFormBase {
|
||||
|
||||
$view->getStandardButtons($form, $form_state, 'views_ui_config_item_form', $name);
|
||||
// Add a 'remove' button.
|
||||
$form['actions']['remove'] = array(
|
||||
$form['actions']['remove'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Remove'),
|
||||
'#submit' => array(array($this, 'remove')),
|
||||
'#limit_validation_errors' => array(array('override')),
|
||||
'#submit' => [[$this, 'remove']],
|
||||
'#limit_validation_errors' => [['override']],
|
||||
'#button_type' => 'danger',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
if ($save_ui_cache) {
|
||||
|
||||
@@ -51,16 +51,16 @@ class ConfigHandlerExtra extends ViewsFormBase {
|
||||
$type = $form_state->get('type');
|
||||
$id = $form_state->get('id');
|
||||
|
||||
$form = array(
|
||||
'options' => array(
|
||||
$form = [
|
||||
'options' => [
|
||||
'#tree' => TRUE,
|
||||
'#theme_wrappers' => array('container'),
|
||||
'#attributes' => array('class' => array('scroll'), 'data-drupal-views-scroll' => TRUE),
|
||||
),
|
||||
);
|
||||
'#theme_wrappers' => ['container'],
|
||||
'#attributes' => ['class' => ['scroll'], 'data-drupal-views-scroll' => TRUE],
|
||||
],
|
||||
];
|
||||
$executable = $view->getExecutable();
|
||||
if (!$executable->setDisplay($display_id)) {
|
||||
$form['markup'] = array('#markup' => $this->t('Invalid display id @display', array('@display' => $display_id)));
|
||||
$form['markup'] = ['#markup' => $this->t('Invalid display id @display', ['@display' => $display_id])];
|
||||
return $form;
|
||||
}
|
||||
$item = $executable->getHandler($display_id, $type, $id);
|
||||
@@ -68,13 +68,13 @@ class ConfigHandlerExtra extends ViewsFormBase {
|
||||
if ($item) {
|
||||
$handler = $executable->display_handler->getHandler($type, $id);
|
||||
if (empty($handler)) {
|
||||
$form['markup'] = array('#markup' => $this->t("Error: handler for @table > @field doesn't exist!", array('@table' => $item['table'], '@field' => $item['field'])));
|
||||
$form['markup'] = ['#markup' => $this->t("Error: handler for @table > @field doesn't exist!", ['@table' => $item['table'], '@field' => $item['field']])];
|
||||
}
|
||||
else {
|
||||
$handler->init($executable, $executable->display_handler, $item);
|
||||
$types = ViewExecutable::getHandlerTypes();
|
||||
|
||||
$form['#title'] = $this->t('Configure extra settings for @type %item', array('@type' => $types[$type]['lstitle'], '%item' => $handler->adminLabel()));
|
||||
$form['#title'] = $this->t('Configure extra settings for @type %item', ['@type' => $types[$type]['lstitle'], '%item' => $handler->adminLabel()]);
|
||||
|
||||
$form['#section'] = $display_id . '-' . $type . '-' . $id;
|
||||
|
||||
|
||||
@@ -52,16 +52,16 @@ class ConfigHandlerGroup extends ViewsFormBase {
|
||||
$type = $form_state->get('type');
|
||||
$id = $form_state->get('id');
|
||||
|
||||
$form = array(
|
||||
'options' => array(
|
||||
$form = [
|
||||
'options' => [
|
||||
'#tree' => TRUE,
|
||||
'#theme_wrappers' => array('container'),
|
||||
'#attributes' => array('class' => array('scroll'), 'data-drupal-views-scroll' => TRUE),
|
||||
),
|
||||
);
|
||||
'#theme_wrappers' => ['container'],
|
||||
'#attributes' => ['class' => ['scroll'], 'data-drupal-views-scroll' => TRUE],
|
||||
],
|
||||
];
|
||||
$executable = $view->getExecutable();
|
||||
if (!$executable->setDisplay($display_id)) {
|
||||
$form['markup'] = array('#markup' => $this->t('Invalid display id @display', array('@display' => $display_id)));
|
||||
$form['markup'] = ['#markup' => $this->t('Invalid display id @display', ['@display' => $display_id])];
|
||||
return $form;
|
||||
}
|
||||
|
||||
@@ -72,13 +72,13 @@ class ConfigHandlerGroup extends ViewsFormBase {
|
||||
if ($item) {
|
||||
$handler = $executable->display_handler->getHandler($type, $id);
|
||||
if (empty($handler)) {
|
||||
$form['markup'] = array('#markup' => $this->t("Error: handler for @table > @field doesn't exist!", array('@table' => $item['table'], '@field' => $item['field'])));
|
||||
$form['markup'] = ['#markup' => $this->t("Error: handler for @table > @field doesn't exist!", ['@table' => $item['table'], '@field' => $item['field']])];
|
||||
}
|
||||
else {
|
||||
$handler->init($executable, $executable->display_handler, $item);
|
||||
$types = ViewExecutable::getHandlerTypes();
|
||||
|
||||
$form['#title'] = $this->t('Configure aggregation settings for @type %item', array('@type' => $types[$type]['lstitle'], '%item' => $handler->adminLabel()));
|
||||
$form['#title'] = $this->t('Configure aggregation settings for @type %item', ['@type' => $types[$type]['lstitle'], '%item' => $handler->adminLabel()]);
|
||||
|
||||
$handler->buildGroupByForm($form['options'], $form_state);
|
||||
$form_state->set('handler', $handler);
|
||||
|
||||
@@ -60,15 +60,15 @@ class Display extends ViewsFormBase {
|
||||
|
||||
$executable = $view->getExecutable();
|
||||
if (!$executable->setDisplay($display_id)) {
|
||||
$form['markup'] = array('#markup' => $this->t('Invalid display id @display', array('@display' => $display_id)));
|
||||
$form['markup'] = ['#markup' => $this->t('Invalid display id @display', ['@display' => $display_id])];
|
||||
return $form;
|
||||
}
|
||||
|
||||
// Get form from the handler.
|
||||
$form['options'] = array(
|
||||
'#theme_wrappers' => array('container'),
|
||||
'#attributes' => array('class' => array('scroll'), 'data-drupal-views-scroll' => TRUE),
|
||||
);
|
||||
$form['options'] = [
|
||||
'#theme_wrappers' => ['container'],
|
||||
'#attributes' => ['class' => ['scroll'], 'data-drupal-views-scroll' => TRUE],
|
||||
];
|
||||
$executable->display_handler->buildOptionsForm($form['options'], $form_state);
|
||||
|
||||
// The handler options form sets $form['#title'], which we need on the entire
|
||||
|
||||
@@ -33,33 +33,33 @@ class EditDetails extends ViewsFormBase {
|
||||
$form['#title'] = $this->t('Name and description');
|
||||
$form['#section'] = 'details';
|
||||
|
||||
$form['details'] = array(
|
||||
'#theme_wrappers' => array('container'),
|
||||
'#attributes' => array('class' => array('scroll'), 'data-drupal-views-scroll' => TRUE),
|
||||
);
|
||||
$form['details']['label'] = array(
|
||||
$form['details'] = [
|
||||
'#theme_wrappers' => ['container'],
|
||||
'#attributes' => ['class' => ['scroll'], 'data-drupal-views-scroll' => TRUE],
|
||||
];
|
||||
$form['details']['label'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Administrative name'),
|
||||
'#default_value' => $view->label(),
|
||||
);
|
||||
$form['details']['langcode'] = array(
|
||||
];
|
||||
$form['details']['langcode'] = [
|
||||
'#type' => 'language_select',
|
||||
'#title' => $this->t('View language'),
|
||||
'#description' => $this->t('Language of labels and other textual elements in this view.'),
|
||||
'#default_value' => $view->get('langcode'),
|
||||
);
|
||||
$form['details']['description'] = array(
|
||||
];
|
||||
$form['details']['description'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Administrative description'),
|
||||
'#default_value' => $view->get('description'),
|
||||
);
|
||||
$form['details']['tag'] = array(
|
||||
];
|
||||
$form['details']['tag'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Administrative tags'),
|
||||
'#description' => t('Enter a comma-separated list of words to describe your view.'),
|
||||
'#default_value' => $view->get('tag'),
|
||||
'#autocomplete_route_name' => 'views_ui.autocomplete',
|
||||
);
|
||||
];
|
||||
|
||||
$view->getStandardButtons($form, $form_state, 'views_ui_edit_details_form');
|
||||
return $form;
|
||||
|
||||
@@ -53,11 +53,11 @@ class Rearrange extends ViewsFormBase {
|
||||
$types = ViewExecutable::getHandlerTypes();
|
||||
$executable = $view->getExecutable();
|
||||
if (!$executable->setDisplay($display_id)) {
|
||||
$form['markup'] = array('#markup' => $this->t('Invalid display id @display', array('@display' => $display_id)));
|
||||
$form['markup'] = ['#markup' => $this->t('Invalid display id @display', ['@display' => $display_id])];
|
||||
return $form;
|
||||
}
|
||||
$display = &$executable->displayHandlers->get($display_id);
|
||||
$form['#title'] = $this->t('Rearrange @type', array('@type' => $types[$type]['ltitle']));
|
||||
$form['#title'] = $this->t('Rearrange @type', ['@type' => $types[$type]['ltitle']]);
|
||||
$form['#section'] = $display_id . 'rearrange-item';
|
||||
|
||||
if ($display->defaultableSections($types[$type]['plural'])) {
|
||||
@@ -69,31 +69,31 @@ class Rearrange extends ViewsFormBase {
|
||||
$count = 0;
|
||||
|
||||
// Get relationship labels
|
||||
$relationships = array();
|
||||
$relationships = [];
|
||||
foreach ($display->getHandlers('relationship') as $id => $handler) {
|
||||
$relationships[$id] = $handler->adminLabel();
|
||||
}
|
||||
|
||||
$form['fields'] = array(
|
||||
$form['fields'] = [
|
||||
'#type' => 'table',
|
||||
'#header' => array('', $this->t('Weight'), $this->t('Remove')),
|
||||
'#header' => ['', $this->t('Weight'), $this->t('Remove')],
|
||||
'#empty' => $this->t('No fields available.'),
|
||||
'#tabledrag' => array(
|
||||
array(
|
||||
'#tabledrag' => [
|
||||
[
|
||||
'action' => 'order',
|
||||
'relationship' => 'sibling',
|
||||
'group' => 'weight',
|
||||
)
|
||||
),
|
||||
]
|
||||
],
|
||||
'#tree' => TRUE,
|
||||
'#prefix' => '<div class="scroll" data-drupal-views-scroll>',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
];
|
||||
|
||||
foreach ($display->getOption($types[$type]['plural']) as $id => $field) {
|
||||
$form['fields'][$id] = array();
|
||||
$form['fields'][$id] = [];
|
||||
|
||||
$form['fields'][$id]['#attributes'] = array('class' => array('draggable'), 'id' => 'views-row-' . $id);
|
||||
$form['fields'][$id]['#attributes'] = ['class' => ['draggable'], 'id' => 'views-row-' . $id];
|
||||
|
||||
$handler = $display->getHandler($type, $id);
|
||||
if ($handler) {
|
||||
@@ -105,34 +105,34 @@ class Rearrange extends ViewsFormBase {
|
||||
}
|
||||
else {
|
||||
$name = $id;
|
||||
$markup = $this->t('Broken field @id', array('@id' => $id));
|
||||
$markup = $this->t('Broken field @id', ['@id' => $id]);
|
||||
}
|
||||
$form['fields'][$id]['name'] = array('#markup' => $markup);
|
||||
$form['fields'][$id]['name'] = ['#markup' => $markup];
|
||||
|
||||
$form['fields'][$id]['weight'] = array(
|
||||
$form['fields'][$id]['weight'] = [
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => ++$count,
|
||||
'#attributes' => array('class' => array('weight')),
|
||||
'#title' => t('Weight for @title', array('@title' => $name)),
|
||||
'#attributes' => ['class' => ['weight']],
|
||||
'#title' => t('Weight for @title', ['@title' => $name]),
|
||||
'#title_display' => 'invisible',
|
||||
);
|
||||
];
|
||||
|
||||
$form['fields'][$id]['removed'] = array(
|
||||
$form['fields'][$id]['removed'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Remove @title', array('@title' => $name)),
|
||||
'#title' => t('Remove @title', ['@title' => $name]),
|
||||
'#title_display' => 'invisible',
|
||||
'#id' => 'views-removed-' . $id,
|
||||
'#attributes' => array('class' => array('views-remove-checkbox')),
|
||||
'#attributes' => ['class' => ['views-remove-checkbox']],
|
||||
'#default_value' => 0,
|
||||
'#suffix' => \Drupal::l(SafeMarkup::format('<span>@text</span>', array('@text' => $this->t('Remove'))),
|
||||
Url::fromRoute('<none>', array(), array('attributes' => array(
|
||||
'#suffix' => \Drupal::l(SafeMarkup::format('<span>@text</span>', ['@text' => $this->t('Remove')]),
|
||||
Url::fromRoute('<none>', [], ['attributes' => [
|
||||
'id' => 'views-remove-link-' . $id,
|
||||
'class' => array('views-hidden', 'views-button-remove', 'views-remove-link'),
|
||||
'class' => ['views-hidden', 'views-button-remove', 'views-remove-link'],
|
||||
'alt' => $this->t('Remove this item'),
|
||||
'title' => $this->t('Remove this item')),
|
||||
))
|
||||
'title' => $this->t('Remove this item')],
|
||||
])
|
||||
),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$view->getStandardButtons($form, $form_state, 'views_ui_rearrange_form');
|
||||
@@ -152,7 +152,7 @@ class Rearrange extends ViewsFormBase {
|
||||
$display = &$view->getExecutable()->displayHandlers->get($display_id);
|
||||
|
||||
$old_fields = $display->getOption($types[$type]['plural']);
|
||||
$new_fields = $order = array();
|
||||
$new_fields = $order = [];
|
||||
|
||||
// Make an array with the weights
|
||||
foreach ($form_state->getValue('fields') as $field => $info) {
|
||||
|
||||
@@ -43,12 +43,12 @@ class RearrangeFilter extends ViewsFormBase {
|
||||
$types = ViewExecutable::getHandlerTypes();
|
||||
$executable = $view->getExecutable();
|
||||
if (!$executable->setDisplay($display_id)) {
|
||||
$form['markup'] = array('#markup' => $this->t('Invalid display id @display', array('@display' => $display_id)));
|
||||
$form['markup'] = ['#markup' => $this->t('Invalid display id @display', ['@display' => $display_id])];
|
||||
return $form;
|
||||
}
|
||||
$display = $executable->displayHandlers->get($display_id);
|
||||
$form['#title'] = Html::escape($display->display['display_title']) . ': ';
|
||||
$form['#title'] .= $this->t('Rearrange @type', array('@type' => $types[$type]['ltitle']));
|
||||
$form['#title'] .= $this->t('Rearrange @type', ['@type' => $types[$type]['ltitle']]);
|
||||
$form['#section'] = $display_id . 'rearrange-item';
|
||||
|
||||
if ($display->defaultableSections($types[$type]['plural'])) {
|
||||
@@ -68,12 +68,12 @@ class RearrangeFilter extends ViewsFormBase {
|
||||
$count = 0;
|
||||
|
||||
// Get relationship labels
|
||||
$relationships = array();
|
||||
$relationships = [];
|
||||
foreach ($display->getHandlers('relationship') as $id => $handler) {
|
||||
$relationships[$id] = $handler->adminLabel();
|
||||
}
|
||||
|
||||
$group_options = array();
|
||||
$group_options = [];
|
||||
|
||||
/**
|
||||
* Filter groups is an array that contains:
|
||||
@@ -88,58 +88,59 @@ class RearrangeFilter extends ViewsFormBase {
|
||||
$grouping = count(array_keys($groups['groups'])) > 1;
|
||||
|
||||
$form['filter_groups']['#tree'] = TRUE;
|
||||
$form['filter_groups']['operator'] = array(
|
||||
$form['filter_groups']['operator'] = [
|
||||
'#type' => 'select',
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'AND' => $this->t('And'),
|
||||
'OR' => $this->t('Or'),
|
||||
),
|
||||
],
|
||||
'#default_value' => $groups['operator'],
|
||||
'#attributes' => array(
|
||||
'class' => array('warning-on-change'),
|
||||
),
|
||||
'#attributes' => [
|
||||
'class' => ['warning-on-change'],
|
||||
],
|
||||
'#title' => $this->t('Operator to use on all groups'),
|
||||
'#description' => $this->t('Either "group 0 AND group 1 AND group 2" or "group 0 OR group 1 OR group 2", etc'),
|
||||
'#access' => $grouping,
|
||||
);
|
||||
];
|
||||
|
||||
$form['remove_groups']['#tree'] = TRUE;
|
||||
|
||||
foreach ($groups['groups'] as $id => $group) {
|
||||
$form['filter_groups']['groups'][$id] = array(
|
||||
$form['filter_groups']['groups'][$id] = [
|
||||
'#title' => $this->t('Operator'),
|
||||
'#type' => 'select',
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'AND' => $this->t('And'),
|
||||
'OR' => $this->t('Or'),
|
||||
),
|
||||
],
|
||||
'#default_value' => $group,
|
||||
'#attributes' => array(
|
||||
'class' => array('warning-on-change'),
|
||||
),
|
||||
);
|
||||
'#attributes' => [
|
||||
'class' => ['warning-on-change'],
|
||||
],
|
||||
];
|
||||
|
||||
$form['remove_groups'][$id] = array(); // to prevent a notice
|
||||
$form['remove_groups'][$id] = []; // to prevent a notice
|
||||
if ($id != 1) {
|
||||
$form['remove_groups'][$id] = array(
|
||||
$form['remove_groups'][$id] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Remove group @group', array('@group' => $id)),
|
||||
'#value' => $this->t('Remove group @group', ['@group' => $id]),
|
||||
'#id' => "views-remove-group-$id",
|
||||
'#attributes' => array(
|
||||
'class' => array('views-remove-group'),
|
||||
),
|
||||
'#attributes' => [
|
||||
'class' => ['views-remove-group'],
|
||||
],
|
||||
'#group' => $id,
|
||||
);
|
||||
'#ajax' => ['url' => NULL],
|
||||
];
|
||||
}
|
||||
$group_options[$id] = $id == 1 ? $this->t('Default group') : $this->t('Group @group', array('@group' => $id));
|
||||
$form['#group_renders'][$id] = array();
|
||||
$group_options[$id] = $id == 1 ? $this->t('Default group') : $this->t('Group @group', ['@group' => $id]);
|
||||
$form['#group_renders'][$id] = [];
|
||||
}
|
||||
|
||||
$form['#group_options'] = $group_options;
|
||||
$form['#groups'] = $groups;
|
||||
// We don't use getHandlers() because we want items without handlers to
|
||||
// appear and show up as 'broken' so that the user can see them.
|
||||
$form['filters'] = array('#tree' => TRUE);
|
||||
$form['filters'] = ['#tree' => TRUE];
|
||||
foreach ($handlers as $id => $field) {
|
||||
// If the group does not exist, move the filters to the default group.
|
||||
if (empty($field['group']) || empty($groups['groups'][$field['group']])) {
|
||||
@@ -161,24 +162,24 @@ class RearrangeFilter extends ViewsFormBase {
|
||||
// Place this item into the proper group for rendering.
|
||||
$form['#group_renders'][$field['group']][] = $id;
|
||||
|
||||
$form['filters'][$id]['weight'] = array(
|
||||
'#title' => t('Weight for @id', array('@id' => $id)),
|
||||
$form['filters'][$id]['weight'] = [
|
||||
'#title' => t('Weight for @id', ['@id' => $id]),
|
||||
'#title_display' => 'invisible',
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => ++$count,
|
||||
'#size' => 8,
|
||||
);
|
||||
$form['filters'][$id]['group'] = array(
|
||||
'#title' => t('Group for @id', array('@id' => $id)),
|
||||
];
|
||||
$form['filters'][$id]['group'] = [
|
||||
'#title' => t('Group for @id', ['@id' => $id]),
|
||||
'#title_display' => 'invisible',
|
||||
'#type' => 'select',
|
||||
'#options' => $group_options,
|
||||
'#default_value' => $field['group'],
|
||||
'#attributes' => array(
|
||||
'class' => array('views-region-select', 'views-region-' . $id),
|
||||
),
|
||||
'#attributes' => [
|
||||
'class' => ['views-region-select', 'views-region-' . $id],
|
||||
],
|
||||
'#access' => $field['group'] !== 'ungroupable',
|
||||
);
|
||||
];
|
||||
|
||||
if ($handler) {
|
||||
$name = $handler->adminLabel() . ' ' . $handler->adminSummary();
|
||||
@@ -186,34 +187,34 @@ class RearrangeFilter extends ViewsFormBase {
|
||||
$name = '(' . $relationships[$field['relationship']] . ') ' . $name;
|
||||
}
|
||||
|
||||
$form['filters'][$id]['name'] = array(
|
||||
$form['filters'][$id]['name'] = [
|
||||
'#markup' => $name,
|
||||
);
|
||||
];
|
||||
}
|
||||
else {
|
||||
$form['filters'][$id]['name'] = array('#markup' => $this->t('Broken field @id', array('@id' => $id)));
|
||||
$form['filters'][$id]['name'] = ['#markup' => $this->t('Broken field @id', ['@id' => $id])];
|
||||
}
|
||||
$form['filters'][$id]['removed'] = array(
|
||||
'#title' => t('Remove @id', array('@id' => $id)),
|
||||
$form['filters'][$id]['removed'] = [
|
||||
'#title' => t('Remove @id', ['@id' => $id]),
|
||||
'#title_display' => 'invisible',
|
||||
'#type' => 'checkbox',
|
||||
'#id' => 'views-removed-' . $id,
|
||||
'#attributes' => array('class' => array('views-remove-checkbox')),
|
||||
'#attributes' => ['class' => ['views-remove-checkbox']],
|
||||
'#default_value' => 0,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$view->getStandardButtons($form, $form_state, 'views_ui_rearrange_filter_form');
|
||||
$form['actions']['add_group'] = array(
|
||||
$form['actions']['add_group'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Create new filter group'),
|
||||
'#id' => 'views-add-group',
|
||||
'#group' => 'add',
|
||||
'#attributes' => array(
|
||||
'class' => array('views-add-group'),
|
||||
),
|
||||
'#attributes' => [
|
||||
'class' => ['views-add-group'],
|
||||
],
|
||||
'#ajax' => ['url' => NULL],
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
@@ -225,7 +226,7 @@ class RearrangeFilter extends ViewsFormBase {
|
||||
$types = ViewExecutable::getHandlerTypes();
|
||||
$view = $form_state->get('view');
|
||||
$display = &$view->getExecutable()->displayHandlers->get($form_state->get('display_id'));
|
||||
$remember_groups = array();
|
||||
$remember_groups = [];
|
||||
|
||||
if (!empty($view->form_cache)) {
|
||||
$old_fields = $view->form_cache['handlers'];
|
||||
@@ -236,7 +237,7 @@ class RearrangeFilter extends ViewsFormBase {
|
||||
|
||||
$groups = $form_state->getValue('filter_groups');
|
||||
// Whatever button was clicked, re-calculate field information.
|
||||
$new_fields = $order = array();
|
||||
$new_fields = $order = [];
|
||||
|
||||
// Make an array with the weights
|
||||
foreach ($form_state->getValue('filters') as $field => $info) {
|
||||
@@ -331,7 +332,7 @@ class RearrangeFilter extends ViewsFormBase {
|
||||
*
|
||||
* For example array(0 => 'foo') would be array(1 => 'foo').
|
||||
*
|
||||
* @param array
|
||||
* @param array $array
|
||||
* The array to increment keys on.
|
||||
*
|
||||
* @return array
|
||||
|
||||
@@ -40,10 +40,10 @@ class ReorderDisplays extends ViewsFormBase {
|
||||
'view' => $view->id(),
|
||||
'display_id' => $display_id,
|
||||
]);
|
||||
$form['view'] = array(
|
||||
$form['view'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $view
|
||||
);
|
||||
];
|
||||
|
||||
$displays = $view->get('display');
|
||||
$count = count($displays);
|
||||
@@ -56,82 +56,82 @@ class ReorderDisplays extends ViewsFormBase {
|
||||
return 0;
|
||||
});
|
||||
|
||||
$form['displays'] = array(
|
||||
$form['displays'] = [
|
||||
'#type' => 'table',
|
||||
'#id' => 'reorder-displays',
|
||||
'#header' => array($this->t('Display'), $this->t('Weight'), $this->t('Remove')),
|
||||
'#header' => [$this->t('Display'), $this->t('Weight'), $this->t('Remove')],
|
||||
'#empty' => $this->t('No displays available.'),
|
||||
'#tabledrag' => array(
|
||||
array(
|
||||
'#tabledrag' => [
|
||||
[
|
||||
'action' => 'order',
|
||||
'relationship' => 'sibling',
|
||||
'group' => 'weight',
|
||||
)
|
||||
),
|
||||
]
|
||||
],
|
||||
'#tree' => TRUE,
|
||||
'#prefix' => '<div class="scroll" data-drupal-views-scroll>',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
];
|
||||
|
||||
foreach ($displays as $id => $display) {
|
||||
$form['displays'][$id] = array(
|
||||
$form['displays'][$id] = [
|
||||
'#display' => $display,
|
||||
'#attributes' => array(
|
||||
'#attributes' => [
|
||||
'id' => 'display-row-' . $id,
|
||||
),
|
||||
],
|
||||
'#weight' => $display['position'],
|
||||
);
|
||||
];
|
||||
|
||||
// Only make row draggable if it's not the default display.
|
||||
if ($id !== 'default') {
|
||||
$form['displays'][$id]['#attributes']['class'][] = 'draggable';
|
||||
}
|
||||
|
||||
$form['displays'][$id]['title'] = array(
|
||||
$form['displays'][$id]['title'] = [
|
||||
'#markup' => $display['display_title'],
|
||||
);
|
||||
];
|
||||
|
||||
$form['displays'][$id]['weight'] = array(
|
||||
$form['displays'][$id]['weight'] = [
|
||||
'#type' => 'weight',
|
||||
'#value' => $display['position'],
|
||||
'#delta' => $count,
|
||||
'#title' => $this->t('Weight for @display', array('@display' => $display['display_title'])),
|
||||
'#title' => $this->t('Weight for @display', ['@display' => $display['display_title']]),
|
||||
'#title_display' => 'invisible',
|
||||
'#attributes' => array(
|
||||
'class' => array('weight'),
|
||||
),
|
||||
);
|
||||
'#attributes' => [
|
||||
'class' => ['weight'],
|
||||
],
|
||||
];
|
||||
|
||||
$form['displays'][$id]['removed'] = array(
|
||||
'checkbox' => array(
|
||||
'#title' => t('Remove @id', array('@id' => $id)),
|
||||
$form['displays'][$id]['removed'] = [
|
||||
'checkbox' => [
|
||||
'#title' => t('Remove @id', ['@id' => $id]),
|
||||
'#title_display' => 'invisible',
|
||||
'#type' => 'checkbox',
|
||||
'#id' => 'display-removed-' . $id,
|
||||
'#attributes' => array(
|
||||
'class' => array('views-remove-checkbox'),
|
||||
),
|
||||
'#attributes' => [
|
||||
'class' => ['views-remove-checkbox'],
|
||||
],
|
||||
'#default_value' => !empty($display['deleted']),
|
||||
),
|
||||
'link' => array(
|
||||
],
|
||||
'link' => [
|
||||
'#type' => 'link',
|
||||
'#title' => SafeMarkup::format('<span>@text</span>', array('@text' => $this->t('Remove'))),
|
||||
'#title' => SafeMarkup::format('<span>@text</span>', ['@text' => $this->t('Remove')]),
|
||||
'#url' => Url::fromRoute('<none>'),
|
||||
'#attributes' => array(
|
||||
'#attributes' => [
|
||||
'id' => 'display-remove-link-' . $id,
|
||||
'class' => array('views-button-remove', 'display-remove-link'),
|
||||
'class' => ['views-button-remove', 'display-remove-link'],
|
||||
'alt' => $this->t('Remove this display'),
|
||||
'title' => $this->t('Remove this display'),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
'#access' => ($id !== 'default'),
|
||||
);
|
||||
];
|
||||
|
||||
if (!empty($display['deleted'])) {
|
||||
$form['displays'][$id]['deleted'] = array(
|
||||
$form['displays'][$id]['deleted'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
$form['displays'][$id]['#attributes']['class'][] = 'hidden';
|
||||
}
|
||||
@@ -149,7 +149,7 @@ class ReorderDisplays extends ViewsFormBase {
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
/** @var $view \Drupal\views_ui\ViewUI */
|
||||
$view = $form_state->get('view');
|
||||
$order = array();
|
||||
$order = [];
|
||||
|
||||
$user_input = $form_state->getUserInput();
|
||||
foreach ($user_input['displays'] as $display => $info) {
|
||||
|
||||
@@ -108,7 +108,7 @@ abstract class ViewsFormBase extends FormBase implements ViewsFormInterface {
|
||||
unset($view->stack[$key]);
|
||||
|
||||
if (array_shift($top) != $identifier) {
|
||||
$view->stack = array();
|
||||
$view->stack = [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ abstract class ViewsFormBase extends FormBase implements ViewsFormInterface {
|
||||
$form_state = $reflection->newInstanceArgs(array_slice($top, 3, 2))->getFormState($view, $top[2], $form_state->get('ajax'));
|
||||
$form_class = get_class($form_state->getFormObject());
|
||||
|
||||
$form_state->setUserInput(array());
|
||||
$form_state->setUserInput([]);
|
||||
$form_url = views_ui_build_form_url($form_state);
|
||||
if (!$form_state->get('ajax')) {
|
||||
return new RedirectResponse($form_url->setAbsolute()->toString());
|
||||
@@ -234,16 +234,16 @@ abstract class ViewsFormBase extends FormBase implements ViewsFormInterface {
|
||||
$response->setAttachments($form['#attached']);
|
||||
|
||||
$display = '';
|
||||
$status_messages = array('#type' => 'status_messages');
|
||||
$status_messages = ['#type' => 'status_messages'];
|
||||
if ($messages = $renderer->renderRoot($status_messages)) {
|
||||
$display = '<div class="views-messages">' . $messages . '</div>';
|
||||
}
|
||||
$display .= $output;
|
||||
|
||||
$options = array(
|
||||
$options = [
|
||||
'dialogClass' => 'views-ui-dialog js-views-ui-dialog',
|
||||
'width' => '75%',
|
||||
);
|
||||
];
|
||||
|
||||
$response->addCommand(new OpenModalDialogCommand($title, $display, $options));
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ class BasicSettingsForm extends ConfigFormBase {
|
||||
$form = parent::buildForm($form, $form_state);
|
||||
|
||||
$config = $this->config('views.settings');
|
||||
$options = array();
|
||||
$options = [];
|
||||
foreach ($this->themeHandler->listInfo() as $name => $theme) {
|
||||
if ($theme->status) {
|
||||
$options[$name] = $theme->info['name'];
|
||||
@@ -74,94 +74,94 @@ class BasicSettingsForm extends ConfigFormBase {
|
||||
|
||||
// This is not currently a fieldset but we may want it to be later,
|
||||
// so this will make it easier to change if we do.
|
||||
$form['basic'] = array();
|
||||
$form['basic'] = [];
|
||||
|
||||
$form['basic']['ui_show_master_display'] = array(
|
||||
$form['basic']['ui_show_master_display'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Always show the master (default) display'),
|
||||
'#default_value' => $config->get('ui.show.master_display'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['basic']['ui_show_advanced_column'] = array(
|
||||
$form['basic']['ui_show_advanced_column'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Always show advanced display settings'),
|
||||
'#default_value' => $config->get('ui.show.advanced_column'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['basic']['ui_show_display_embed'] = array(
|
||||
$form['basic']['ui_show_display_embed'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Allow embedded displays'),
|
||||
'#description' => t('Embedded displays can be used in code via views_embed_view().'),
|
||||
'#default_value' => $config->get('ui.show.display_embed'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['basic']['ui_exposed_filter_any_label'] = array(
|
||||
$form['basic']['ui_exposed_filter_any_label'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Label for "Any" value on non-required single-select exposed filters'),
|
||||
'#options' => array('old_any' => '<Any>', 'new_any' => $this->t('- Any -')),
|
||||
'#options' => ['old_any' => '<Any>', 'new_any' => $this->t('- Any -')],
|
||||
'#default_value' => $config->get('ui.exposed_filter_any_label'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['live_preview'] = array(
|
||||
$form['live_preview'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Live preview settings'),
|
||||
'#open' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
$form['live_preview']['ui_always_live_preview'] = array(
|
||||
$form['live_preview']['ui_always_live_preview'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Automatically update preview on changes'),
|
||||
'#default_value' => $config->get('ui.always_live_preview'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['live_preview']['ui_show_preview_information'] = array(
|
||||
$form['live_preview']['ui_show_preview_information'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Show information and statistics about the view during live preview'),
|
||||
'#default_value' => $config->get('ui.show.preview_information'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['live_preview']['options'] = array(
|
||||
$form['live_preview']['options'] = [
|
||||
'#type' => 'container',
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
':input[name="ui_show_preview_information"]' => array('checked' => TRUE),
|
||||
),
|
||||
),
|
||||
);
|
||||
'#states' => [
|
||||
'visible' => [
|
||||
':input[name="ui_show_preview_information"]' => ['checked' => TRUE],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$form['live_preview']['options']['ui_show_sql_query_enabled'] = array(
|
||||
$form['live_preview']['options']['ui_show_sql_query_enabled'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Show the SQL query'),
|
||||
'#default_value' => $config->get('ui.show.sql_query.enabled'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['live_preview']['options']['ui_show_sql_query_where'] = array(
|
||||
$form['live_preview']['options']['ui_show_sql_query_where'] = [
|
||||
'#type' => 'radios',
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
':input[name="ui_show_sql_query_enabled"]' => array('checked' => TRUE),
|
||||
),
|
||||
),
|
||||
'#states' => [
|
||||
'visible' => [
|
||||
':input[name="ui_show_sql_query_enabled"]' => ['checked' => TRUE],
|
||||
],
|
||||
],
|
||||
'#title' => t('Show SQL query'),
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'above' => $this->t('Above the preview'),
|
||||
'below' => $this->t('Below the preview'),
|
||||
),
|
||||
],
|
||||
'#default_value' => $config->get('ui.show.sql_query.where'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['live_preview']['options']['ui_show_performance_statistics'] = array(
|
||||
$form['live_preview']['options']['ui_show_performance_statistics'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Show performance statistics'),
|
||||
'#default_value' => $config->get('ui.show.performance_statistics'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['live_preview']['options']['ui_show_additional_queries'] = array(
|
||||
$form['live_preview']['options']['ui_show_additional_queries'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Show other queries run during render during live preview'),
|
||||
'#description' => $this->t("Drupal has the potential to run many queries while a view is being rendered. Checking this box will display every query run during view render as part of the live preview."),
|
||||
'#default_value' => $config->get('ui.show.additional_queries'),
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ class BreakLockForm extends EntityConfirmFormBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return $this->t('Do you want to break the lock on view %name?', array('%name' => $this->entity->id()));
|
||||
return $this->t('Do you want to break the lock on view %name?', ['%name' => $this->entity->id()]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,11 +70,11 @@ class BreakLockForm extends EntityConfirmFormBase {
|
||||
public function getDescription() {
|
||||
$locked = $this->tempStore->getMetadata($this->entity->id());
|
||||
$account = $this->entityManager->getStorage('user')->load($locked->owner);
|
||||
$username = array(
|
||||
$username = [
|
||||
'#theme' => 'username',
|
||||
'#account' => $account,
|
||||
);
|
||||
return $this->t('By breaking this lock, any unsaved changes made by @user will be lost.', array('@user' => drupal_render($username)));
|
||||
];
|
||||
return $this->t('By breaking this lock, any unsaved changes made by @user will be lost.', ['@user' => drupal_render($username)]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,7 +96,7 @@ class BreakLockForm extends EntityConfirmFormBase {
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
if (!$this->tempStore->getMetadata($this->entity->id())) {
|
||||
$form['message']['#markup'] = $this->t('There is no lock on view %name to break.', array('%name' => $this->entity->id()));
|
||||
$form['message']['#markup'] = $this->t('There is no lock on view %name to break.', ['%name' => $this->entity->id()]);
|
||||
return $form;
|
||||
}
|
||||
return parent::buildForm($form, $form_state);
|
||||
|
||||
@@ -16,25 +16,44 @@ class ExposedFormUITest extends UITestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_exposed_admin_ui');
|
||||
public static $testViews = ['test_exposed_admin_ui'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['node', 'views_ui', 'block', 'taxonomy', 'field_ui', 'datetime'];
|
||||
|
||||
/**
|
||||
* Array of error message strings raised by the grouped form.
|
||||
*
|
||||
* @var array
|
||||
*
|
||||
* @see FilterPluginBase::buildGroupValidate
|
||||
*/
|
||||
protected $groupFormUiErrors = [];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType(array('type' => 'article'));
|
||||
$this->drupalCreateContentType(array('type' => 'page'));
|
||||
$this->drupalCreateContentType(['type' => 'article']);
|
||||
$this->drupalCreateContentType(['type' => 'page']);
|
||||
|
||||
// Create some random nodes.
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$this->drupalCreateNode();
|
||||
}
|
||||
|
||||
// Error strings used in the grouped filter form validation.
|
||||
$this->groupFormUiErrors['missing_value'] = t('A value is required if the label for this item is defined.');
|
||||
$this->groupFormUiErrors['missing_title'] = t('A label is required if the value for this item is defined.');
|
||||
$this->groupFormUiErrors['missing_title_empty_operator'] = t('A label is required for the specified operator.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the admin interface of exposed filter and sort items.
|
||||
*/
|
||||
function testExposedAdminUi() {
|
||||
$edit = array();
|
||||
public function testExposedAdminUi() {
|
||||
$edit = [];
|
||||
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/type');
|
||||
// Be sure that the button is called exposed.
|
||||
@@ -51,8 +70,6 @@ class ExposedFormUITest extends UITestBase {
|
||||
$this->drupalPostForm('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/type', $edit, t('Expose filter'));
|
||||
// Check the label of the expose button.
|
||||
$this->helperButtonHasLabel('edit-options-expose-button-button', t('Hide filter'));
|
||||
// Check the label of the grouped exposed button
|
||||
$this->helperButtonHasLabel('edit-options-group-button-button', t('Grouped filters'));
|
||||
|
||||
// After exposing the filter, Operator and Value should be still here.
|
||||
$this->assertFieldById('edit-options-operator-in', '', 'Operator In exists');
|
||||
@@ -61,12 +78,12 @@ class ExposedFormUITest extends UITestBase {
|
||||
$this->assertFieldById('edit-options-value-article', '', 'Checkbox for Article exists');
|
||||
|
||||
// Check the validations of the filter handler.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['options[expose][identifier]'] = '';
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
$this->assertText(t('The identifier is required if the filter is exposed.'));
|
||||
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['options[expose][identifier]'] = 'value';
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
$this->assertText(t('This identifier is not allowed.'));
|
||||
@@ -76,65 +93,9 @@ class ExposedFormUITest extends UITestBase {
|
||||
$this->helperButtonHasLabel('edit-options-expose-button-button', t('Expose sort'));
|
||||
$this->assertNoFieldById('edit-options-expose-label', '', 'Make sure no label field is shown');
|
||||
|
||||
// Click the Grouped Filters button.
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/type');
|
||||
$this->drupalPostForm(NULL, array(), t('Grouped filters'));
|
||||
|
||||
// After click on 'Grouped Filters', the standard operator and value should
|
||||
// not be displayed.
|
||||
$this->assertNoFieldById('edit-options-operator-in', '', 'Operator In not exists');
|
||||
$this->assertNoFieldById('edit-options-operator-not-in', '', 'Operator Not In not exists');
|
||||
$this->assertNoFieldById('edit-options-value-page', '', 'Checkbox for Page not exists');
|
||||
$this->assertNoFieldById('edit-options-value-article', '', 'Checkbox for Article not exists');
|
||||
|
||||
// Check that after click on 'Grouped Filters', a new button is shown to
|
||||
// add more items to the list.
|
||||
$this->helperButtonHasLabel('edit-options-group-info-add-group', t('Add another item'));
|
||||
|
||||
// Create a grouped filter
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/type');
|
||||
$edit = array();
|
||||
$edit["options[group_info][group_items][1][title]"] = 'Is Article';
|
||||
$edit["options[group_info][group_items][1][value][article]"] = 'article';
|
||||
|
||||
$edit["options[group_info][group_items][2][title]"] = 'Is Page';
|
||||
$edit["options[group_info][group_items][2][value][page]"] = TRUE;
|
||||
|
||||
$edit["options[group_info][group_items][3][title]"] = 'Is Page and Article';
|
||||
$edit["options[group_info][group_items][3][value][article]"] = TRUE;
|
||||
$edit["options[group_info][group_items][3][value][page]"] = TRUE;
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
|
||||
// Select the empty operator, so the empty value should not trigger a form
|
||||
// error.
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/body_value');
|
||||
$edit = array();
|
||||
$edit["options[group_info][group_items][1][title]"] = $this->randomMachineName();
|
||||
$edit["options[group_info][group_items][1][operator]"] = 'empty';
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
$this->assertUrl('admin/structure/views/view/test_exposed_admin_ui/edit/default', array(), 'Validation did not run for the empty operator.');
|
||||
// Test the validation error message text is not shown.
|
||||
$this->assertNoText(t('The value is required if title for this item is defined.'));
|
||||
|
||||
// Validate that all the titles are defined for each group
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/type');
|
||||
$edit = array();
|
||||
$edit["options[group_info][group_items][1][title]"] = 'Is Article';
|
||||
$edit["options[group_info][group_items][1][value][article]"] = TRUE;
|
||||
|
||||
// This should trigger an error
|
||||
$edit["options[group_info][group_items][2][title]"] = '';
|
||||
$edit["options[group_info][group_items][2][value][page]"] = TRUE;
|
||||
|
||||
$edit["options[group_info][group_items][3][title]"] = 'Is Page and Article';
|
||||
$edit["options[group_info][group_items][3][value][article]"] = TRUE;
|
||||
$edit["options[group_info][group_items][3][value][page]"] = TRUE;
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
$this->assertRaw(t('The title is required if value for this item is defined.'), 'Group items should have a title');
|
||||
|
||||
// Un-expose the filter.
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/type');
|
||||
$this->drupalPostForm(NULL, array(), t('Hide filter'));
|
||||
$this->drupalPostForm(NULL, [], t('Hide filter'));
|
||||
|
||||
// After Un-exposing the filter, Operator and Value should be shown again.
|
||||
$this->assertFieldById('edit-options-operator-in', '', 'Operator In exists after hide filter');
|
||||
@@ -143,7 +104,7 @@ class ExposedFormUITest extends UITestBase {
|
||||
$this->assertFieldById('edit-options-value-article', '', 'Checkbox for Article exists after hide filter');
|
||||
|
||||
// Click the Expose sort button.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$this->drupalPostForm('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/sort/created', $edit, t('Expose sort'));
|
||||
// Check the label of the expose button.
|
||||
$this->helperButtonHasLabel('edit-options-expose-button-button', t('Hide sort'));
|
||||
@@ -170,4 +131,190 @@ class ExposedFormUITest extends UITestBase {
|
||||
$this->assertEqual($display['display_options']['sorts']['created']['order'], 'DESC');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the admin interface of exposed grouped filters.
|
||||
*/
|
||||
public function testGroupedFilterAdminUi() {
|
||||
$edit = [];
|
||||
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/type');
|
||||
|
||||
// Click the Expose filter button.
|
||||
$this->drupalPostForm('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/type', $edit, t('Expose filter'));
|
||||
// Check the label of the grouped filters button.
|
||||
$this->helperButtonHasLabel('edit-options-group-button-button', t('Grouped filters'));
|
||||
|
||||
// Click the Grouped Filters button.
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/type');
|
||||
$this->drupalPostForm(NULL, [], t('Grouped filters'));
|
||||
|
||||
// After click on 'Grouped Filters', the standard operator and value should
|
||||
// not be displayed.
|
||||
$this->assertNoFieldById('edit-options-operator-in', '', 'Operator In not exists');
|
||||
$this->assertNoFieldById('edit-options-operator-not-in', '', 'Operator Not In not exists');
|
||||
$this->assertNoFieldById('edit-options-value-page', '', 'Checkbox for Page not exists');
|
||||
$this->assertNoFieldById('edit-options-value-article', '', 'Checkbox for Article not exists');
|
||||
|
||||
// Check that after click on 'Grouped Filters', a new button is shown to
|
||||
// add more items to the list.
|
||||
$this->helperButtonHasLabel('edit-options-group-info-add-group', t('Add another item'));
|
||||
|
||||
// Validate a single entry for a grouped filter.
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/type');
|
||||
$edit = [];
|
||||
$edit["options[group_info][group_items][1][title]"] = 'Is Article';
|
||||
$edit["options[group_info][group_items][1][value][article]"] = 'article';
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
$this->assertUrl('admin/structure/views/view/test_exposed_admin_ui/edit/default');
|
||||
$this->assertNoGroupedFilterErrors();
|
||||
|
||||
// Validate multiple entries for grouped filters.
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/type');
|
||||
$edit = [];
|
||||
$edit["options[group_info][group_items][1][title]"] = 'Is Article';
|
||||
$edit["options[group_info][group_items][1][value][article]"] = 'article';
|
||||
$edit["options[group_info][group_items][2][title]"] = 'Is Page';
|
||||
$edit["options[group_info][group_items][2][value][page]"] = 'page';
|
||||
$edit["options[group_info][group_items][3][title]"] = 'Is Page and Article';
|
||||
$edit["options[group_info][group_items][3][value][article]"] = 'article';
|
||||
$edit["options[group_info][group_items][3][value][page]"] = 'page';
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
$this->assertUrl('admin/structure/views/view/test_exposed_admin_ui/edit/default', [], 'Correct validation of the node type filter.');
|
||||
$this->assertNoGroupedFilterErrors();
|
||||
|
||||
// Validate an "is empty" filter -- title without value is valid.
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/body_value');
|
||||
$edit = [];
|
||||
$edit["options[group_info][group_items][1][title]"] = 'No body';
|
||||
$edit["options[group_info][group_items][1][operator]"] = 'empty';
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
$this->assertUrl('admin/structure/views/view/test_exposed_admin_ui/edit/default', [], 'The "empty" operator validates correctly.');
|
||||
$this->assertNoGroupedFilterErrors();
|
||||
|
||||
// Ensure the string "0" can be used as a value for numeric filters.
|
||||
$this->drupalPostForm('admin/structure/views/nojs/add-handler/test_exposed_admin_ui/default/filter', ['name[node_field_data.nid]' => TRUE], t('Add and configure @handler', ['@handler' => t('filter criteria')]));
|
||||
$this->drupalPostForm(NULL, [], t('Expose filter'));
|
||||
$this->drupalPostForm(NULL, [], t('Grouped filters'));
|
||||
$edit = [];
|
||||
$edit['options[group_info][group_items][1][title]'] = 'Testing zero';
|
||||
$edit['options[group_info][group_items][1][operator]'] = '>';
|
||||
$edit['options[group_info][group_items][1][value][value]'] = '0';
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
$this->assertUrl('admin/structure/views/view/test_exposed_admin_ui/edit/default', [], 'A string "0" is a valid value.');
|
||||
$this->assertNoGroupedFilterErrors();
|
||||
|
||||
// Ensure "between" filters validate correctly.
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/nid');
|
||||
$edit['options[group_info][group_items][1][title]'] = 'ID between test';
|
||||
$edit['options[group_info][group_items][1][operator]'] = 'between';
|
||||
$edit['options[group_info][group_items][1][value][min]'] = '0';
|
||||
$edit['options[group_info][group_items][1][value][max]'] = '10';
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
$this->assertUrl('admin/structure/views/view/test_exposed_admin_ui/edit/default', [], 'The "between" filter validates correctly.');
|
||||
$this->assertNoGroupedFilterErrors();
|
||||
}
|
||||
|
||||
public function testGroupedFilterAdminUiErrors() {
|
||||
// Select the empty operator without a title specified.
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/body_value');
|
||||
$edit = [];
|
||||
$edit["options[group_info][group_items][1][title]"] = '';
|
||||
$edit["options[group_info][group_items][1][operator]"] = 'empty';
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
$this->assertText($this->groupFormUiErrors['missing_title_empty_operator']);
|
||||
|
||||
// Specify a title without a value.
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/type');
|
||||
$this->drupalPostForm('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/type', [], t('Expose filter'));
|
||||
$this->drupalPostForm('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/type', [], t('Grouped filters'));
|
||||
$edit = [];
|
||||
$edit["options[group_info][group_items][1][title]"] = 'Is Article';
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
$this->assertText($this->groupFormUiErrors['missing_value']);
|
||||
|
||||
// Specify a value without a title.
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/type');
|
||||
$edit = [];
|
||||
$edit["options[group_info][group_items][1][title]"] = '';
|
||||
$edit["options[group_info][group_items][1][value][article]"] = 'article';
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
$this->assertText($this->groupFormUiErrors['missing_title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that there are no Grouped Filters errors.
|
||||
*
|
||||
* @param string $message
|
||||
* The assert message.
|
||||
* @param string $group
|
||||
* The assertion group.
|
||||
*
|
||||
* @return bool
|
||||
* Result of the assertion.
|
||||
*/
|
||||
protected function assertNoGroupedFilterErrors($message = '', $group = 'Other') {
|
||||
foreach ($this->groupFormUiErrors as $error) {
|
||||
$err_message = $message;
|
||||
if (empty($err_message)) {
|
||||
$err_message = "Verify that '$error' is not in the HTML output.";
|
||||
}
|
||||
if (empty($message)) {
|
||||
return $this->assertNoRaw($error, $err_message, $group);
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the configuration of grouped exposed filters.
|
||||
*/
|
||||
public function testExposedGroupedFilter() {
|
||||
// Click the Expose filter button.
|
||||
$this->drupalPostForm('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/type', [], t('Expose filter'));
|
||||
// Select 'Grouped filters' radio button.
|
||||
$this->drupalPostForm('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/type', [], t('Grouped filters'));
|
||||
// Add 3 groupings.
|
||||
$edit = [
|
||||
'options[group_button][radios][radios]' => 1,
|
||||
'options[group_info][group_items][1][title]' => '1st',
|
||||
'options[group_info][group_items][1][value][all]' => 'all',
|
||||
'options[group_info][group_items][2][title]' => '2nd',
|
||||
'options[group_info][group_items][2][value][article]' => 'article',
|
||||
'options[group_info][group_items][3][title]' => '3rd',
|
||||
'options[group_info][group_items][3][value][page]' => 'page',
|
||||
];
|
||||
// Apply the filter settings.
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
// Check that the view is saved without errors.
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
$this->assertResponse(200);
|
||||
|
||||
// Click the Expose filter button.
|
||||
$this->drupalPostForm('admin/structure/views/nojs/add-handler/test_exposed_admin_ui/default/filter', ['name[node_field_data.status]' => 1], t('Add and configure filter criteria'));
|
||||
$this->drupalPostForm('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/status', [], t('Expose filter'));
|
||||
// Select 'Grouped filters' radio button.
|
||||
$this->drupalPostForm('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/status', [], t('Grouped filters'));
|
||||
// Add 3 groupings.
|
||||
$edit = [
|
||||
'options[group_button][radios][radios]' => 1,
|
||||
'options[group_info][group_items][1][title]' => 'Any',
|
||||
'options[group_info][group_items][1][value]' => 'All',
|
||||
'options[group_info][group_items][2][title]' => 'Published',
|
||||
'options[group_info][group_items][2][value]' => 1,
|
||||
'options[group_info][group_items][3][title]' => 'Unpublished',
|
||||
'options[group_info][group_items][3][value]' => 0,
|
||||
];
|
||||
// Apply the filter settings.
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
// Check that the view is saved without errors.
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
$this->assertResponse(200);
|
||||
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/status');
|
||||
// Assert the same settings defined before still are there.
|
||||
$this->assertFieldChecked('edit-options-group-info-group-items-1-value-all');
|
||||
$this->assertFieldChecked('edit-options-group-info-group-items-2-value-1');
|
||||
$this->assertFieldChecked('edit-options-group-info-group-items-3-value-0');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Drupal\views_ui\Tests;
|
||||
|
||||
use Drupal\Component\Serialization\Json;
|
||||
use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
|
||||
|
||||
/**
|
||||
* Tests the UI preview functionality.
|
||||
@@ -16,23 +17,23 @@ class PreviewTest extends UITestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_preview', 'test_preview_error', 'test_pager_full', 'test_mini_pager', 'test_click_sort');
|
||||
public static $testViews = ['test_preview', 'test_preview_error', 'test_pager_full', 'test_mini_pager', 'test_click_sort'];
|
||||
|
||||
/**
|
||||
* Tests contextual links in the preview form.
|
||||
*/
|
||||
public function testPreviewContextual() {
|
||||
\Drupal::service('module_installer')->install(array('contextual'));
|
||||
\Drupal::service('module_installer')->install(['contextual']);
|
||||
$this->resetAll();
|
||||
|
||||
$this->drupalGet('admin/structure/views/view/test_preview/edit');
|
||||
$this->assertResponse(200);
|
||||
$this->drupalPostForm(NULL, $edit = array(), t('Update preview'));
|
||||
$this->drupalPostForm(NULL, $edit = [], t('Update preview'));
|
||||
|
||||
$elements = $this->xpath('//div[@id="views-live-preview"]//ul[contains(@class, :ul-class)]/li[contains(@class, :li-class)]', array(':ul-class' => 'contextual-links', ':li-class' => 'filter-add'));
|
||||
$elements = $this->xpath('//div[@id="views-live-preview"]//ul[contains(@class, :ul-class)]/li[contains(@class, :li-class)]', [':ul-class' => 'contextual-links', ':li-class' => 'filter-add']);
|
||||
$this->assertEqual(count($elements), 1, 'The contextual link to add a new field is shown.');
|
||||
|
||||
$this->drupalPostForm(NULL, $edit = array('view_args' => '100'), t('Update preview'));
|
||||
$this->drupalPostForm(NULL, $edit = ['view_args' => '100'], t('Update preview'));
|
||||
|
||||
// Test that area text and exposed filters are present and rendered.
|
||||
$this->assertFieldByName('id', NULL, 'ID exposed filter field found.');
|
||||
@@ -44,23 +45,23 @@ class PreviewTest extends UITestBase {
|
||||
/**
|
||||
* Tests arguments in the preview form.
|
||||
*/
|
||||
function testPreviewUI() {
|
||||
public function testPreviewUI() {
|
||||
$this->drupalGet('admin/structure/views/view/test_preview/edit');
|
||||
$this->assertResponse(200);
|
||||
|
||||
$this->drupalPostForm(NULL, $edit = array(), t('Update preview'));
|
||||
$this->drupalPostForm(NULL, $edit = [], t('Update preview'));
|
||||
|
||||
$elements = $this->xpath('//div[@class = "view-content"]/div[contains(@class, views-row)]');
|
||||
$this->assertEqual(count($elements), 5);
|
||||
|
||||
// Filter just the first result.
|
||||
$this->drupalPostForm(NULL, $edit = array('view_args' => '1'), t('Update preview'));
|
||||
$this->drupalPostForm(NULL, $edit = ['view_args' => '1'], t('Update preview'));
|
||||
|
||||
$elements = $this->xpath('//div[@class = "view-content"]/div[contains(@class, views-row)]');
|
||||
$this->assertEqual(count($elements), 1);
|
||||
|
||||
// Filter for no results.
|
||||
$this->drupalPostForm(NULL, $edit = array('view_args' => '100'), t('Update preview'));
|
||||
$this->drupalPostForm(NULL, $edit = ['view_args' => '100'], t('Update preview'));
|
||||
|
||||
$elements = $this->xpath('//div[@class = "view-content"]/div[contains(@class, views-row)]');
|
||||
$this->assertEqual(count($elements), 0);
|
||||
@@ -72,7 +73,7 @@ class PreviewTest extends UITestBase {
|
||||
$this->assertText('Test empty text', 'Rendered empty text found.');
|
||||
|
||||
// Test feed preview.
|
||||
$view = array();
|
||||
$view = [];
|
||||
$view['label'] = $this->randomMachineName(16);
|
||||
$view['id'] = strtolower($this->randomMachineName(16));
|
||||
$view['page[create]'] = 1;
|
||||
@@ -82,7 +83,7 @@ class PreviewTest extends UITestBase {
|
||||
$view['page[feed_properties][path]'] = $this->randomMachineName(16);
|
||||
$this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
|
||||
$this->clickLink(t('Feed'));
|
||||
$this->drupalPostForm(NULL, array(), t('Update preview'));
|
||||
$this->drupalPostForm(NULL, [], t('Update preview'));
|
||||
$result = $this->xpath('//div[@id="views-live-preview"]/pre');
|
||||
$this->assertTrue(strpos($result[0], '<title>' . $view['page[title]'] . '</title>'), 'The Feed RSS preview was rendered.');
|
||||
|
||||
@@ -91,7 +92,7 @@ class PreviewTest extends UITestBase {
|
||||
$settings = \Drupal::configFactory()->getEditable('views.settings');
|
||||
$settings->set('ui.show.performance_statistics', TRUE)->save();
|
||||
$this->drupalGet('admin/structure/views/view/test_preview/edit');
|
||||
$this->drupalPostForm(NULL, $edit = array('view_args' => '100'), t('Update preview'));
|
||||
$this->drupalPostForm(NULL, $edit = ['view_args' => '100'], t('Update preview'));
|
||||
$this->assertText(t('Query build time'));
|
||||
$this->assertText(t('Query execute time'));
|
||||
$this->assertText(t('View render time'));
|
||||
@@ -99,20 +100,26 @@ class PreviewTest extends UITestBase {
|
||||
|
||||
// Statistics and query.
|
||||
$settings->set('ui.show.sql_query.enabled', TRUE)->save();
|
||||
$this->drupalPostForm(NULL, $edit = array('view_args' => '100'), t('Update preview'));
|
||||
$this->drupalPostForm(NULL, $edit = ['view_args' => '100'], t('Update preview'));
|
||||
$this->assertText(t('Query build time'));
|
||||
$this->assertText(t('Query execute time'));
|
||||
$this->assertText(t('View render time'));
|
||||
$this->assertRaw('<strong>Query</strong>');
|
||||
$this->assertText("SELECT views_test_data.name AS views_test_data_name\nFROM \n{views_test_data} views_test_data\nWHERE (( (views_test_data.id = '100' ) ))");
|
||||
$this->assertText("SELECT views_test_data.name AS views_test_data_name\nFROM \n{views_test_data} views_test_data\nWHERE (views_test_data.id = '100' )");
|
||||
|
||||
// Test that the statistics and query are rendered above the preview.
|
||||
$this->assertTrue(strpos($this->getRawContent(), 'views-query-info') < strpos($this->getRawContent(), 'view-test-preview'), 'Statistics shown above the preview.');
|
||||
|
||||
// Test that statistics and query rendered below the preview.
|
||||
$settings->set('ui.show.sql_query.where', 'below')->save();
|
||||
$this->drupalPostForm(NULL, $edit = array('view_args' => '100'), t('Update preview'));
|
||||
$this->drupalPostForm(NULL, $edit = ['view_args' => '100'], t('Update preview'));
|
||||
$this->assertTrue(strpos($this->getRawContent(), 'view-test-preview') < strpos($this->getRawContent(), 'views-query-info'), 'Statistics shown below the preview.');
|
||||
|
||||
// Test that the preview title isn't double escaped.
|
||||
$this->drupalPostForm("admin/structure/views/nojs/display/test_preview/default/title", $edit = ['title' => 'Double & escaped'], t('Apply'));
|
||||
$this->drupalPostForm(NULL, [], t('Update preview'));
|
||||
$elements = $this->xpath('//div[@id="views-live-preview"]/div[contains(@class, views-query-info)]//td[text()=:text]', [':text' => t('Double & escaped')]);
|
||||
$this->assertEqual(1, count($elements));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,7 +130,7 @@ class PreviewTest extends UITestBase {
|
||||
* @see https://www.drupal.org/node/2452659
|
||||
*/
|
||||
public function testTaxonomyAJAX() {
|
||||
\Drupal::service('module_installer')->install(array('taxonomy'));
|
||||
\Drupal::service('module_installer')->install(['taxonomy']);
|
||||
$this->getPreviewAJAX('taxonomy_term', 'page_1', 0);
|
||||
}
|
||||
|
||||
@@ -133,7 +140,7 @@ class PreviewTest extends UITestBase {
|
||||
public function testPreviewWithPagersUI() {
|
||||
|
||||
// Create 11 nodes and make sure that everyone is returned.
|
||||
$this->drupalCreateContentType(array('type' => 'page'));
|
||||
$this->drupalCreateContentType(['type' => 'page']);
|
||||
for ($i = 0; $i < 11; $i++) {
|
||||
$this->drupalCreateNode();
|
||||
}
|
||||
@@ -142,7 +149,7 @@ class PreviewTest extends UITestBase {
|
||||
$this->getPreviewAJAX('test_pager_full', 'default', 5);
|
||||
|
||||
// Test that the pager is present and rendered.
|
||||
$elements = $this->xpath('//ul[contains(@class, :class)]/li', array(':class' => 'pager__items'));
|
||||
$elements = $this->xpath('//ul[contains(@class, :class)]/li', [':class' => 'pager__items']);
|
||||
$this->assertTrue(!empty($elements), 'Full pager found.');
|
||||
|
||||
// Verify elements and links to pages.
|
||||
@@ -164,11 +171,11 @@ class PreviewTest extends UITestBase {
|
||||
$this->assertTrue($elements[4]->a, 'Link to last page found.');
|
||||
|
||||
// Navigate to next page.
|
||||
$elements = $this->xpath('//li[contains(@class, :class)]/a', array(':class' => 'pager__item--next'));
|
||||
$elements = $this->xpath('//li[contains(@class, :class)]/a', [':class' => 'pager__item--next']);
|
||||
$this->clickPreviewLinkAJAX($elements[0]['href'], 5);
|
||||
|
||||
// Test that the pager is present and rendered.
|
||||
$elements = $this->xpath('//ul[contains(@class, :class)]/li', array(':class' => 'pager__items'));
|
||||
$elements = $this->xpath('//ul[contains(@class, :class)]/li', [':class' => 'pager__items']);
|
||||
$this->assertTrue(!empty($elements), 'Full pager found.');
|
||||
|
||||
// Verify elements and links to pages.
|
||||
@@ -200,7 +207,7 @@ class PreviewTest extends UITestBase {
|
||||
$this->getPreviewAJAX('test_mini_pager', 'default', 3);
|
||||
|
||||
// Test that the pager is present and rendered.
|
||||
$elements = $this->xpath('//ul[contains(@class, :class)]/li', array(':class' => 'pager__items'));
|
||||
$elements = $this->xpath('//ul[contains(@class, :class)]/li', [':class' => 'pager__items']);
|
||||
$this->assertTrue(!empty($elements), 'Mini pager found.');
|
||||
|
||||
// Verify elements and links to pages.
|
||||
@@ -212,11 +219,11 @@ class PreviewTest extends UITestBase {
|
||||
$this->assertTrue($elements[1]->a, 'Link to next page found.');
|
||||
|
||||
// Navigate to next page.
|
||||
$elements = $this->xpath('//li[contains(@class, :class)]/a', array(':class' => 'pager__item--next'));
|
||||
$elements = $this->xpath('//li[contains(@class, :class)]/a', [':class' => 'pager__item--next']);
|
||||
$this->clickPreviewLinkAJAX($elements[0]['href'], 3);
|
||||
|
||||
// Test that the pager is present and rendered.
|
||||
$elements = $this->xpath('//ul[contains(@class, :class)]/li', array(':class' => 'pager__items'));
|
||||
$elements = $this->xpath('//ul[contains(@class, :class)]/li', [':class' => 'pager__items']);
|
||||
$this->assertTrue(!empty($elements), 'Mini pager found.');
|
||||
|
||||
// Verify elements and links to pages.
|
||||
@@ -236,17 +243,17 @@ class PreviewTest extends UITestBase {
|
||||
* Tests the additional information query info area.
|
||||
*/
|
||||
public function testPreviewAdditionalInfo() {
|
||||
\Drupal::service('module_installer')->install(array('views_ui_test'));
|
||||
\Drupal::service('module_installer')->install(['views_ui_test']);
|
||||
$this->resetAll();
|
||||
|
||||
$this->drupalGet('admin/structure/views/view/test_preview/edit');
|
||||
$this->assertResponse(200);
|
||||
|
||||
$this->drupalPostForm(NULL, $edit = array(), t('Update preview'));
|
||||
$this->drupalPostForm(NULL, $edit = [], t('Update preview'));
|
||||
|
||||
// Check for implementation of hook_views_preview_info_alter().
|
||||
// @see views_ui_test.module
|
||||
$elements = $this->xpath('//div[@id="views-live-preview"]/div[contains(@class, views-query-info)]//td[text()=:text]', array(':text' => t('Test row count')));
|
||||
$elements = $this->xpath('//div[@id="views-live-preview"]/div[contains(@class, views-query-info)]//td[text()=:text]', [':text' => t('Test row count')]);
|
||||
$this->assertEqual(count($elements), 1, 'Views Query Preview Info area altered.');
|
||||
// Check that additional assets are attached.
|
||||
$this->assertTrue(strpos($this->getDrupalSettings()['ajaxPageState']['libraries'], 'views_ui_test/views_ui_test.test') !== FALSE, 'Attached library found.');
|
||||
@@ -260,7 +267,7 @@ class PreviewTest extends UITestBase {
|
||||
$this->drupalGet('admin/structure/views/view/test_preview_error/edit');
|
||||
$this->assertResponse(200);
|
||||
|
||||
$this->drupalPostForm(NULL, $edit = array(), t('Update preview'));
|
||||
$this->drupalPostForm(NULL, $edit = [], t('Update preview'));
|
||||
|
||||
$this->assertText('Unable to preview due to validation errors.', 'Preview error text found.');
|
||||
}
|
||||
@@ -274,7 +281,7 @@ class PreviewTest extends UITestBase {
|
||||
$this->getPreviewAJAX('test_click_sort', 'page_1', 0);
|
||||
|
||||
// Test that the header label is present.
|
||||
$elements = $this->xpath('//th[contains(@class, :class)]/a', array(':class' => 'views-field views-field-name'));
|
||||
$elements = $this->xpath('//th[contains(@class, :class)]/a', [':class' => 'views-field views-field-name']);
|
||||
$this->assertTrue(!empty($elements), 'The header label is present.');
|
||||
|
||||
// Verify link.
|
||||
@@ -284,7 +291,7 @@ class PreviewTest extends UITestBase {
|
||||
$this->clickPreviewLinkAJAX($elements[0]['href'], 0);
|
||||
|
||||
// Test that the header label is present.
|
||||
$elements = $this->xpath('//th[contains(@class, :class)]/a', array(':class' => 'views-field views-field-name is-active'));
|
||||
$elements = $this->xpath('//th[contains(@class, :class)]/a', [':class' => 'views-field views-field-name is-active']);
|
||||
$this->assertTrue(!empty($elements), 'The header label is present.');
|
||||
|
||||
// Verify link.
|
||||
@@ -303,7 +310,7 @@ class PreviewTest extends UITestBase {
|
||||
*/
|
||||
protected function getPreviewAJAX($view_name, $panel_id, $row_count) {
|
||||
$this->drupalGet('admin/structure/views/view/' . $view_name . '/preview/' . $panel_id);
|
||||
$result = $this->drupalPostAjaxForm(NULL, array(), array('op' => t('Update preview')));
|
||||
$result = $this->drupalPostAjaxForm(NULL, [], ['op' => t('Update preview')]);
|
||||
$this->assertPreviewAJAX($result, $row_count);
|
||||
}
|
||||
|
||||
@@ -318,13 +325,13 @@ class PreviewTest extends UITestBase {
|
||||
protected function clickPreviewLinkAJAX($url, $row_count) {
|
||||
$content = $this->content;
|
||||
$drupal_settings = $this->drupalSettings;
|
||||
$ajax_settings = array(
|
||||
$ajax_settings = [
|
||||
'wrapper' => 'views-preview-wrapper',
|
||||
'method' => 'replaceWith',
|
||||
);
|
||||
];
|
||||
$url = $this->getAbsoluteUrl($url);
|
||||
$post = array('js' => 'true') + $this->getAjaxPageStatePostData();
|
||||
$result = Json::decode($this->drupalPost($url, 'application/vnd.drupal-ajax', $post));
|
||||
$post = ['js' => 'true'] + $this->getAjaxPageStatePostData();
|
||||
$result = Json::decode($this->drupalPost($url, '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]));
|
||||
if (!empty($result)) {
|
||||
$this->drupalProcessAjaxResponse($content, $result, $ajax_settings, $drupal_settings);
|
||||
}
|
||||
@@ -342,7 +349,7 @@ class PreviewTest extends UITestBase {
|
||||
protected function assertPreviewAJAX($result, $row_count) {
|
||||
// Has AJAX callback replied with an insert command? If so, we can
|
||||
// assume that the page content was updated with AJAX returned data.
|
||||
$result_commands = array();
|
||||
$result_commands = [];
|
||||
foreach ($result as $command) {
|
||||
$result_commands[$command['command']] = $command;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ class RowUITest extends UITestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_view');
|
||||
public static $testViews = ['test_view'];
|
||||
|
||||
/**
|
||||
* Tests changing the row plugin and changing some options of a row.
|
||||
@@ -33,20 +33,20 @@ class RowUITest extends UITestBase {
|
||||
$this->drupalGet($row_plugin_url);
|
||||
$this->assertFieldByName('row[type]', 'fields', 'The default row plugin selected in the UI should be fields.');
|
||||
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'row[type]' => 'test_row'
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
$this->assertFieldByName('row_options[test_option]', NULL, 'Make sure the custom settings form from the test plugin appears.');
|
||||
$random_name = $this->randomMachineName();
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'row_options[test_option]' => $random_name
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
$this->drupalGet($row_options_url);
|
||||
$this->assertFieldByName('row_options[test_option]', $random_name, 'Make sure the custom settings form field has the expected value stored.');
|
||||
|
||||
$this->drupalPostForm($view_edit_url, array(), t('Save'));
|
||||
$this->drupalPostForm($view_edit_url, [], t('Save'));
|
||||
$this->assertLink(t('Test row plugin'), 0, 'Make sure the test row plugin is shown in the UI');
|
||||
|
||||
$view = Views::getView($view_name);
|
||||
|
||||
@@ -6,6 +6,9 @@ use Drupal\views\Tests\ViewTestBase;
|
||||
|
||||
/**
|
||||
* Provides a base class for testing the Views UI.
|
||||
*
|
||||
* @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.x.
|
||||
* Use \Drupal\Tests\views_ui\Functional\UITestBase.
|
||||
*/
|
||||
abstract class UITestBase extends ViewTestBase {
|
||||
|
||||
@@ -28,7 +31,7 @@ abstract class UITestBase extends ViewTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'views_ui', 'block', 'taxonomy');
|
||||
public static $modules = ['node', 'views_ui', 'block', 'taxonomy'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -38,24 +41,26 @@ abstract class UITestBase extends ViewTestBase {
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
|
||||
$this->adminUser = $this->drupalCreateUser(array('administer views'));
|
||||
$this->adminUser = $this->drupalCreateUser(['administer views']);
|
||||
|
||||
$this->fullAdminUser = $this->drupalCreateUser(array('administer views',
|
||||
$this->fullAdminUser = $this->drupalCreateUser(['administer views',
|
||||
'administer blocks',
|
||||
'bypass node access',
|
||||
'access user profiles',
|
||||
'view all revisions',
|
||||
'administer permissions',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($this->fullAdminUser);
|
||||
|
||||
@trigger_error('\Drupal\views_ui\Tests\UITestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.x. Instead, use \Drupal\Tests\views_ui\Functional\UITestBase', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
/**
|
||||
* A helper method which creates a random view.
|
||||
*/
|
||||
public function randomView(array $view = array()) {
|
||||
public function randomView(array $view = []) {
|
||||
// Create a new view in the UI.
|
||||
$default = array();
|
||||
$default = [];
|
||||
$default['label'] = $this->randomMachineName(16);
|
||||
$default['id'] = strtolower($this->randomMachineName(16));
|
||||
$default['description'] = $this->randomMachineName(16);
|
||||
@@ -72,7 +77,7 @@ abstract class UITestBase extends ViewTestBase {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function drupalGet($path, array $options = array(), array $headers = array()) {
|
||||
protected function drupalGet($path, array $options = [], array $headers = []) {
|
||||
$url = $this->buildUrl($path, $options);
|
||||
|
||||
// Ensure that each nojs page is accessible via ajax as well.
|
||||
|
||||
@@ -17,7 +17,7 @@ class ViewEditTest extends UITestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_view', 'test_display', 'test_groupwise_term_ui');
|
||||
public static $testViews = ['test_view', 'test_display', 'test_groupwise_term_ui'];
|
||||
|
||||
/**
|
||||
* Tests the delete link on a views UI.
|
||||
@@ -30,8 +30,8 @@ class ViewEditTest extends UITestBase {
|
||||
$this->assertTrue($view instanceof View);
|
||||
$this->clickLink(t('Delete view'));
|
||||
$this->assertUrl('admin/structure/views/view/test_view/delete');
|
||||
$this->drupalPostForm(NULL, array(), t('Delete'));
|
||||
$this->assertRaw(t('The view %name has been deleted.', array('%name' => $view->label())));
|
||||
$this->drupalPostForm(NULL, [], t('Delete'));
|
||||
$this->assertRaw(t('The view %name has been deleted.', ['%name' => $view->label()]));
|
||||
|
||||
$this->assertUrl('admin/structure/views');
|
||||
$view = $this->container->get('entity.manager')->getStorage('view')->load('test_view');
|
||||
@@ -44,26 +44,32 @@ class ViewEditTest extends UITestBase {
|
||||
public function testOtherOptions() {
|
||||
$this->drupalGet('admin/structure/views/view/test_view');
|
||||
// Add a new attachment display.
|
||||
$this->drupalPostForm(NULL, array(), 'Add Attachment');
|
||||
$this->drupalPostForm(NULL, [], 'Add Attachment');
|
||||
|
||||
// Test that a long administrative comment is truncated.
|
||||
$edit = array('display_comment' => 'one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen');
|
||||
$edit = ['display_comment' => 'one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen'];
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/test_view/attachment_1/display_comment', $edit, 'Apply');
|
||||
$this->assertText('one two three four five six seven eight nine ten eleven twelve thirteen fourteen...');
|
||||
|
||||
// Change the machine name for the display from page_1 to test_1.
|
||||
$edit = array('display_id' => 'test_1');
|
||||
$edit = ['display_id' => 'test_1'];
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/test_view/attachment_1/display_id', $edit, 'Apply');
|
||||
$this->assertLink(t('test_1'));
|
||||
|
||||
// Save the view, and test the new ID has been saved.
|
||||
$this->drupalPostForm(NULL, array(), 'Save');
|
||||
$this->drupalPostForm(NULL, [], 'Save');
|
||||
$view = \Drupal::entityManager()->getStorage('view')->load('test_view');
|
||||
$displays = $view->get('display');
|
||||
$this->assertTrue(!empty($displays['test_1']), 'Display data found for new display ID key.');
|
||||
$this->assertIdentical($displays['test_1']['id'], 'test_1', 'New display ID matches the display ID key.');
|
||||
$this->assertFalse(array_key_exists('attachment_1', $displays), 'Old display ID not found.');
|
||||
|
||||
// Set to the same machine name and save the View.
|
||||
$edit = ['display_id' => 'test_1'];
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/test_view/test_1/display_id', $edit, 'Apply');
|
||||
$this->drupalPostForm(NULL, [], 'Save');
|
||||
$this->assertLink(t('test_1'));
|
||||
|
||||
// Test the form validation with invalid IDs.
|
||||
$machine_name_edit_url = 'admin/structure/views/nojs/display/test_view/test_1/display_id';
|
||||
$error_text = t('Display name must be letters, numbers, or underscores only.');
|
||||
@@ -72,16 +78,16 @@ class ViewEditTest extends UITestBase {
|
||||
$this->drupalGet('admin/structure/views/ajax/handler/test_view/fake_display_name/filter/title');
|
||||
$this->assertText('Invalid display id fake_display_name');
|
||||
|
||||
$edit = array('display_id' => 'test 1');
|
||||
$edit = ['display_id' => 'test 1'];
|
||||
$this->drupalPostForm($machine_name_edit_url, $edit, 'Apply');
|
||||
$this->assertText($error_text);
|
||||
|
||||
$edit = array('display_id' => 'test_1#');
|
||||
$edit = ['display_id' => 'test_1#'];
|
||||
$this->drupalPostForm($machine_name_edit_url, $edit, 'Apply');
|
||||
$this->assertText($error_text);
|
||||
|
||||
// Test using an existing display ID.
|
||||
$edit = array('display_id' => 'default');
|
||||
$edit = ['display_id' => 'default'];
|
||||
$this->drupalPostForm($machine_name_edit_url, $edit, 'Apply');
|
||||
$this->assertText(t('Display id should be unique.'));
|
||||
|
||||
@@ -97,10 +103,10 @@ class ViewEditTest extends UITestBase {
|
||||
$fields['fields[id][removed]'] = 1;
|
||||
$fields['fields[name][removed]'] = 1;
|
||||
$this->drupalPostForm('admin/structure/views/nojs/rearrange/test_view/default/field', $fields, t('Apply'));
|
||||
$this->drupalPostForm(NULL, array(), 'Save');
|
||||
$this->drupalPostForm(NULL, array(), t('Cancel'));
|
||||
$this->drupalPostForm(NULL, [], 'Save');
|
||||
$this->drupalPostForm(NULL, [], t('Cancel'));
|
||||
$this->assertNoFieldByXpath('//div[contains(@class, "error")]', FALSE, 'No error message is displayed.');
|
||||
$this->assertUrl('admin/structure/views', array(), 'Redirected back to the view listing page..');
|
||||
$this->assertUrl('admin/structure/views', [], 'Redirected back to the view listing page..');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,21 +114,21 @@ class ViewEditTest extends UITestBase {
|
||||
*/
|
||||
public function testEditFormLanguageOptions() {
|
||||
// Language options should not exist without language module.
|
||||
$test_views = array(
|
||||
$test_views = [
|
||||
'test_view' => 'default',
|
||||
'test_display' => 'page_1',
|
||||
);
|
||||
];
|
||||
foreach ($test_views as $view_name => $display) {
|
||||
$this->drupalGet('admin/structure/views/view/' . $view_name);
|
||||
$this->assertResponse(200);
|
||||
$langcode_url = 'admin/structure/views/nojs/display/' . $view_name . '/' . $display . '/rendering_language';
|
||||
$this->assertNoLinkByHref($langcode_url);
|
||||
$this->assertNoLink(t('@type language selected for page', array('@type' => t('Content'))));
|
||||
$this->assertNoLink(t('@type language selected for page', ['@type' => t('Content')]));
|
||||
$this->assertNoLink(t('Content language of view row'));
|
||||
}
|
||||
|
||||
// Make the site multilingual and test the options again.
|
||||
$this->container->get('module_installer')->install(array('language', 'content_translation'));
|
||||
$this->container->get('module_installer')->install(['language', 'content_translation']);
|
||||
ConfigurableLanguage::createFromLangcode('hu')->save();
|
||||
$this->resetAll();
|
||||
$this->rebuildContainer();
|
||||
@@ -134,12 +140,12 @@ class ViewEditTest extends UITestBase {
|
||||
$langcode_url = 'admin/structure/views/nojs/display/' . $view_name . '/' . $display . '/rendering_language';
|
||||
if ($view_name == 'test_view') {
|
||||
$this->assertNoLinkByHref($langcode_url);
|
||||
$this->assertNoLink(t('@type language selected for page', array('@type' => t('Content'))));
|
||||
$this->assertNoLink(t('@type language selected for page', ['@type' => t('Content')]));
|
||||
$this->assertNoLink(t('Content language of view row'));
|
||||
}
|
||||
else {
|
||||
$this->assertLinkByHref($langcode_url);
|
||||
$this->assertNoLink(t('@type language selected for page', array('@type' => t('Content'))));
|
||||
$this->assertNoLink(t('@type language selected for page', ['@type' => t('Content')]));
|
||||
$this->assertLink(t('Content language of view row'));
|
||||
}
|
||||
|
||||
@@ -152,14 +158,14 @@ class ViewEditTest extends UITestBase {
|
||||
$this->assertFieldByName('rendering_language', '***LANGUAGE_entity_translation***');
|
||||
// Test that the order of the language list is similar to other language
|
||||
// lists, such as in the content translation settings.
|
||||
$expected_elements = array(
|
||||
$expected_elements = [
|
||||
'***LANGUAGE_entity_translation***',
|
||||
'***LANGUAGE_entity_default***',
|
||||
'***LANGUAGE_site_default***',
|
||||
'***LANGUAGE_language_interface***',
|
||||
'en',
|
||||
'hu',
|
||||
);
|
||||
];
|
||||
$elements = $this->xpath('//select[@id="edit-rendering-language"]/option');
|
||||
// Compare values inside the option elements with expected values.
|
||||
for ($i = 0; $i < count($elements); $i++) {
|
||||
@@ -202,7 +208,7 @@ class ViewEditTest extends UITestBase {
|
||||
$this->drupalGet($langcode_url);
|
||||
$this->assertResponse(200);
|
||||
|
||||
$expected_elements = array(
|
||||
$expected_elements = [
|
||||
'all',
|
||||
'***LANGUAGE_site_default***',
|
||||
'***LANGUAGE_language_interface***',
|
||||
@@ -211,7 +217,7 @@ class ViewEditTest extends UITestBase {
|
||||
'hu',
|
||||
'und',
|
||||
'zxx',
|
||||
);
|
||||
];
|
||||
$elements = $this->xpath('//div[@id="edit-options-value"]//input');
|
||||
// Compare values inside the option elements with expected values.
|
||||
for ($i = 0; $i < count($elements); $i++) {
|
||||
@@ -229,7 +235,7 @@ class ViewEditTest extends UITestBase {
|
||||
$edit["name[taxonomy_term_field_data.tid_representative]"] = TRUE;
|
||||
$this->drupalPostForm('admin/structure/views/nojs/add-handler/test_groupwise_term_ui/default/relationship', $edit, 'Add and configure relationships');
|
||||
// Apply changes.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$this->drupalPostForm('admin/structure/views/nojs/handler/test_groupwise_term_ui/default/relationship/tid_representative', $edit, 'Apply');
|
||||
}
|
||||
|
||||
|
||||
@@ -31,11 +31,11 @@ class ViewsUITourTest extends TourTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('views_ui', 'tour', 'language', 'locale');
|
||||
public static $modules = ['views_ui', 'tour', 'language', 'locale'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->adminUser = $this->drupalCreateUser(array('administer views', 'access tour'));
|
||||
$this->adminUser = $this->drupalCreateUser(['administer views', 'access tour']);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
}
|
||||
|
||||
@@ -66,18 +66,18 @@ class ViewsUITourTest extends TourTestBase {
|
||||
ConfigurableLanguage::createFromLangcode($langcode)->save();
|
||||
|
||||
// Handler titles that need translations.
|
||||
$handler_titles = array(
|
||||
$handler_titles = [
|
||||
'Format',
|
||||
'Fields',
|
||||
'Sort criteria',
|
||||
'Filter criteria',
|
||||
);
|
||||
];
|
||||
|
||||
foreach ($handler_titles as $handler_title) {
|
||||
// Create source string.
|
||||
$source = $this->localeStorage->createString(array(
|
||||
$source = $this->localeStorage->createString([
|
||||
'source' => $handler_title
|
||||
));
|
||||
]);
|
||||
$source->save();
|
||||
$this->createTranslation($source, $langcode);
|
||||
}
|
||||
@@ -101,11 +101,11 @@ class ViewsUITourTest extends TourTestBase {
|
||||
* Creates single translation for source string.
|
||||
*/
|
||||
public function createTranslation($source, $langcode) {
|
||||
return $this->localeStorage->createTranslation(array(
|
||||
return $this->localeStorage->createTranslation([
|
||||
'lid' => $source->lid,
|
||||
'language' => $langcode,
|
||||
'translation' => $this->randomMachineName(100),
|
||||
))->save();
|
||||
])->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,83 +51,83 @@ class ViewAddForm extends ViewFormBase {
|
||||
*/
|
||||
public function form(array $form, FormStateInterface $form_state) {
|
||||
$form['#attached']['library'][] = 'views_ui/views_ui.admin';
|
||||
$form['#attributes']['class'] = array('views-admin');
|
||||
$form['#attributes']['class'] = ['views-admin'];
|
||||
|
||||
$form['name'] = array(
|
||||
$form['name'] = [
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('View basic information'),
|
||||
'#attributes' => array('class' => array('fieldset-no-legend')),
|
||||
);
|
||||
'#attributes' => ['class' => ['fieldset-no-legend']],
|
||||
];
|
||||
|
||||
$form['name']['label'] = array(
|
||||
$form['name']['label'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('View name'),
|
||||
'#required' => TRUE,
|
||||
'#size' => 32,
|
||||
'#default_value' => '',
|
||||
'#maxlength' => 255,
|
||||
);
|
||||
$form['name']['id'] = array(
|
||||
];
|
||||
$form['name']['id'] = [
|
||||
'#type' => 'machine_name',
|
||||
'#maxlength' => 128,
|
||||
'#machine_name' => array(
|
||||
'#machine_name' => [
|
||||
'exists' => '\Drupal\views\Views::getView',
|
||||
'source' => array('name', 'label'),
|
||||
),
|
||||
'source' => ['name', 'label'],
|
||||
],
|
||||
'#description' => $this->t('A unique machine-readable name for this View. It must only contain lowercase letters, numbers, and underscores.'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['name']['description_enable'] = array(
|
||||
$form['name']['description_enable'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Description'),
|
||||
);
|
||||
$form['name']['description'] = array(
|
||||
];
|
||||
$form['name']['description'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Provide description'),
|
||||
'#title_display' => 'invisible',
|
||||
'#size' => 64,
|
||||
'#default_value' => '',
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
':input[name="description_enable"]' => array('checked' => TRUE),
|
||||
),
|
||||
),
|
||||
);
|
||||
'#states' => [
|
||||
'visible' => [
|
||||
':input[name="description_enable"]' => ['checked' => TRUE],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// Create a wrapper for the entire dynamic portion of the form. Everything
|
||||
// that can be updated by AJAX goes somewhere inside here. For example, this
|
||||
// is needed by "Show" dropdown (below); it changes the base table of the
|
||||
// view and therefore potentially requires all options on the form to be
|
||||
// dynamically updated.
|
||||
$form['displays'] = array();
|
||||
$form['displays'] = [];
|
||||
|
||||
// Create the part of the form that allows the user to select the basic
|
||||
// properties of what the view will display.
|
||||
$form['displays']['show'] = array(
|
||||
$form['displays']['show'] = [
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('View settings'),
|
||||
'#tree' => TRUE,
|
||||
'#attributes' => array('class' => array('container-inline')),
|
||||
);
|
||||
'#attributes' => ['class' => ['container-inline']],
|
||||
];
|
||||
|
||||
// Create the "Show" dropdown, which allows the base table of the view to be
|
||||
// selected.
|
||||
$wizard_plugins = $this->wizardManager->getDefinitions();
|
||||
$options = array();
|
||||
$options = [];
|
||||
foreach ($wizard_plugins as $key => $wizard) {
|
||||
$options[$key] = $wizard['title'];
|
||||
}
|
||||
$form['displays']['show']['wizard_key'] = array(
|
||||
$form['displays']['show']['wizard_key'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Show'),
|
||||
'#options' => $options,
|
||||
);
|
||||
];
|
||||
$show_form = &$form['displays']['show'];
|
||||
$default_value = \Drupal::moduleHandler()->moduleExists('node') ? 'node' : 'users';
|
||||
$show_form['wizard_key']['#default_value'] = WizardPluginBase::getSelected($form_state, array('show', 'wizard_key'), $default_value, $show_form['wizard_key']);
|
||||
$show_form['wizard_key']['#default_value'] = WizardPluginBase::getSelected($form_state, ['show', 'wizard_key'], $default_value, $show_form['wizard_key']);
|
||||
// Changing this dropdown updates the entire content of $form['displays'] via
|
||||
// AJAX.
|
||||
views_ui_add_ajax_trigger($show_form, 'wizard_key', array('displays'));
|
||||
views_ui_add_ajax_trigger($show_form, 'wizard_key', ['displays']);
|
||||
|
||||
// Build the rest of the form based on the currently selected wizard plugin.
|
||||
$wizard_key = $show_form['wizard_key']['#default_value'];
|
||||
@@ -144,13 +144,13 @@ class ViewAddForm extends ViewFormBase {
|
||||
$actions = parent::actions($form, $form_state);
|
||||
$actions['submit']['#value'] = $this->t('Save and edit');
|
||||
// Remove EntityFormController::save() form the submission handlers.
|
||||
$actions['submit']['#submit'] = array(array($this, 'submitForm'));
|
||||
$actions['cancel'] = array(
|
||||
$actions['submit']['#submit'] = [[$this, 'submitForm']];
|
||||
$actions['cancel'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Cancel'),
|
||||
'#submit' => array('::cancel'),
|
||||
'#limit_validation_errors' => array(),
|
||||
);
|
||||
'#submit' => ['::cancel'],
|
||||
'#limit_validation_errors' => [],
|
||||
];
|
||||
return $actions;
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ class ViewAddForm extends ViewFormBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validateForm(array &$form, FormStateInterface $form_state) {
|
||||
$wizard_type = $form_state->getValue(array('show', 'wizard_key'));
|
||||
$wizard_type = $form_state->getValue(['show', 'wizard_key']);
|
||||
$wizard_instance = $this->wizardManager->createInstance($wizard_type);
|
||||
$form_state->set('wizard', $wizard_instance->getPluginDefinition());
|
||||
$form_state->set('wizard_instance', $wizard_instance);
|
||||
@@ -187,7 +187,7 @@ class ViewAddForm extends ViewFormBase {
|
||||
return;
|
||||
}
|
||||
$this->entity->save();
|
||||
drupal_set_message($this->t('The view %name has been saved.', array('%name' => $form_state->getValue('label'))));
|
||||
drupal_set_message($this->t('The view %name has been saved.', ['%name' => $form_state->getValue('label')]));
|
||||
$form_state->setRedirectUrl($this->entity->urlInfo('edit-form'));
|
||||
}
|
||||
|
||||
|
||||
@@ -22,26 +22,26 @@ class ViewDuplicateForm extends ViewFormBase {
|
||||
public function form(array $form, FormStateInterface $form_state) {
|
||||
parent::form($form, $form_state);
|
||||
|
||||
$form['#title'] = $this->t('Duplicate of @label', array('@label' => $this->entity->label()));
|
||||
$form['#title'] = $this->t('Duplicate of @label', ['@label' => $this->entity->label()]);
|
||||
|
||||
$form['label'] = array(
|
||||
$form['label'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('View name'),
|
||||
'#required' => TRUE,
|
||||
'#size' => 32,
|
||||
'#maxlength' => 255,
|
||||
'#default_value' => $this->t('Duplicate of @label', array('@label' => $this->entity->label())),
|
||||
);
|
||||
$form['id'] = array(
|
||||
'#default_value' => $this->t('Duplicate of @label', ['@label' => $this->entity->label()]),
|
||||
];
|
||||
$form['id'] = [
|
||||
'#type' => 'machine_name',
|
||||
'#maxlength' => 128,
|
||||
'#machine_name' => array(
|
||||
'#machine_name' => [
|
||||
'exists' => '\Drupal\views\Views::getView',
|
||||
'source' => array('label'),
|
||||
),
|
||||
'source' => ['label'],
|
||||
],
|
||||
'#default_value' => '',
|
||||
'#description' => $this->t('A unique machine-readable name for this View. It must only contain lowercase letters, numbers, and underscores.'),
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
@@ -50,10 +50,10 @@ class ViewDuplicateForm extends ViewFormBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function actions(array $form, FormStateInterface $form_state) {
|
||||
$actions['submit'] = array(
|
||||
$actions['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Duplicate'),
|
||||
);
|
||||
];
|
||||
return $actions;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace Drupal\views_ui;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Utility\Xss;
|
||||
use Drupal\Core\Ajax\AjaxResponse;
|
||||
use Drupal\Core\Ajax\HtmlCommand;
|
||||
use Drupal\Core\Ajax\ReplaceCommand;
|
||||
@@ -99,7 +98,7 @@ class ViewEditForm extends ViewFormBase {
|
||||
|
||||
if ($display_id) {
|
||||
if (!$view->getExecutable()->setDisplay($display_id)) {
|
||||
$form['#markup'] = $this->t('Invalid display id @display', array('@display' => $display_id));
|
||||
$form['#markup'] = $this->t('Invalid display id @display', ['@display' => $display_id]);
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
@@ -113,55 +112,55 @@ class ViewEditForm extends ViewFormBase {
|
||||
$form['#attached']['library'][] = 'views_ui/views_ui.admin';
|
||||
$form['#attached']['library'][] = 'views_ui/admin.styling';
|
||||
|
||||
$form += array(
|
||||
$form += [
|
||||
'#prefix' => '',
|
||||
'#suffix' => '',
|
||||
);
|
||||
];
|
||||
|
||||
$view_status = $view->status() ? 'enabled' : 'disabled';
|
||||
$form['#prefix'] .= '<div class="views-edit-view views-admin ' . $view_status . ' clearfix">';
|
||||
$form['#suffix'] = '</div>' . $form['#suffix'];
|
||||
|
||||
$form['#attributes']['class'] = array('form-edit');
|
||||
$form['#attributes']['class'] = ['form-edit'];
|
||||
|
||||
if ($view->isLocked()) {
|
||||
$username = array(
|
||||
$username = [
|
||||
'#theme' => 'username',
|
||||
'#account' => $this->entityManager->getStorage('user')->load($view->lock->owner),
|
||||
);
|
||||
$lock_message_substitutions = array(
|
||||
];
|
||||
$lock_message_substitutions = [
|
||||
'@user' => drupal_render($username),
|
||||
'@age' => $this->dateFormatter->formatTimeDiffSince($view->lock->updated),
|
||||
':url' => $view->url('break-lock-form'),
|
||||
);
|
||||
$form['locked'] = array(
|
||||
];
|
||||
$form['locked'] = [
|
||||
'#type' => 'container',
|
||||
'#attributes' => array('class' => array('view-locked', 'messages', 'messages--warning')),
|
||||
'#attributes' => ['class' => ['view-locked', 'messages', 'messages--warning']],
|
||||
'#children' => $this->t('This view is being edited by user @user, and is therefore locked from editing by others. This lock is @age old. Click here to <a href=":url">break this lock</a>.', $lock_message_substitutions),
|
||||
'#weight' => -10,
|
||||
);
|
||||
];
|
||||
}
|
||||
else {
|
||||
$form['changed'] = array(
|
||||
$form['changed'] = [
|
||||
'#type' => 'container',
|
||||
'#attributes' => array('class' => array('view-changed', 'messages', 'messages--warning')),
|
||||
'#attributes' => ['class' => ['view-changed', 'messages', 'messages--warning']],
|
||||
'#children' => $this->t('You have unsaved changes.'),
|
||||
'#weight' => -10,
|
||||
);
|
||||
];
|
||||
if (empty($view->changed)) {
|
||||
$form['changed']['#attributes']['class'][] = 'js-hide';
|
||||
}
|
||||
}
|
||||
|
||||
$form['displays'] = array(
|
||||
$form['displays'] = [
|
||||
'#prefix' => '<h1 class="unit-title clearfix">' . $this->t('Displays') . '</h1>',
|
||||
'#type' => 'container',
|
||||
'#attributes' => array(
|
||||
'class' => array(
|
||||
'#attributes' => [
|
||||
'class' => [
|
||||
'views-displays',
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
$form['displays']['top'] = $this->renderDisplayTop($view);
|
||||
@@ -171,13 +170,13 @@ class ViewEditForm extends ViewFormBase {
|
||||
$form_state->set('display_id', $display_id);
|
||||
|
||||
// The part of the page where editing will take place.
|
||||
$form['displays']['settings'] = array(
|
||||
$form['displays']['settings'] = [
|
||||
'#type' => 'container',
|
||||
'#id' => 'edit-display-settings',
|
||||
'#attributes' => array(
|
||||
'class' => array('edit-display-settings'),
|
||||
),
|
||||
);
|
||||
'#attributes' => [
|
||||
'class' => ['edit-display-settings'],
|
||||
],
|
||||
];
|
||||
|
||||
// Add a text that the display is disabled.
|
||||
if ($view->getExecutable()->displayHandlers->has($display_id)) {
|
||||
@@ -188,8 +187,8 @@ class ViewEditForm extends ViewFormBase {
|
||||
|
||||
// Add the edit display content
|
||||
$tab_content = $this->getDisplayTab($view);
|
||||
$tab_content['#theme_wrappers'] = array('container');
|
||||
$tab_content['#attributes'] = array('class' => array('views-display-tab'));
|
||||
$tab_content['#theme_wrappers'] = ['container'];
|
||||
$tab_content['#attributes'] = ['class' => ['views-display-tab']];
|
||||
$tab_content['#id'] = 'views-tab-' . $display_id;
|
||||
// Mark deleted displays as such.
|
||||
$display = $view->get('display');
|
||||
@@ -201,10 +200,10 @@ class ViewEditForm extends ViewFormBase {
|
||||
if ($view->getExecutable()->displayHandlers->has($display_id) && !$view->getExecutable()->displayHandlers->get($display_id)->isEnabled()) {
|
||||
$tab_content['#attributes']['class'][] = 'views-display-disabled';
|
||||
}
|
||||
$form['displays']['settings']['settings_content'] = array(
|
||||
$form['displays']['settings']['settings_content'] = [
|
||||
'#type' => 'container',
|
||||
'tab_content' => $tab_content,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
return $form;
|
||||
@@ -217,12 +216,12 @@ class ViewEditForm extends ViewFormBase {
|
||||
$actions = parent::actions($form, $form_state);
|
||||
unset($actions['delete']);
|
||||
|
||||
$actions['cancel'] = array(
|
||||
$actions['cancel'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Cancel'),
|
||||
'#submit' => array('::cancel'),
|
||||
'#limit_validation_errors' => array(),
|
||||
);
|
||||
'#submit' => ['::cancel'],
|
||||
'#limit_validation_errors' => [],
|
||||
];
|
||||
if ($this->entity->isLocked()) {
|
||||
$actions['submit']['#access'] = FALSE;
|
||||
$actions['cancel']['#access'] = FALSE;
|
||||
@@ -259,6 +258,16 @@ class ViewEditForm extends ViewFormBase {
|
||||
$displays = $view->get('display');
|
||||
foreach ($displays as $id => $display) {
|
||||
if (!empty($display['deleted'])) {
|
||||
// Remove view display from view attachment under the attachments
|
||||
// options.
|
||||
$display_handler = $executable->displayHandlers->get($id);
|
||||
if ($attachments = $display_handler->getAttachedDisplays()) {
|
||||
foreach ($attachments as $attachment ) {
|
||||
$attached_options = $executable->displayHandlers->get($attachment)->getOption('displays');
|
||||
unset($attached_options[$id]);
|
||||
$executable->displayHandlers->get($attachment)->setOption('displays', $attached_options);
|
||||
}
|
||||
}
|
||||
$executable->displayHandlers->remove($id);
|
||||
unset($displays[$id]);
|
||||
}
|
||||
@@ -266,7 +275,7 @@ class ViewEditForm extends ViewFormBase {
|
||||
|
||||
// Rename display ids if needed.
|
||||
foreach ($executable->displayHandlers as $id => $display) {
|
||||
if (!empty($display->display['new_id'])) {
|
||||
if (!empty($display->display['new_id']) && $display->display['new_id'] !== $display->display['id'] && empty($display->display['deleted'])) {
|
||||
$new_id = $display->display['new_id'];
|
||||
$display->display['id'] = $new_id;
|
||||
unset($display->display['new_id']);
|
||||
@@ -276,10 +285,13 @@ class ViewEditForm extends ViewFormBase {
|
||||
unset($displays[$id]);
|
||||
|
||||
// Redirect the user to the renamed display to be sure that the page itself exists and doesn't throw errors.
|
||||
$form_state->setRedirect('entity.view.edit_display_form', array(
|
||||
$form_state->setRedirect('entity.view.edit_display_form', [
|
||||
'view' => $view->id(),
|
||||
'display_id' => $new_id,
|
||||
));
|
||||
]);
|
||||
}
|
||||
elseif (isset($display->display['new_id'])) {
|
||||
unset($display->display['new_id']);
|
||||
}
|
||||
}
|
||||
$view->set('display', $displays);
|
||||
@@ -311,7 +323,7 @@ class ViewEditForm extends ViewFormBase {
|
||||
|
||||
$view->save();
|
||||
|
||||
drupal_set_message($this->t('The view %name has been saved.', array('%name' => $view->label())));
|
||||
drupal_set_message($this->t('The view %name has been saved.', ['%name' => $view->label()]));
|
||||
|
||||
// Remove this view from cache so we can edit it properly.
|
||||
$this->tempStore->delete($view->id());
|
||||
@@ -336,14 +348,14 @@ class ViewEditForm extends ViewFormBase {
|
||||
* Returns a renderable array representing the edit page for one display.
|
||||
*/
|
||||
public function getDisplayTab($view) {
|
||||
$build = array();
|
||||
$build = [];
|
||||
$display_id = $this->displayID;
|
||||
$display = $view->getExecutable()->displayHandlers->get($display_id);
|
||||
// If the plugin doesn't exist, display an error message instead of an edit
|
||||
// page.
|
||||
if (empty($display)) {
|
||||
// @TODO: Improved UX for the case where a plugin is missing.
|
||||
$build['#markup'] = $this->t("Error: Display @display refers to a plugin named '@plugin', but that plugin is not available.", array('@display' => $display->display['id'], '@plugin' => $display->display['display_plugin']));
|
||||
$build['#markup'] = $this->t("Error: Display @display refers to a plugin named '@plugin', but that plugin is not available.", ['@display' => $display->display['id'], '@plugin' => $display->display['display_plugin']]);
|
||||
}
|
||||
// Build the content of the edit page.
|
||||
else {
|
||||
@@ -365,10 +377,10 @@ class ViewEditForm extends ViewFormBase {
|
||||
*/
|
||||
public function getDisplayDetails($view, $display) {
|
||||
$display_title = $this->getDisplayLabel($view, $display['id'], FALSE);
|
||||
$build = array(
|
||||
'#theme_wrappers' => array('container'),
|
||||
'#attributes' => array('id' => 'edit-display-settings-details'),
|
||||
);
|
||||
$build = [
|
||||
'#theme_wrappers' => ['container'],
|
||||
'#attributes' => ['id' => 'edit-display-settings-details'],
|
||||
];
|
||||
|
||||
$is_display_deleted = !empty($display['deleted']);
|
||||
// The master display cannot be duplicated.
|
||||
@@ -377,14 +389,14 @@ class ViewEditForm extends ViewFormBase {
|
||||
$is_enabled = $view->getExecutable()->displayHandlers->get($display['id'])->isEnabled();
|
||||
|
||||
if ($display['id'] != 'default') {
|
||||
$build['top']['#theme_wrappers'] = array('container');
|
||||
$build['top']['#theme_wrappers'] = ['container'];
|
||||
$build['top']['#attributes']['id'] = 'edit-display-settings-top';
|
||||
$build['top']['#attributes']['class'] = array('views-ui-display-tab-actions', 'edit-display-settings-top', 'views-ui-display-tab-bucket', 'clearfix');
|
||||
$build['top']['#attributes']['class'] = ['views-ui-display-tab-actions', 'edit-display-settings-top', 'views-ui-display-tab-bucket', 'clearfix'];
|
||||
|
||||
// The Delete, Duplicate and Undo Delete buttons.
|
||||
$build['top']['actions'] = array(
|
||||
'#theme_wrappers' => array('dropbutton_wrapper'),
|
||||
);
|
||||
$build['top']['actions'] = [
|
||||
'#theme_wrappers' => ['dropbutton_wrapper'],
|
||||
];
|
||||
|
||||
// Because some of the 'links' are actually submit buttons, we have to
|
||||
// manually wrap each item in <li> and the whole list in <ul>.
|
||||
@@ -392,14 +404,14 @@ class ViewEditForm extends ViewFormBase {
|
||||
|
||||
if (!$is_display_deleted) {
|
||||
if (!$is_enabled) {
|
||||
$build['top']['actions']['enable'] = array(
|
||||
$build['top']['actions']['enable'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Enable @display_title', ['@display_title' => $display_title]),
|
||||
'#limit_validation_errors' => array(),
|
||||
'#submit' => array('::submitDisplayEnable', '::submitDelayDestination'),
|
||||
'#limit_validation_errors' => [],
|
||||
'#submit' => ['::submitDisplayEnable', '::submitDelayDestination'],
|
||||
'#prefix' => '<li class="enable">',
|
||||
"#suffix" => '</li>',
|
||||
);
|
||||
];
|
||||
}
|
||||
// Add a link to view the page unless the view is disabled or has no
|
||||
// path.
|
||||
@@ -414,118 +426,118 @@ class ViewEditForm extends ViewFormBase {
|
||||
else {
|
||||
$url = Url::fromUri("base:$path");
|
||||
}
|
||||
$build['top']['actions']['path'] = array(
|
||||
$build['top']['actions']['path'] = [
|
||||
'#type' => 'link',
|
||||
'#title' => $this->t('View @display_title', ['@display_title' => $display_title]),
|
||||
'#options' => array('alt' => array($this->t("Go to the real page for this display"))),
|
||||
'#options' => ['alt' => [$this->t("Go to the real page for this display")]],
|
||||
'#url' => $url,
|
||||
'#prefix' => '<li class="view">',
|
||||
"#suffix" => '</li>',
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
if (!$is_default) {
|
||||
$build['top']['actions']['duplicate'] = array(
|
||||
$build['top']['actions']['duplicate'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Duplicate @display_title', ['@display_title' => $display_title]),
|
||||
'#limit_validation_errors' => array(),
|
||||
'#submit' => array('::submitDisplayDuplicate', '::submitDelayDestination'),
|
||||
'#limit_validation_errors' => [],
|
||||
'#submit' => ['::submitDisplayDuplicate', '::submitDelayDestination'],
|
||||
'#prefix' => '<li class="duplicate">',
|
||||
"#suffix" => '</li>',
|
||||
);
|
||||
];
|
||||
}
|
||||
// Always allow a display to be deleted.
|
||||
$build['top']['actions']['delete'] = array(
|
||||
$build['top']['actions']['delete'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Delete @display_title', ['@display_title' => $display_title]),
|
||||
'#limit_validation_errors' => array(),
|
||||
'#submit' => array('::submitDisplayDelete', '::submitDelayDestination'),
|
||||
'#limit_validation_errors' => [],
|
||||
'#submit' => ['::submitDisplayDelete', '::submitDelayDestination'],
|
||||
'#prefix' => '<li class="delete">',
|
||||
"#suffix" => '</li>',
|
||||
);
|
||||
];
|
||||
|
||||
foreach (Views::fetchPluginNames('display', NULL, array($view->get('storage')->get('base_table'))) as $type => $label) {
|
||||
foreach (Views::fetchPluginNames('display', NULL, [$view->get('storage')->get('base_table')]) as $type => $label) {
|
||||
if ($type == $display['display_plugin']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$build['top']['actions']['duplicate_as'][$type] = array(
|
||||
$build['top']['actions']['duplicate_as'][$type] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Duplicate as @type', ['@type' => $label]),
|
||||
'#limit_validation_errors' => array(),
|
||||
'#submit' => array('::submitDuplicateDisplayAsType', '::submitDelayDestination'),
|
||||
'#limit_validation_errors' => [],
|
||||
'#submit' => ['::submitDuplicateDisplayAsType', '::submitDelayDestination'],
|
||||
'#prefix' => '<li class="duplicate">',
|
||||
'#suffix' => '</li>',
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
else {
|
||||
$build['top']['actions']['undo_delete'] = array(
|
||||
$build['top']['actions']['undo_delete'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Undo delete of @display_title', ['@display_title' => $display_title]),
|
||||
'#limit_validation_errors' => array(),
|
||||
'#submit' => array('::submitDisplayUndoDelete', '::submitDelayDestination'),
|
||||
'#limit_validation_errors' => [],
|
||||
'#submit' => ['::submitDisplayUndoDelete', '::submitDelayDestination'],
|
||||
'#prefix' => '<li class="undo-delete">',
|
||||
"#suffix" => '</li>',
|
||||
);
|
||||
];
|
||||
}
|
||||
if ($is_enabled) {
|
||||
$build['top']['actions']['disable'] = array(
|
||||
$build['top']['actions']['disable'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Disable @display_title', ['@display_title' => $display_title]),
|
||||
'#limit_validation_errors' => array(),
|
||||
'#submit' => array('::submitDisplayDisable', '::submitDelayDestination'),
|
||||
'#limit_validation_errors' => [],
|
||||
'#submit' => ['::submitDisplayDisable', '::submitDelayDestination'],
|
||||
'#prefix' => '<li class="disable">',
|
||||
"#suffix" => '</li>',
|
||||
);
|
||||
];
|
||||
}
|
||||
$build['top']['actions']['suffix']['#markup'] = '</ul>';
|
||||
|
||||
// The area above the three columns.
|
||||
$build['top']['display_title'] = array(
|
||||
$build['top']['display_title'] = [
|
||||
'#theme' => 'views_ui_display_tab_setting',
|
||||
'#description' => $this->t('Display name'),
|
||||
'#link' => $view->getExecutable()->displayHandlers->get($display['id'])->optionLink($display_title, 'display_title'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$build['columns'] = array();
|
||||
$build['columns']['#theme_wrappers'] = array('container');
|
||||
$build['columns']['#attributes'] = array('id' => 'edit-display-settings-main', 'class' => array('clearfix', 'views-display-columns'));
|
||||
$build['columns'] = [];
|
||||
$build['columns']['#theme_wrappers'] = ['container'];
|
||||
$build['columns']['#attributes'] = ['id' => 'edit-display-settings-main', 'class' => ['clearfix', 'views-display-columns']];
|
||||
|
||||
$build['columns']['first']['#theme_wrappers'] = array('container');
|
||||
$build['columns']['first']['#attributes'] = array('class' => array('views-display-column', 'first'));
|
||||
$build['columns']['first']['#theme_wrappers'] = ['container'];
|
||||
$build['columns']['first']['#attributes'] = ['class' => ['views-display-column', 'first']];
|
||||
|
||||
$build['columns']['second']['#theme_wrappers'] = array('container');
|
||||
$build['columns']['second']['#attributes'] = array('class' => array('views-display-column', 'second'));
|
||||
$build['columns']['second']['#theme_wrappers'] = ['container'];
|
||||
$build['columns']['second']['#attributes'] = ['class' => ['views-display-column', 'second']];
|
||||
|
||||
$build['columns']['second']['settings'] = array();
|
||||
$build['columns']['second']['header'] = array();
|
||||
$build['columns']['second']['footer'] = array();
|
||||
$build['columns']['second']['empty'] = array();
|
||||
$build['columns']['second']['pager'] = array();
|
||||
$build['columns']['second']['settings'] = [];
|
||||
$build['columns']['second']['header'] = [];
|
||||
$build['columns']['second']['footer'] = [];
|
||||
$build['columns']['second']['empty'] = [];
|
||||
$build['columns']['second']['pager'] = [];
|
||||
|
||||
// The third column buckets are wrapped in details.
|
||||
$build['columns']['third'] = array(
|
||||
$build['columns']['third'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Advanced'),
|
||||
'#theme_wrappers' => array('details'),
|
||||
'#attributes' => array(
|
||||
'class' => array(
|
||||
'#theme_wrappers' => ['details'],
|
||||
'#attributes' => [
|
||||
'class' => [
|
||||
'views-display-column',
|
||||
'third',
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
// Collapse the details by default.
|
||||
$build['columns']['third']['#open'] = \Drupal::config('views.settings')->get('ui.show.advanced_column');
|
||||
|
||||
// Each option (e.g. title, access, display as grid/table/list) fits into one
|
||||
// of several "buckets," or boxes (Format, Fields, Sort, and so on).
|
||||
$buckets = array();
|
||||
$buckets = [];
|
||||
|
||||
// Fetch options from the display plugin, with a list of buckets they go into.
|
||||
$options = array();
|
||||
$options = [];
|
||||
$view->getExecutable()->displayHandlers->get($display['id'])->optionsSummary($buckets, $options);
|
||||
|
||||
// Place each option into its bucket.
|
||||
@@ -580,10 +592,10 @@ class ViewEditForm extends ViewFormBase {
|
||||
$view->cacheSet();
|
||||
|
||||
// Redirect to the top-level edit page.
|
||||
$form_state->setRedirect('entity.view.edit_display_form', array(
|
||||
$form_state->setRedirect('entity.view.edit_display_form', [
|
||||
'view' => $view->id(),
|
||||
'display_id' => $id,
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -599,10 +611,10 @@ class ViewEditForm extends ViewFormBase {
|
||||
$view->cacheSet();
|
||||
|
||||
// Redirect to the top-level edit page.
|
||||
$form_state->setRedirect('entity.view.edit_display_form', array(
|
||||
$form_state->setRedirect('entity.view.edit_display_form', [
|
||||
'view' => $view->id(),
|
||||
'display_id' => $id,
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -617,10 +629,10 @@ class ViewEditForm extends ViewFormBase {
|
||||
$view->cacheSet();
|
||||
|
||||
// Redirect to the top-level edit page.
|
||||
$form_state->setRedirect('entity.view.edit_display_form', array(
|
||||
$form_state->setRedirect('entity.view.edit_display_form', [
|
||||
'view' => $view->id(),
|
||||
'display_id' => $id,
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -672,43 +684,43 @@ class ViewEditForm extends ViewFormBase {
|
||||
public function renderDisplayTop(ViewUI $view) {
|
||||
$display_id = $this->displayID;
|
||||
$element['#theme_wrappers'][] = 'views_ui_container';
|
||||
$element['#attributes']['class'] = array('views-display-top', 'clearfix');
|
||||
$element['#attributes']['id'] = array('views-display-top');
|
||||
$element['#attributes']['class'] = ['views-display-top', 'clearfix'];
|
||||
$element['#attributes']['id'] = ['views-display-top'];
|
||||
|
||||
// Extra actions for the display
|
||||
$element['extra_actions'] = array(
|
||||
$element['extra_actions'] = [
|
||||
'#type' => 'dropbutton',
|
||||
'#attributes' => array(
|
||||
'#attributes' => [
|
||||
'id' => 'views-display-extra-actions',
|
||||
),
|
||||
'#links' => array(
|
||||
'edit-details' => array(
|
||||
],
|
||||
'#links' => [
|
||||
'edit-details' => [
|
||||
'title' => $this->t('Edit view name/description'),
|
||||
'url' => Url::fromRoute('views_ui.form_edit_details', ['js' => 'nojs', 'view' => $view->id(), 'display_id' => $display_id]),
|
||||
'attributes' => array('class' => array('views-ajax-link')),
|
||||
),
|
||||
'analyze' => array(
|
||||
'attributes' => ['class' => ['views-ajax-link']],
|
||||
],
|
||||
'analyze' => [
|
||||
'title' => $this->t('Analyze view'),
|
||||
'url' => Url::fromRoute('views_ui.form_analyze', ['js' => 'nojs', 'view' => $view->id(), 'display_id' => $display_id]),
|
||||
'attributes' => array('class' => array('views-ajax-link')),
|
||||
),
|
||||
'duplicate' => array(
|
||||
'attributes' => ['class' => ['views-ajax-link']],
|
||||
],
|
||||
'duplicate' => [
|
||||
'title' => $this->t('Duplicate view'),
|
||||
'url' => $view->urlInfo('duplicate-form'),
|
||||
),
|
||||
'reorder' => array(
|
||||
],
|
||||
'reorder' => [
|
||||
'title' => $this->t('Reorder displays'),
|
||||
'url' => Url::fromRoute('views_ui.form_reorder_displays', ['js' => 'nojs', 'view' => $view->id(), 'display_id' => $display_id]),
|
||||
'attributes' => array('class' => array('views-ajax-link')),
|
||||
),
|
||||
),
|
||||
);
|
||||
'attributes' => ['class' => ['views-ajax-link']],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
if ($view->access('delete')) {
|
||||
$element['extra_actions']['#links']['delete'] = array(
|
||||
$element['extra_actions']['#links']['delete'] = [
|
||||
'title' => $this->t('Delete view'),
|
||||
'url' => $view->urlInfo('delete-form'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// Let other modules add additional links here.
|
||||
@@ -716,17 +728,17 @@ class ViewEditForm extends ViewFormBase {
|
||||
|
||||
if (isset($view->type) && $view->type != $this->t('Default')) {
|
||||
if ($view->type == $this->t('Overridden')) {
|
||||
$element['extra_actions']['#links']['revert'] = array(
|
||||
$element['extra_actions']['#links']['revert'] = [
|
||||
'title' => $this->t('Revert view'),
|
||||
'href' => "admin/structure/views/view/{$view->id()}/revert",
|
||||
'query' => array('destination' => $view->url('edit-form')),
|
||||
);
|
||||
'query' => ['destination' => $view->url('edit-form')],
|
||||
];
|
||||
}
|
||||
else {
|
||||
$element['extra_actions']['#links']['delete'] = array(
|
||||
$element['extra_actions']['#links']['delete'] = [
|
||||
'title' => $this->t('Delete view'),
|
||||
'url' => $view->urlInfo('delete-form'),
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -741,18 +753,18 @@ class ViewEditForm extends ViewFormBase {
|
||||
}
|
||||
|
||||
// Buttons for adding a new display.
|
||||
foreach (Views::fetchPluginNames('display', NULL, array($view->get('base_table'))) as $type => $label) {
|
||||
$element['add_display'][$type] = array(
|
||||
foreach (Views::fetchPluginNames('display', NULL, [$view->get('base_table')]) as $type => $label) {
|
||||
$element['add_display'][$type] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Add @display', array('@display' => $label)),
|
||||
'#limit_validation_errors' => array(),
|
||||
'#submit' => array('::submitDisplayAdd', '::submitDelayDestination'),
|
||||
'#attributes' => array('class' => array('add-display')),
|
||||
'#value' => $this->t('Add @display', ['@display' => $label]),
|
||||
'#limit_validation_errors' => [],
|
||||
'#submit' => ['::submitDisplayAdd', '::submitDelayDestination'],
|
||||
'#attributes' => ['class' => ['add-display']],
|
||||
// Allow JavaScript to remove the 'Add ' prefix from the button label when
|
||||
// placing the button in a "Add" dropdown menu.
|
||||
'#process' => array_merge(array('views_ui_form_button_was_clicked'), $this->elementInfo->getInfoProperty('submit', '#process', array())),
|
||||
'#values' => array($this->t('Add @display', array('@display' => $label)), $label),
|
||||
);
|
||||
'#process' => array_merge(['views_ui_form_button_was_clicked'], $this->elementInfo->getInfoProperty('submit', '#process', [])),
|
||||
'#values' => [$this->t('Add @display', ['@display' => $label]), $label],
|
||||
];
|
||||
}
|
||||
|
||||
return $element;
|
||||
@@ -815,10 +827,10 @@ class ViewEditForm extends ViewFormBase {
|
||||
$view->cacheSet();
|
||||
|
||||
// Redirect to the new display's edit page.
|
||||
$form_state->setRedirect('entity.view.edit_display_form', array(
|
||||
$form_state->setRedirect('entity.view.edit_display_form', [
|
||||
'view' => $view->id(),
|
||||
'display_id' => $new_display_id,
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -837,10 +849,10 @@ class ViewEditForm extends ViewFormBase {
|
||||
$view->cacheSet();
|
||||
|
||||
// Redirect to the new display's edit page.
|
||||
$form_state->setRedirect('entity.view.edit_display_form', array(
|
||||
$form_state->setRedirect('entity.view.edit_display_form', [
|
||||
'view' => $view->id(),
|
||||
'display_id' => $display_id,
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -863,10 +875,10 @@ class ViewEditForm extends ViewFormBase {
|
||||
$view->cacheSet();
|
||||
|
||||
// Redirect to the new display's edit page.
|
||||
$form_state->setRedirect('entity.view.edit_display_form', array(
|
||||
$form_state->setRedirect('entity.view.edit_display_form', [
|
||||
'view' => $view->id(),
|
||||
'display_id' => $new_display_id,
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -876,14 +888,14 @@ class ViewEditForm extends ViewFormBase {
|
||||
* object emerges out of refactoring.
|
||||
*/
|
||||
public function buildOptionForm(ViewUI $view, $id, $option, $display) {
|
||||
$option_build = array();
|
||||
$option_build = [];
|
||||
$option_build['#theme'] = 'views_ui_display_tab_setting';
|
||||
|
||||
$option_build['#description'] = $option['title'];
|
||||
|
||||
$option_build['#link'] = $view->getExecutable()->displayHandlers->get($display['id'])->optionLink($option['value'], $id, '', empty($option['desc']) ? '' : $option['desc']);
|
||||
|
||||
$option_build['#links'] = array();
|
||||
$option_build['#links'] = [];
|
||||
if (!empty($option['links']) && is_array($option['links'])) {
|
||||
foreach ($option['links'] as $link_id => $link_value) {
|
||||
$option_build['#settings_links'][] = $view->getExecutable()->displayHandlers->get($display['id'])->optionLink($option['setting'], $link_id, 'views-button-configure', $link_value);
|
||||
@@ -916,9 +928,9 @@ class ViewEditForm extends ViewFormBase {
|
||||
|
||||
$types = $executable->getHandlerTypes();
|
||||
|
||||
$build = array(
|
||||
'#theme_wrappers' => array('views_ui_display_tab_bucket'),
|
||||
);
|
||||
$build = [
|
||||
'#theme_wrappers' => ['views_ui_display_tab_bucket'],
|
||||
];
|
||||
|
||||
$build['#overridden'] = FALSE;
|
||||
$build['#defaulted'] = FALSE;
|
||||
@@ -944,11 +956,11 @@ class ViewEditForm extends ViewFormBase {
|
||||
$style_plugin = $executable->style_plugin;
|
||||
$uses_fields = $style_plugin && $style_plugin->usesFields();
|
||||
if (!$uses_fields) {
|
||||
$build['fields'][] = array(
|
||||
$build['fields'][] = [
|
||||
'#markup' => $this->t('The selected style or row format does not use fields.'),
|
||||
'#theme_wrappers' => array('views_ui_container'),
|
||||
'#attributes' => array('class' => array('views-display-setting')),
|
||||
);
|
||||
'#theme_wrappers' => ['views_ui_container'],
|
||||
'#attributes' => ['class' => ['views-display-setting']],
|
||||
];
|
||||
return $build;
|
||||
}
|
||||
break;
|
||||
@@ -956,47 +968,47 @@ class ViewEditForm extends ViewFormBase {
|
||||
case 'footer':
|
||||
case 'empty':
|
||||
if (!$executable->display_handler->usesAreas()) {
|
||||
$build[$type][] = array(
|
||||
'#markup' => $this->t('The selected display type does not use @type plugins', array('@type' => $type)),
|
||||
'#theme_wrappers' => array('views_ui_container'),
|
||||
'#attributes' => array('class' => array('views-display-setting')),
|
||||
);
|
||||
$build[$type][] = [
|
||||
'#markup' => $this->t('The selected display type does not use @type plugins', ['@type' => $type]),
|
||||
'#theme_wrappers' => ['views_ui_container'],
|
||||
'#attributes' => ['class' => ['views-display-setting']],
|
||||
];
|
||||
return $build;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Create an array of actions to pass to links template.
|
||||
$actions = array();
|
||||
$actions = [];
|
||||
$count_handlers = count($executable->display_handler->getHandlers($type));
|
||||
|
||||
// Create the add text variable for the add action.
|
||||
$add_text = $this->t('Add <span class="visually-hidden">@type</span>', array('@type' => $types[$type]['ltitle']));
|
||||
$add_text = $this->t('Add <span class="visually-hidden">@type</span>', ['@type' => $types[$type]['ltitle']]);
|
||||
|
||||
$actions['add'] = array(
|
||||
$actions['add'] = [
|
||||
'title' => $add_text,
|
||||
'url' => Url::fromRoute('views_ui.form_add_handler', ['js' => 'nojs', 'view' => $view->id(), 'display_id' => $display['id'], 'type' => $type]),
|
||||
'attributes' => array('class' => array('icon compact add', 'views-ajax-link'), 'id' => 'views-add-' . $type),
|
||||
);
|
||||
'attributes' => ['class' => ['icon compact add', 'views-ajax-link'], 'id' => 'views-add-' . $type],
|
||||
];
|
||||
if ($count_handlers > 0) {
|
||||
// Create the rearrange text variable for the rearrange action.
|
||||
$rearrange_text = $type == 'filter' ? $this->t('And/Or Rearrange <span class="visually-hidden">filter criteria</span>') : $this->t('Rearrange <span class="visually-hidden">@type</span>', array('@type' => $types[$type]['ltitle']));
|
||||
$rearrange_text = $type == 'filter' ? $this->t('And/Or Rearrange <span class="visually-hidden">filter criteria</span>') : $this->t('Rearrange <span class="visually-hidden">@type</span>', ['@type' => $types[$type]['ltitle']]);
|
||||
|
||||
$actions['rearrange'] = array(
|
||||
$actions['rearrange'] = [
|
||||
'title' => $rearrange_text,
|
||||
'url' => $rearrange_url,
|
||||
'attributes' => array('class' => array($class, 'views-ajax-link'), 'id' => 'views-rearrange-' . $type),
|
||||
);
|
||||
'attributes' => ['class' => [$class, 'views-ajax-link'], 'id' => 'views-rearrange-' . $type],
|
||||
];
|
||||
}
|
||||
|
||||
// Render the array of links
|
||||
$build['#actions'] = array(
|
||||
$build['#actions'] = [
|
||||
'#type' => 'dropbutton',
|
||||
'#links' => $actions,
|
||||
'#attributes' => array(
|
||||
'class' => array('views-ui-settings-bucket-operations'),
|
||||
),
|
||||
);
|
||||
'#attributes' => [
|
||||
'class' => ['views-ui-settings-bucket-operations'],
|
||||
],
|
||||
];
|
||||
|
||||
if (!$executable->display_handler->isDefaultDisplay()) {
|
||||
if (!$executable->display_handler->isDefaulted($types[$type]['plural'])) {
|
||||
@@ -1010,14 +1022,14 @@ class ViewEditForm extends ViewFormBase {
|
||||
static $relationships = NULL;
|
||||
if (!isset($relationships)) {
|
||||
// Get relationship labels.
|
||||
$relationships = array();
|
||||
$relationships = [];
|
||||
foreach ($executable->display_handler->getHandlers('relationship') as $id => $handler) {
|
||||
$relationships[$id] = $handler->adminLabel();
|
||||
}
|
||||
}
|
||||
|
||||
// Filters can now be grouped so we do a little bit extra:
|
||||
$groups = array();
|
||||
$groups = [];
|
||||
$grouping = FALSE;
|
||||
if ($type == 'filter') {
|
||||
$group_info = $executable->display_handler->getOption('filter_groups');
|
||||
@@ -1026,28 +1038,28 @@ class ViewEditForm extends ViewFormBase {
|
||||
// "OR" label next to items within the group.
|
||||
if (!empty($group_info['groups']) && (count($group_info['groups']) > 1 || current($group_info['groups']) == 'OR')) {
|
||||
$grouping = TRUE;
|
||||
$groups = array(0 => array());
|
||||
$groups = [0 => []];
|
||||
}
|
||||
}
|
||||
|
||||
$build['fields'] = array();
|
||||
$build['fields'] = [];
|
||||
|
||||
foreach ($executable->display_handler->getOption($types[$type]['plural']) as $id => $field) {
|
||||
// Build the option link for this handler ("Node: ID = article").
|
||||
$build['fields'][$id] = array();
|
||||
$build['fields'][$id] = [];
|
||||
$build['fields'][$id]['#theme'] = 'views_ui_display_tab_setting';
|
||||
|
||||
$handler = $executable->display_handler->getHandler($type, $id);
|
||||
if ($handler->broken()) {
|
||||
$build['fields'][$id]['#class'][] = 'broken';
|
||||
$field_name = $handler->adminLabel();
|
||||
$build['fields'][$id]['#link'] = $this->l($field_name, new Url('views_ui.form_handler', array(
|
||||
$build['fields'][$id]['#link'] = $this->l($field_name, new Url('views_ui.form_handler', [
|
||||
'js' => 'nojs',
|
||||
'view' => $view->id(),
|
||||
'display_id' => $display['id'],
|
||||
'type' => $type,
|
||||
'id' => $id,
|
||||
), array('attributes' => array('class' => array('views-ajax-link')))));
|
||||
], ['attributes' => ['class' => ['views-ajax-link']]]));
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1056,41 +1068,41 @@ class ViewEditForm extends ViewFormBase {
|
||||
$field_name = '(' . $relationships[$field['relationship']] . ') ' . $field_name;
|
||||
}
|
||||
|
||||
$description = Xss::filterAdmin($handler->adminSummary());
|
||||
$description = $handler->adminSummary();
|
||||
$link_text = $field_name . (empty($description) ? '' : " ($description)");
|
||||
$link_attributes = array('class' => array('views-ajax-link'));
|
||||
$link_attributes = ['class' => ['views-ajax-link']];
|
||||
if (!empty($field['exclude'])) {
|
||||
$link_attributes['class'][] = 'views-field-excluded';
|
||||
// Add a [hidden] marker, if the field is excluded.
|
||||
$link_text .= ' [' . $this->t('hidden') . ']';
|
||||
}
|
||||
$build['fields'][$id]['#link'] = $this->l($link_text, new Url('views_ui.form_handler', array(
|
||||
$build['fields'][$id]['#link'] = $this->l($link_text, new Url('views_ui.form_handler', [
|
||||
'js' => 'nojs',
|
||||
'view' => $view->id(),
|
||||
'display_id' => $display['id'],
|
||||
'type' => $type,
|
||||
'id' => $id,
|
||||
), array('attributes' => $link_attributes)));
|
||||
], ['attributes' => $link_attributes]));
|
||||
$build['fields'][$id]['#class'][] = Html::cleanCssIdentifier($display['id'] . '-' . $type . '-' . $id);
|
||||
|
||||
if ($executable->display_handler->useGroupBy() && $handler->usesGroupBy()) {
|
||||
$build['fields'][$id]['#settings_links'][] = $this->l(SafeMarkup::format('<span class="label">@text</span>', array('@text' => $this->t('Aggregation settings'))), new Url('views_ui.form_handler_group', array(
|
||||
$build['fields'][$id]['#settings_links'][] = $this->l(SafeMarkup::format('<span class="label">@text</span>', ['@text' => $this->t('Aggregation settings')]), new Url('views_ui.form_handler_group', [
|
||||
'js' => 'nojs',
|
||||
'view' => $view->id(),
|
||||
'display_id' => $display['id'],
|
||||
'type' => $type,
|
||||
'id' => $id,
|
||||
), array('attributes' => array('class' => array('views-button-configure', 'views-ajax-link'), 'title' => $this->t('Aggregation settings')))));
|
||||
], ['attributes' => ['class' => ['views-button-configure', 'views-ajax-link'], 'title' => $this->t('Aggregation settings')]]));
|
||||
}
|
||||
|
||||
if ($handler->hasExtraOptions()) {
|
||||
$build['fields'][$id]['#settings_links'][] = $this->l(SafeMarkup::format('<span class="label">@text</span>', array('@text' => $this->t('Settings'))), new Url('views_ui.form_handler_extra', array(
|
||||
$build['fields'][$id]['#settings_links'][] = $this->l(SafeMarkup::format('<span class="label">@text</span>', ['@text' => $this->t('Settings')]), new Url('views_ui.form_handler_extra', [
|
||||
'js' => 'nojs',
|
||||
'view' => $view->id(),
|
||||
'display_id' => $display['id'],
|
||||
'type' => $type,
|
||||
'id' => $id,
|
||||
), array('attributes' => array('class' => array('views-button-configure', 'views-ajax-link'), 'title' => $this->t('Settings')))));
|
||||
], ['attributes' => ['class' => ['views-button-configure', 'views-ajax-link'], 'title' => $this->t('Settings')]]));
|
||||
}
|
||||
|
||||
if ($grouping) {
|
||||
@@ -1107,15 +1119,15 @@ class ViewEditForm extends ViewFormBase {
|
||||
// If using grouping, re-order fields so that they show up properly in the list.
|
||||
if ($type == 'filter' && $grouping) {
|
||||
$store = $build['fields'];
|
||||
$build['fields'] = array();
|
||||
$build['fields'] = [];
|
||||
foreach ($groups as $gid => $contents) {
|
||||
// Display an operator between each group.
|
||||
if (!empty($build['fields'])) {
|
||||
$build['fields'][] = array(
|
||||
$build['fields'][] = [
|
||||
'#theme' => 'views_ui_display_tab_setting',
|
||||
'#class' => array('views-group-text'),
|
||||
'#class' => ['views-group-text'],
|
||||
'#link' => ($group_info['operator'] == 'OR' ? $this->t('OR') : $this->t('AND')),
|
||||
);
|
||||
];
|
||||
}
|
||||
// Display an operator between each pair of filters within the group.
|
||||
$keys = array_keys($contents);
|
||||
|
||||
@@ -88,7 +88,7 @@ abstract class ViewFormBase extends EntityForm {
|
||||
$executable = $view->getExecutable();
|
||||
$executable->initDisplay();
|
||||
$display_id = $this->displayID;
|
||||
$tabs = array();
|
||||
$tabs = [];
|
||||
|
||||
// Create a tab for each display.
|
||||
foreach ($view->get('display') as $id => $display) {
|
||||
@@ -99,15 +99,15 @@ abstract class ViewFormBase extends EntityForm {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tabs[$id] = array(
|
||||
$tabs[$id] = [
|
||||
'#theme' => 'menu_local_task',
|
||||
'#weight' => $display['position'],
|
||||
'#link' => array(
|
||||
'#link' => [
|
||||
'title' => $this->getDisplayLabel($view, $id),
|
||||
'localized_options' => array(),
|
||||
'localized_options' => [],
|
||||
'url' => $view->urlInfo('edit-display-form')->setRouteParameter('display_id', $id),
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
if (!empty($display['deleted'])) {
|
||||
$tabs[$id]['#link']['localized_options']['attributes']['class'][] = 'views-display-deleted-link';
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class ViewListBuilder extends ConfigEntityListBuilder {
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
||||
* The entity type definition.
|
||||
* @param \Drupal\Core\Entity\EntityStorageInterface $storage.
|
||||
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
|
||||
* The entity storage class.
|
||||
* @param \Drupal\Component\Plugin\PluginManagerInterface $display_manager
|
||||
* The views display plugin manager to use.
|
||||
@@ -65,10 +65,10 @@ class ViewListBuilder extends ConfigEntityListBuilder {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load() {
|
||||
$entities = array(
|
||||
'enabled' => array(),
|
||||
'disabled' => array(),
|
||||
);
|
||||
$entities = [
|
||||
'enabled' => [],
|
||||
'disabled' => [],
|
||||
];
|
||||
foreach (parent::load() as $entity) {
|
||||
if ($entity->status()) {
|
||||
$entities['enabled'][] = $entity;
|
||||
@@ -85,67 +85,73 @@ class ViewListBuilder extends ConfigEntityListBuilder {
|
||||
*/
|
||||
public function buildRow(EntityInterface $view) {
|
||||
$row = parent::buildRow($view);
|
||||
return array(
|
||||
'data' => array(
|
||||
'view_name' => array(
|
||||
'data' => array(
|
||||
'#theme' => 'views_ui_view_info',
|
||||
'#view' => $view,
|
||||
'#displays' => $this->getDisplaysList($view)
|
||||
),
|
||||
),
|
||||
'description' => array(
|
||||
'data' => array(
|
||||
return [
|
||||
'data' => [
|
||||
'view_name' => [
|
||||
'data' => [
|
||||
'#plain_text' => $view->label(),
|
||||
],
|
||||
],
|
||||
'machine_name' => [
|
||||
'data' => [
|
||||
'#plain_text' => $view->id(),
|
||||
],
|
||||
],
|
||||
'description' => [
|
||||
'data' => [
|
||||
'#plain_text' => $view->get('description'),
|
||||
),
|
||||
'data-drupal-selector' => 'views-table-filter-text-source',
|
||||
),
|
||||
'tag' => array(
|
||||
'data' => array(
|
||||
'#plain_text' => $view->get('tag'),
|
||||
),
|
||||
'data-drupal-selector' => 'views-table-filter-text-source',
|
||||
),
|
||||
'path' => array(
|
||||
'data' => array(
|
||||
'#theme' => 'item_list',
|
||||
'#items' => $this->getDisplayPaths($view),
|
||||
'#context' => ['list_style' => 'comma-list'],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
'displays' => [
|
||||
'data' => [
|
||||
'#theme' => 'views_ui_view_displays_list',
|
||||
'#displays' => $this->getDisplaysList($view),
|
||||
],
|
||||
],
|
||||
'operations' => $row['operations'],
|
||||
),
|
||||
'title' => $this->t('Machine name: @name', array('@name' => $view->id())),
|
||||
'class' => array($view->status() ? 'views-ui-list-enabled' : 'views-ui-list-disabled'),
|
||||
);
|
||||
],
|
||||
'#attributes' => [
|
||||
'class' => [$view->status() ? 'views-ui-list-enabled' : 'views-ui-list-disabled'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildHeader() {
|
||||
return array(
|
||||
'view_name' => array(
|
||||
return [
|
||||
'view_name' => [
|
||||
'data' => $this->t('View name'),
|
||||
'class' => array('views-ui-name'),
|
||||
),
|
||||
'description' => array(
|
||||
'#attributes' => [
|
||||
'class' => ['views-ui-name'],
|
||||
],
|
||||
],
|
||||
'machine_name' => [
|
||||
'data' => $this->t('Machine name'),
|
||||
'#attributes' => [
|
||||
'class' => ['views-ui-machine-name'],
|
||||
],
|
||||
],
|
||||
'description' => [
|
||||
'data' => $this->t('Description'),
|
||||
'class' => array('views-ui-description'),
|
||||
),
|
||||
'tag' => array(
|
||||
'data' => $this->t('Tag'),
|
||||
'class' => array('views-ui-tag'),
|
||||
),
|
||||
'path' => array(
|
||||
'data' => $this->t('Path'),
|
||||
'class' => array('views-ui-path'),
|
||||
),
|
||||
'operations' => array(
|
||||
'#attributes' => [
|
||||
'class' => ['views-ui-description'],
|
||||
],
|
||||
],
|
||||
'displays' => [
|
||||
'data' => $this->t('Displays'),
|
||||
'#attributes' => [
|
||||
'class' => ['views-ui-displays'],
|
||||
],
|
||||
],
|
||||
'operations' => [
|
||||
'data' => $this->t('Operations'),
|
||||
'class' => array('views-ui-operations'),
|
||||
),
|
||||
);
|
||||
'#attributes' => [
|
||||
'class' => ['views-ui-operations'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,15 +161,15 @@ class ViewListBuilder extends ConfigEntityListBuilder {
|
||||
$operations = parent::getDefaultOperations($entity);
|
||||
|
||||
if ($entity->hasLinkTemplate('duplicate-form')) {
|
||||
$operations['duplicate'] = array(
|
||||
$operations['duplicate'] = [
|
||||
'title' => $this->t('Duplicate'),
|
||||
'weight' => 15,
|
||||
'url' => $entity->urlInfo('duplicate-form'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// Add AJAX functionality to enable/disable operations.
|
||||
foreach (array('enable', 'disable') as $op) {
|
||||
foreach (['enable', 'disable'] as $op) {
|
||||
if (isset($operations[$op])) {
|
||||
$operations[$op]['url'] = $entity->urlInfo($op);
|
||||
// Enable and disable operations should use AJAX.
|
||||
@@ -185,40 +191,37 @@ class ViewListBuilder extends ConfigEntityListBuilder {
|
||||
$list['#attached']['library'][] = 'core/drupal.ajax';
|
||||
$list['#attached']['library'][] = 'views_ui/views_ui.listing';
|
||||
|
||||
$form['filters'] = array(
|
||||
$form['filters'] = [
|
||||
'#type' => 'container',
|
||||
'#attributes' => array(
|
||||
'class' => array('table-filter', 'js-show'),
|
||||
),
|
||||
);
|
||||
'#attributes' => [
|
||||
'class' => ['table-filter', 'js-show'],
|
||||
],
|
||||
];
|
||||
|
||||
$list['filters']['text'] = array(
|
||||
$list['filters']['text'] = [
|
||||
'#type' => 'search',
|
||||
'#title' => $this->t('Filter'),
|
||||
'#title_display' => 'invisible',
|
||||
'#size' => 40,
|
||||
'#placeholder' => $this->t('Filter by view name or description'),
|
||||
'#attributes' => array(
|
||||
'class' => array('views-filter-text'),
|
||||
'#size' => 60,
|
||||
'#placeholder' => $this->t('Filter by view name, machine name, description, or display path'),
|
||||
'#attributes' => [
|
||||
'class' => ['views-filter-text'],
|
||||
'data-table' => '.views-listing-table',
|
||||
'autocomplete' => 'off',
|
||||
'title' => $this->t('Enter a part of the view name or description to filter by.'),
|
||||
),
|
||||
);
|
||||
'title' => $this->t('Enter a part of the view name, machine name, description, or display path to filter by.'),
|
||||
],
|
||||
];
|
||||
|
||||
$list['enabled']['heading']['#markup'] = '<h2>' . $this->t('Enabled', array(), array('context' => 'Plural')) . '</h2>';
|
||||
$list['disabled']['heading']['#markup'] = '<h2>' . $this->t('Disabled', array(), array('context' => 'Plural')) . '</h2>';
|
||||
foreach (array('enabled', 'disabled') as $status) {
|
||||
$list['enabled']['heading']['#markup'] = '<h2>' . $this->t('Enabled', [], ['context' => 'Plural']) . '</h2>';
|
||||
$list['disabled']['heading']['#markup'] = '<h2>' . $this->t('Disabled', [], ['context' => 'Plural']) . '</h2>';
|
||||
foreach (['enabled', 'disabled'] as $status) {
|
||||
$list[$status]['#type'] = 'container';
|
||||
$list[$status]['#attributes'] = array('class' => array('views-list-section', $status));
|
||||
$list[$status]['table'] = array(
|
||||
'#type' => 'table',
|
||||
'#attributes' => array(
|
||||
'class' => array('views-listing-table'),
|
||||
),
|
||||
'#header' => $this->buildHeader(),
|
||||
'#rows' => array(),
|
||||
);
|
||||
$list[$status]['#attributes'] = ['class' => ['views-list-section', $status]];
|
||||
$list[$status]['table'] = [
|
||||
'#theme' => 'views_ui_views_listing_table',
|
||||
'#headers' => $this->buildHeader(),
|
||||
'#attributes' => ['class' => ['views-listing-table', $status]],
|
||||
];
|
||||
foreach ($entities[$status] as $entity) {
|
||||
$list[$status]['table']['#rows'][$entity->id()] = $this->buildRow($entity);
|
||||
}
|
||||
@@ -241,13 +244,29 @@ class ViewListBuilder extends ConfigEntityListBuilder {
|
||||
* An array of display types that this view includes.
|
||||
*/
|
||||
protected function getDisplaysList(EntityInterface $view) {
|
||||
$displays = array();
|
||||
foreach ($view->get('display') as $display) {
|
||||
$definition = $this->displayManager->getDefinition($display['display_plugin']);
|
||||
$displays = [];
|
||||
|
||||
$executable = $view->getExecutable();
|
||||
$executable->initDisplay();
|
||||
foreach ($executable->displayHandlers as $display) {
|
||||
$rendered_path = FALSE;
|
||||
$definition = $display->getPluginDefinition();
|
||||
if (!empty($definition['admin'])) {
|
||||
// Cast the admin label to a string since it is an object.
|
||||
// @see \Drupal\Core\StringTranslation\TranslatableMarkup
|
||||
$displays[] = (string) $definition['admin'];
|
||||
if ($display->hasPath()) {
|
||||
$path = $display->getPath();
|
||||
if ($view->status() && strpos($path, '%') === FALSE) {
|
||||
// @todo Views should expect and store a leading /. See:
|
||||
// https://www.drupal.org/node/2423913
|
||||
$rendered_path = \Drupal::l('/' . $path, Url::fromUserInput('/' . $path));
|
||||
}
|
||||
else {
|
||||
$rendered_path = '/' . $path;
|
||||
}
|
||||
}
|
||||
$displays[] = [
|
||||
'display' => $definition['admin'],
|
||||
'path' => $rendered_path,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,33 +274,4 @@ class ViewListBuilder extends ConfigEntityListBuilder {
|
||||
return $displays;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of paths assigned to the view.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityInterface $view
|
||||
* The view entity.
|
||||
*
|
||||
* @return array
|
||||
* An array of paths for this view.
|
||||
*/
|
||||
protected function getDisplayPaths(EntityInterface $view) {
|
||||
$all_paths = array();
|
||||
$executable = $view->getExecutable();
|
||||
$executable->initDisplay();
|
||||
foreach ($executable->displayHandlers as $display) {
|
||||
if ($display->hasPath()) {
|
||||
$path = $display->getPath();
|
||||
if ($view->status() && strpos($path, '%') === FALSE) {
|
||||
// @todo Views should expect and store a leading /. See:
|
||||
// https://www.drupal.org/node/2423913
|
||||
$all_paths[] = \Drupal::l('/' . $path, Url::fromUserInput('/' . $path));
|
||||
}
|
||||
else {
|
||||
$all_paths[] = '/' . $path;
|
||||
}
|
||||
}
|
||||
}
|
||||
return array_unique($all_paths);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,43 +22,43 @@ class ViewPreviewForm extends ViewFormBase {
|
||||
|
||||
$form_state->disableCache();
|
||||
|
||||
$form['controls']['#attributes'] = array('class' => array('clearfix'));
|
||||
$form['controls']['#attributes'] = ['class' => ['clearfix']];
|
||||
|
||||
$form['controls']['title'] = array(
|
||||
$form['controls']['title'] = [
|
||||
'#prefix' => '<h2 class="view-preview-form__title">',
|
||||
'#markup' => $this->t('Preview'),
|
||||
'#suffix' => '</h2>',
|
||||
);
|
||||
];
|
||||
|
||||
// Add a checkbox controlling whether or not this display auto-previews.
|
||||
$form['controls']['live_preview'] = array(
|
||||
$form['controls']['live_preview'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#id' => 'edit-displays-live-preview',
|
||||
'#title' => $this->t('Auto preview'),
|
||||
'#default_value' => \Drupal::config('views.settings')->get('ui.always_live_preview'),
|
||||
);
|
||||
];
|
||||
|
||||
// Add the arguments textfield
|
||||
$form['controls']['view_args'] = array(
|
||||
$form['controls']['view_args'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Preview with contextual filters:'),
|
||||
'#description' => $this->t('Separate contextual filter values with a "/". For example, %example.', array('%example' => '40/12/10')),
|
||||
'#description' => $this->t('Separate contextual filter values with a "/". For example, %example.', ['%example' => '40/12/10']),
|
||||
'#id' => 'preview-args',
|
||||
);
|
||||
];
|
||||
|
||||
$args = array();
|
||||
$args = [];
|
||||
if (!$form_state->isValueEmpty('view_args')) {
|
||||
$args = explode('/', $form_state->getValue('view_args'));
|
||||
}
|
||||
|
||||
$user_input = $form_state->getUserInput();
|
||||
if ($form_state->get('show_preview') || !empty($user_input['js'])) {
|
||||
$form['preview'] = array(
|
||||
$form['preview'] = [
|
||||
'#weight' => 110,
|
||||
'#theme_wrappers' => array('container'),
|
||||
'#attributes' => array('id' => 'views-live-preview', 'class' => 'views-live-preview'),
|
||||
'#theme_wrappers' => ['container'],
|
||||
'#attributes' => ['id' => 'views-live-preview', 'class' => ['views-live-preview']],
|
||||
'preview' => $view->renderPreview($this->displayID, $args),
|
||||
);
|
||||
];
|
||||
}
|
||||
$uri = $view->urlInfo('preview-form');
|
||||
$uri->setRouteParameter('display_id', $this->displayID);
|
||||
@@ -72,27 +72,27 @@ class ViewPreviewForm extends ViewFormBase {
|
||||
*/
|
||||
protected function actions(array $form, FormStateInterface $form_state) {
|
||||
$view = $this->entity;
|
||||
return array(
|
||||
'#attributes' => array(
|
||||
return [
|
||||
'#attributes' => [
|
||||
'id' => 'preview-submit-wrapper',
|
||||
'class' => array('preview-submit-wrapper')
|
||||
),
|
||||
'button' => array(
|
||||
'class' => ['preview-submit-wrapper']
|
||||
],
|
||||
'button' => [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Update preview'),
|
||||
'#attributes' => array('class' => array('arguments-preview')),
|
||||
'#submit' => array('::submitPreview'),
|
||||
'#attributes' => ['class' => ['arguments-preview']],
|
||||
'#submit' => ['::submitPreview'],
|
||||
'#id' => 'preview-submit',
|
||||
'#ajax' => array(
|
||||
'#ajax' => [
|
||||
'url' => Url::fromRoute('entity.view.preview_form', ['view' => $view->id(), 'display_id' => $this->displayID]),
|
||||
'wrapper' => 'views-preview-wrapper',
|
||||
'event' => 'click',
|
||||
'progress' => array('type' => 'fullscreen'),
|
||||
'progress' => ['type' => 'fullscreen'],
|
||||
'method' => 'replaceWith',
|
||||
'disable-refocus' => TRUE,
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace Drupal\views_ui;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Component\Utility\Timer;
|
||||
use Drupal\Component\Utility\Xss;
|
||||
use Drupal\Core\EventSubscriber\AjaxResponseSubscriber;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\views\Views;
|
||||
@@ -107,7 +106,7 @@ class ViewUI implements ViewEntityInterface {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $forms = array(
|
||||
public static $forms = [
|
||||
'add-handler' => '\Drupal\views_ui\Form\Ajax\AddItem',
|
||||
'analyze' => '\Drupal\views_ui\Form\Ajax\Analyze',
|
||||
'handler' => '\Drupal\views_ui\Form\Ajax\ConfigHandler',
|
||||
@@ -118,7 +117,7 @@ class ViewUI implements ViewEntityInterface {
|
||||
'rearrange' => '\Drupal\views_ui\Form\Ajax\Rearrange',
|
||||
'rearrange-filter' => '\Drupal\views_ui\Form\Ajax\RearrangeFilter',
|
||||
'reorder-displays' => '\Drupal\views_ui\Form\Ajax\ReorderDisplays',
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Whether the config is being created, updated or deleted through the
|
||||
@@ -277,22 +276,22 @@ class ViewUI implements ViewEntityInterface {
|
||||
* docblock outdated?
|
||||
*/
|
||||
public function getStandardButtons(&$form, FormStateInterface $form_state, $form_id, $name = NULL) {
|
||||
$form['actions'] = array(
|
||||
$form['actions'] = [
|
||||
'#type' => 'actions',
|
||||
);
|
||||
];
|
||||
|
||||
if (empty($name)) {
|
||||
$name = t('Apply');
|
||||
if (!empty($this->stack) && count($this->stack) > 1) {
|
||||
$name = t('Apply and continue');
|
||||
}
|
||||
$names = array(t('Apply'), t('Apply and continue'));
|
||||
$names = [t('Apply'), t('Apply and continue')];
|
||||
}
|
||||
|
||||
// Forms that are purely informational set an ok_button flag, so we know not
|
||||
// to create an "Apply" button for them.
|
||||
if (!$form_state->get('ok_button')) {
|
||||
$form['actions']['submit'] = array(
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $name,
|
||||
'#id' => 'edit-submit-' . Html::getUniqueId($form_id),
|
||||
@@ -301,9 +300,9 @@ class ViewUI implements ViewEntityInterface {
|
||||
// the current display. Since we have no way of knowing at this point
|
||||
// which display the user wants to update, views_ui_standard_submit will
|
||||
// take care of running the regular submit handler as appropriate.
|
||||
'#submit' => array(array($this, 'standardSubmit')),
|
||||
'#submit' => [[$this, 'standardSubmit']],
|
||||
'#button_type' => 'primary',
|
||||
);
|
||||
];
|
||||
// Form API button click detection requires the button's #value to be the
|
||||
// same between the form build of the initial page request, and the
|
||||
// initial form build of the request processing the form submission.
|
||||
@@ -315,21 +314,21 @@ class ViewUI implements ViewEntityInterface {
|
||||
// button labels.
|
||||
if (isset($names)) {
|
||||
$form['actions']['submit']['#values'] = $names;
|
||||
$form['actions']['submit']['#process'] = array_merge(array('views_ui_form_button_was_clicked'), \Drupal::service('element_info')->getInfoProperty($form['actions']['submit']['#type'], '#process', array()));
|
||||
$form['actions']['submit']['#process'] = array_merge(['views_ui_form_button_was_clicked'], \Drupal::service('element_info')->getInfoProperty($form['actions']['submit']['#type'], '#process', []));
|
||||
}
|
||||
// If a validation handler exists for the form, assign it to this button.
|
||||
$form['actions']['submit']['#validate'][] = [$form_state->getFormObject(), 'validateForm'];
|
||||
}
|
||||
|
||||
// Create a "Cancel" button. For purely informational forms, label it "OK".
|
||||
$cancel_submit = function_exists($form_id . '_cancel') ? $form_id . '_cancel' : array($this, 'standardCancel');
|
||||
$form['actions']['cancel'] = array(
|
||||
$cancel_submit = function_exists($form_id . '_cancel') ? $form_id . '_cancel' : [$this, 'standardCancel'];
|
||||
$form['actions']['cancel'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => !$form_state->get('ok_button') ? t('Cancel') : t('Ok'),
|
||||
'#submit' => array($cancel_submit),
|
||||
'#validate' => array(),
|
||||
'#limit_validation_errors' => array(),
|
||||
);
|
||||
'#submit' => [$cancel_submit],
|
||||
'#validate' => [],
|
||||
'#limit_validation_errors' => [],
|
||||
];
|
||||
|
||||
// Compatibility, to be removed later: // TODO: When is "later"?
|
||||
// We used to set these items on the form, but now we want them on the $form_state:
|
||||
@@ -348,11 +347,11 @@ class ViewUI implements ViewEntityInterface {
|
||||
*/
|
||||
public function getOverrideValues($form, FormStateInterface $form_state) {
|
||||
// Make sure the dropdown exists in the first place.
|
||||
if ($form_state->hasValue(array('override', 'dropdown'))) {
|
||||
if ($form_state->hasValue(['override', 'dropdown'])) {
|
||||
// #default_value is used to determine whether it was the default value or not.
|
||||
// So the available options are: $display, 'default' and 'default_revert', not 'defaults'.
|
||||
$was_defaulted = ($form['override']['dropdown']['#default_value'] === 'defaults');
|
||||
$dropdown = $form_state->getValue(array('override', 'dropdown'));
|
||||
$dropdown = $form_state->getValue(['override', 'dropdown']);
|
||||
$is_defaulted = ($dropdown === 'default');
|
||||
$revert = ($dropdown === 'default_revert');
|
||||
|
||||
@@ -369,7 +368,7 @@ class ViewUI implements ViewEntityInterface {
|
||||
$revert = FALSE;
|
||||
}
|
||||
|
||||
return array($was_defaulted, $is_defaulted, $revert);
|
||||
return [$was_defaulted, $is_defaulted, $revert];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -383,10 +382,10 @@ class ViewUI implements ViewEntityInterface {
|
||||
Html::resetSeenIds();
|
||||
|
||||
if (empty($this->stack)) {
|
||||
$this->stack = array();
|
||||
$this->stack = [];
|
||||
}
|
||||
|
||||
$stack = array(implode('-', array_filter(array($key, $this->id(), $display_id, $type, $id))), $key, $display_id, $type, $id);
|
||||
$stack = [implode('-', array_filter([$key, $this->id(), $display_id, $type, $id])), $key, $display_id, $type, $id];
|
||||
// If we're being asked to add this form to the bottom of the stack, no
|
||||
// special logic is required. Our work is equally easy if we were asked to add
|
||||
// to the top of the stack, but there's nothing in it yet.
|
||||
@@ -463,10 +462,10 @@ class ViewUI implements ViewEntityInterface {
|
||||
if (isset($types[$type]['type'])) {
|
||||
$key = $types[$type]['type'];
|
||||
}
|
||||
$item = array(
|
||||
$item = [
|
||||
'table' => $table,
|
||||
'field' => $field,
|
||||
);
|
||||
];
|
||||
$handler = Views::handlerManager($key)->getHandler($item);
|
||||
if ($this->getExecutable()->displayHandlers->get('default')->useGroupBy() && $handler->usesGroupBy()) {
|
||||
$this->addFormToStack('handler-group', $display_id, $type, $id);
|
||||
@@ -512,7 +511,7 @@ class ViewUI implements ViewEntityInterface {
|
||||
$this->additionalQueries = $queries;
|
||||
}
|
||||
|
||||
public function renderPreview($display_id, $args = array()) {
|
||||
public function renderPreview($display_id, $args = []) {
|
||||
// Save the current path so it can be restored before returning from this function.
|
||||
$request_stack = \Drupal::requestStack();
|
||||
$current_request = $request_stack->getCurrentRequest();
|
||||
@@ -531,7 +530,7 @@ class ViewUI implements ViewEntityInterface {
|
||||
|
||||
$combined = $show_query && $show_stats;
|
||||
|
||||
$rows = array('query' => array(), 'statistics' => array());
|
||||
$rows = ['query' => [], 'statistics' => []];
|
||||
|
||||
$errors = $executable->validate();
|
||||
$executable->destroy();
|
||||
@@ -545,7 +544,7 @@ class ViewUI implements ViewEntityInterface {
|
||||
// have some input in the query parameters, so we merge request() and
|
||||
// query() to ensure we get it all.
|
||||
$exposed_input = array_merge(\Drupal::request()->request->all(), \Drupal::request()->query->all());
|
||||
foreach (array('view_name', 'view_display_id', 'view_args', 'view_path', 'view_dom_id', 'pager_element', 'view_base_path', AjaxResponseSubscriber::AJAX_REQUEST_PARAMETER, 'ajax_page_state', 'form_id', 'form_build_id', 'form_token') as $key) {
|
||||
foreach (['view_name', 'view_display_id', 'view_args', 'view_path', 'view_dom_id', 'pager_element', 'view_base_path', AjaxResponseSubscriber::AJAX_REQUEST_PARAMETER, 'ajax_page_state', 'form_id', 'form_build_id', 'form_token'] as $key) {
|
||||
if (isset($exposed_input[$key])) {
|
||||
unset($exposed_input[$key]);
|
||||
}
|
||||
@@ -554,7 +553,7 @@ class ViewUI implements ViewEntityInterface {
|
||||
|
||||
if (!$executable->setDisplay($display_id)) {
|
||||
return [
|
||||
'#markup' => t('Invalid display id @display', array('@display' => $display_id)),
|
||||
'#markup' => t('Invalid display id @display', ['@display' => $display_id]),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -620,76 +619,80 @@ class ViewUI implements ViewEntityInterface {
|
||||
if ($show_query) {
|
||||
$query_string = $executable->build_info['query'];
|
||||
// Only the sql default class has a method getArguments.
|
||||
$quoted = array();
|
||||
$quoted = [];
|
||||
|
||||
if ($executable->query instanceof Sql) {
|
||||
$quoted = $query_string->getArguments();
|
||||
$connection = Database::getConnection();
|
||||
foreach ($quoted as $key => $val) {
|
||||
if (is_array($val)) {
|
||||
$quoted[$key] = implode(', ', array_map(array($connection, 'quote'), $val));
|
||||
$quoted[$key] = implode(', ', array_map([$connection, 'quote'], $val));
|
||||
}
|
||||
else {
|
||||
$quoted[$key] = $connection->quote($val);
|
||||
}
|
||||
}
|
||||
}
|
||||
$rows['query'][] = array(
|
||||
array(
|
||||
'data' => array(
|
||||
$rows['query'][] = [
|
||||
[
|
||||
'data' => [
|
||||
'#type' => 'inline_template',
|
||||
'#template' => "<strong>{% trans 'Query' %}</strong>",
|
||||
),
|
||||
),
|
||||
array(
|
||||
'data' => array(
|
||||
],
|
||||
],
|
||||
[
|
||||
'data' => [
|
||||
'#type' => 'inline_template',
|
||||
'#template' => '<pre>{{ query }}</pre>',
|
||||
'#context' => array('query' => strtr($query_string, $quoted)),
|
||||
),
|
||||
),
|
||||
);
|
||||
'#context' => ['query' => strtr($query_string, $quoted)],
|
||||
],
|
||||
],
|
||||
];
|
||||
if (!empty($this->additionalQueries)) {
|
||||
$queries[] = array(
|
||||
$queries[] = [
|
||||
'#prefix' => '<strong>',
|
||||
'#markup' => t('These queries were run during view rendering:'),
|
||||
'#suffix' => '</strong>',
|
||||
);
|
||||
];
|
||||
foreach ($this->additionalQueries as $query) {
|
||||
$query_string = strtr($query['query'], $query['args']);
|
||||
$queries[] = array(
|
||||
$queries[] = [
|
||||
'#prefix' => "\n",
|
||||
'#markup' => t('[@time ms] @query', array('@time' => round($query['time'] * 100000, 1) / 100000.0, '@query' => $query_string)),
|
||||
);
|
||||
'#markup' => t('[@time ms] @query', ['@time' => round($query['time'] * 100000, 1) / 100000.0, '@query' => $query_string]),
|
||||
];
|
||||
}
|
||||
|
||||
$rows['query'][] = array(
|
||||
array(
|
||||
'data' => array(
|
||||
$rows['query'][] = [
|
||||
[
|
||||
'data' => [
|
||||
'#type' => 'inline_template',
|
||||
'#template' => "<strong>{% trans 'Other queries' %}</strong>",
|
||||
),
|
||||
),
|
||||
array(
|
||||
'data' => array(
|
||||
],
|
||||
],
|
||||
[
|
||||
'data' => [
|
||||
'#prefix' => '<pre>',
|
||||
'queries' => $queries,
|
||||
'#suffix' => '</pre>',
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
if ($show_info) {
|
||||
$rows['query'][] = array(
|
||||
array(
|
||||
'data' => array(
|
||||
$rows['query'][] = [
|
||||
[
|
||||
'data' => [
|
||||
'#type' => 'inline_template',
|
||||
'#template' => "<strong>{% trans 'Title' %}</strong>",
|
||||
),
|
||||
),
|
||||
Xss::filterAdmin($executable->getTitle()),
|
||||
);
|
||||
],
|
||||
],
|
||||
[
|
||||
'data' => [
|
||||
'#markup' => $executable->getTitle(),
|
||||
],
|
||||
],
|
||||
];
|
||||
if (isset($path)) {
|
||||
// @todo Views should expect and store a leading /. See:
|
||||
// https://www.drupal.org/node/2423913
|
||||
@@ -698,51 +701,51 @@ class ViewUI implements ViewEntityInterface {
|
||||
else {
|
||||
$path = t('This display has no path.');
|
||||
}
|
||||
$rows['query'][] = array(
|
||||
array(
|
||||
'data' => array(
|
||||
$rows['query'][] = [
|
||||
[
|
||||
'data' => [
|
||||
'#prefix' => '<strong>',
|
||||
'#markup' => t('Path'),
|
||||
'#suffix' => '</strong>',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'data' => array(
|
||||
],
|
||||
],
|
||||
[
|
||||
'data' => [
|
||||
'#markup' => $path,
|
||||
),
|
||||
)
|
||||
);
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
if ($show_stats) {
|
||||
$rows['statistics'][] = array(
|
||||
array(
|
||||
'data' => array(
|
||||
$rows['statistics'][] = [
|
||||
[
|
||||
'data' => [
|
||||
'#type' => 'inline_template',
|
||||
'#template' => "<strong>{% trans 'Query build time' %}</strong>",
|
||||
),
|
||||
),
|
||||
t('@time ms', array('@time' => intval($executable->build_time * 100000) / 100)),
|
||||
);
|
||||
],
|
||||
],
|
||||
t('@time ms', ['@time' => intval($executable->build_time * 100000) / 100]),
|
||||
];
|
||||
|
||||
$rows['statistics'][] = array(
|
||||
array(
|
||||
'data' => array(
|
||||
$rows['statistics'][] = [
|
||||
[
|
||||
'data' => [
|
||||
'#type' => 'inline_template',
|
||||
'#template' => "<strong>{% trans 'Query execute time' %}</strong>",
|
||||
),
|
||||
),
|
||||
t('@time ms', array('@time' => intval($executable->execute_time * 100000) / 100)),
|
||||
);
|
||||
],
|
||||
],
|
||||
t('@time ms', ['@time' => intval($executable->execute_time * 100000) / 100]),
|
||||
];
|
||||
|
||||
$rows['statistics'][] = array(
|
||||
array(
|
||||
'data' => array(
|
||||
$rows['statistics'][] = [
|
||||
[
|
||||
'data' => [
|
||||
'#type' => 'inline_template',
|
||||
'#template' => "<strong>{% trans 'View render time' %}</strong>",
|
||||
),
|
||||
),
|
||||
t('@time ms', array('@time' => intval($this->render_time * 100) / 100)),
|
||||
);
|
||||
],
|
||||
],
|
||||
t('@time ms', ['@time' => intval($this->render_time * 100) / 100]),
|
||||
];
|
||||
}
|
||||
\Drupal::moduleHandler()->alter('views_preview_info', $rows, $executable);
|
||||
}
|
||||
@@ -750,36 +753,36 @@ class ViewUI implements ViewEntityInterface {
|
||||
// No query was run. Display that information in place of either the
|
||||
// query or the performance statistics, whichever comes first.
|
||||
if ($combined || ($show_location === 'above')) {
|
||||
$rows['query'][] = array(
|
||||
array(
|
||||
'data' => array(
|
||||
$rows['query'][] = [
|
||||
[
|
||||
'data' => [
|
||||
'#prefix' => '<strong>',
|
||||
'#markup' => t('Query'),
|
||||
'#suffix' => '</strong>',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'data' => array(
|
||||
],
|
||||
],
|
||||
[
|
||||
'data' => [
|
||||
'#markup' => t('No query was run'),
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
else {
|
||||
$rows['statistics'][] = array(
|
||||
array(
|
||||
'data' => array(
|
||||
$rows['statistics'][] = [
|
||||
[
|
||||
'data' => [
|
||||
'#prefix' => '<strong>',
|
||||
'#markup' => t('Query'),
|
||||
'#suffix' => '</strong>',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'data' => array(
|
||||
],
|
||||
],
|
||||
[
|
||||
'data' => [
|
||||
'#markup' => t('No query was run'),
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -795,12 +798,12 @@ class ViewUI implements ViewEntityInterface {
|
||||
|
||||
// Assemble the preview, the query info, and the query statistics in the
|
||||
// requested order.
|
||||
$table = array(
|
||||
$table = [
|
||||
'#type' => 'table',
|
||||
'#prefix' => '<div class="views-query-info">',
|
||||
'#suffix' => '</div>',
|
||||
'#rows' => array_merge($rows['query'], $rows['statistics']),
|
||||
);
|
||||
];
|
||||
|
||||
if ($show_location == 'above') {
|
||||
$output = [
|
||||
@@ -843,7 +846,7 @@ class ViewUI implements ViewEntityInterface {
|
||||
$current = reset($keys) + 1;
|
||||
$total = end($keys) + 1;
|
||||
if ($total > 1) {
|
||||
$progress = array();
|
||||
$progress = [];
|
||||
$progress['current'] = $current;
|
||||
$progress['total'] = $total;
|
||||
}
|
||||
@@ -892,7 +895,7 @@ class ViewUI implements ViewEntityInterface {
|
||||
* Passes through all unknown calls onto the storage object.
|
||||
*/
|
||||
public function __call($method, $args) {
|
||||
return call_user_func_array(array($this->storage, $method), $args);
|
||||
return call_user_func_array([$this->storage, $method], $args);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -968,7 +971,7 @@ class ViewUI implements ViewEntityInterface {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(array $values = array()) {
|
||||
public static function create(array $values = []) {
|
||||
return View::create($values);
|
||||
}
|
||||
|
||||
@@ -1160,14 +1163,14 @@ class ViewUI implements ViewEntityInterface {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function referencedEntities() {
|
||||
return $this->storage->referencedEntities();
|
||||
}
|
||||
public function referencedEntities() {
|
||||
return $this->storage->referencedEntities();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function url($rel = 'edit-form', $options = array()) {
|
||||
public function url($rel = 'edit-form', $options = []) {
|
||||
return $this->storage->url($rel, $options);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
{#
|
||||
/**
|
||||
* @file
|
||||
* Default theme implementation for views displays on the views listing page.
|
||||
*
|
||||
* Available variables:
|
||||
* - displays: Contains multiple display instances. Each display contains:
|
||||
* - display: Display name.
|
||||
* - path: Path to display, if any.
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
#}
|
||||
<ul>
|
||||
{% for display in displays %}
|
||||
<li>
|
||||
{% if display.path %}
|
||||
{{ display.display }} <span data-drupal-selector="views-table-filter-text-source">({{ display.path }})</span>
|
||||
{% else %}
|
||||
{{ display.display }}
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
@@ -0,0 +1,49 @@
|
||||
{#
|
||||
/**
|
||||
* @file
|
||||
* Default theme implementation for views listing table.
|
||||
*
|
||||
* Available variables:
|
||||
* - headers: Contains table headers.
|
||||
* - rows: Contains multiple rows. Each row contains:
|
||||
* - view_name: The human-readable name of the view.
|
||||
* - machine_name: Machine name of the view.
|
||||
* - description: The description of the view.
|
||||
* - displays: List of displays attached to the view.
|
||||
* - operations: List of available operations.
|
||||
*
|
||||
* @see template_preprocess_views_ui_views_listing_table()
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
#}
|
||||
<table{{ attributes.addClass('responsive-enabled') }}>
|
||||
<thead>
|
||||
<tr>
|
||||
{% for header in headers %}
|
||||
<th{{ header.attributes }}>{{ header.data }}</th>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for row in rows %}
|
||||
<tr{{ row.attributes }}>
|
||||
<td class="views-ui-view-name">
|
||||
<h3 data-drupal-selector="views-table-filter-text-source">{{ row.data.view_name.data }}</h3>
|
||||
</td>
|
||||
<td class="views-ui-view-machine-name" data-drupal-selector="views-table-filter-text-source">
|
||||
{{ row.data.machine_name.data }}
|
||||
</td>
|
||||
<td class="views-ui-view-description" data-drupal-selector="views-table-filter-text-source">
|
||||
{{ row.data.description.data }}
|
||||
</td>
|
||||
<td class="views-ui-view-displays">
|
||||
{{ row.data.displays.data }}
|
||||
</td>
|
||||
<td class="views-ui-view-operations">
|
||||
{{ row.data.operations.data }}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -7,8 +7,8 @@ package: Testing
|
||||
dependencies:
|
||||
- views_ui
|
||||
|
||||
# Information added by Drupal.org packaging script on 2016-08-03
|
||||
version: '8.1.8'
|
||||
# Information added by Drupal.org packaging script on 2017-08-16
|
||||
version: '8.3.7'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1470233790
|
||||
datestamp: 1502903957
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
name: 'Views test field'
|
||||
type: module
|
||||
description: 'Add custom global field for testing purposes.'
|
||||
package: Testing
|
||||
# version: VERSION
|
||||
# core: 8.x
|
||||
dependencies:
|
||||
- views_ui
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-08-16
|
||||
version: '8.3.7'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1502903957
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* ViewsUI Test field module.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter() for views_ui_add_handler_form.
|
||||
*
|
||||
* Changes the label for one of the tests fields to validate this label is not
|
||||
* searched on.
|
||||
*/
|
||||
function views_ui_test_field_form_views_ui_add_handler_form_alter(&$form, FormStateInterface $form_state) {
|
||||
$form['options']['name']['#options']['views.views_test_field_1']['title']['data']['#title'] .= ' FIELD_1_LABEL';
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provide views data for testing purposes.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_views_data().
|
||||
*/
|
||||
function views_ui_test_field_views_data() {
|
||||
|
||||
$data['views']['views_test_field_1'] = [
|
||||
'title' => t('Views test field 1 - FIELD_1_TITLE'),
|
||||
'help' => t('Field 1 for testing purposes - FIELD_1_DESCRIPTION'),
|
||||
'field' => [
|
||||
'id' => 'views_test_field_1',
|
||||
],
|
||||
];
|
||||
$data['views']['views_test_field_2'] = [
|
||||
'title' => t('Views test field 2 - FIELD_2_TITLE'),
|
||||
'help' => t('Field 2 for testing purposes - FIELD_2_DESCRIPTION'),
|
||||
'field' => [
|
||||
'id' => 'views_test_field_2',
|
||||
],
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
/**
|
||||
* Tests the views analyze system.
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class AnalyzeTest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['views_ui'];
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_view'];
|
||||
|
||||
/**
|
||||
* Tests that analyze works in general.
|
||||
*/
|
||||
public function testAnalyzeBasic() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
$this->drupalGet('admin/structure/views/view/test_view/edit');
|
||||
$this->assertLink(t('Analyze view'));
|
||||
|
||||
// This redirects the user to the analyze form.
|
||||
$this->clickLink(t('Analyze view'));
|
||||
$this->assertSession()->titleEquals('View analysis | Drupal');
|
||||
|
||||
foreach (['ok', 'warning', 'error'] as $type) {
|
||||
$xpath = $this->xpath('//div[contains(@class, :class)]', [':class' => $type]);
|
||||
$this->assertTrue(count($xpath), format_string('Analyse messages with @type found', ['@type' => $type]));
|
||||
}
|
||||
|
||||
// This redirects the user back to the main views edit page.
|
||||
$this->drupalPostForm(NULL, [], t('Ok'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
use Drupal\block\Entity\Block;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\views\Entity\View;
|
||||
|
||||
/**
|
||||
* Tests the entity area UI test.
|
||||
*
|
||||
* @see \Drupal\views\Plugin\views\area\Entity
|
||||
* @group views_ui
|
||||
*/
|
||||
class AreaEntityUITest extends UITestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['entity_test'];
|
||||
|
||||
public function testUI() {
|
||||
// Set up a block and a entity_test entity.
|
||||
$block = Block::create(['id' => 'test_id', 'plugin' => 'system_main_block']);
|
||||
$block->save();
|
||||
|
||||
$entity_test = EntityTest::create(['bundle' => 'entity_test']);
|
||||
$entity_test->save();
|
||||
|
||||
$default = $this->randomView([]);
|
||||
$id = $default['id'];
|
||||
$view = View::load($id);
|
||||
|
||||
$this->drupalGet($view->urlInfo('edit-form'));
|
||||
|
||||
// Add a global NULL argument to the view for testing argument placeholders.
|
||||
$this->drupalPostForm("admin/structure/views/nojs/add-handler/$id/page_1/argument", ['name[views.null]' => TRUE], 'Add and configure contextual filters');
|
||||
$this->drupalPostForm(NULL, [], 'Apply');
|
||||
|
||||
// Configure both the entity_test area header and the block header to
|
||||
// reference the given entities.
|
||||
$this->drupalPostForm("admin/structure/views/nojs/add-handler/$id/page_1/header", ['name[views.entity_block]' => TRUE], 'Add and configure header');
|
||||
$this->drupalPostForm(NULL, ['options[target]' => $block->id()], 'Apply');
|
||||
|
||||
$this->drupalPostForm("admin/structure/views/nojs/add-handler/$id/page_1/header", ['name[views.entity_entity_test]' => TRUE], 'Add and configure header');
|
||||
$this->drupalPostForm(NULL, ['options[target]' => $entity_test->id()], 'Apply');
|
||||
|
||||
$this->drupalPostForm(NULL, [], 'Save');
|
||||
|
||||
// Confirm the correct target identifiers were saved for both entities.
|
||||
$view = View::load($id);
|
||||
$header = $view->getDisplay('default')['display_options']['header'];
|
||||
$this->assertEqual(['entity_block', 'entity_entity_test'], array_keys($header));
|
||||
|
||||
$this->assertEqual($block->id(), $header['entity_block']['target']);
|
||||
$this->assertEqual($entity_test->uuid(), $header['entity_entity_test']['target']);
|
||||
|
||||
// Confirm that the correct serial ID (for the entity_test) and config ID
|
||||
// (for the block) are displayed in the form.
|
||||
$this->drupalGet("admin/structure/views/nojs/handler/$id/page_1/header/entity_block");
|
||||
$this->assertFieldByName('options[target]', $block->id());
|
||||
|
||||
$this->drupalGet("admin/structure/views/nojs/handler/$id/page_1/header/entity_entity_test");
|
||||
$this->assertFieldByName('options[target]', $entity_test->id());
|
||||
|
||||
// Replace the header target entities with argument placeholders.
|
||||
$this->drupalPostForm("admin/structure/views/nojs/handler/$id/page_1/header/entity_block", ['options[target]' => '{{ raw_arguments.null }}'], 'Apply');
|
||||
$this->drupalPostForm("admin/structure/views/nojs/handler/$id/page_1/header/entity_entity_test", ['options[target]' => '{{ raw_arguments.null }}'], 'Apply');
|
||||
$this->drupalPostForm(NULL, [], 'Save');
|
||||
|
||||
// Confirm that the argument placeholders are saved.
|
||||
$view = View::load($id);
|
||||
$header = $view->getDisplay('default')['display_options']['header'];
|
||||
$this->assertEqual(['entity_block', 'entity_entity_test'], array_keys($header));
|
||||
|
||||
$this->assertEqual('{{ raw_arguments.null }}', $header['entity_block']['target']);
|
||||
$this->assertEqual('{{ raw_arguments.null }}', $header['entity_entity_test']['target']);
|
||||
|
||||
// Confirm that the argument placeholders are still displayed in the form.
|
||||
$this->drupalGet("admin/structure/views/nojs/handler/$id/page_1/header/entity_block");
|
||||
$this->assertFieldByName('options[target]', '{{ raw_arguments.null }}');
|
||||
|
||||
$this->drupalGet("admin/structure/views/nojs/handler/$id/page_1/header/entity_entity_test");
|
||||
$this->assertFieldByName('options[target]', '{{ raw_arguments.null }}');
|
||||
|
||||
// Change the targets for both headers back to the entities.
|
||||
$this->drupalPostForm("admin/structure/views/nojs/handler/$id/page_1/header/entity_block", ['options[target]' => $block->id()], 'Apply');
|
||||
$this->drupalPostForm("admin/structure/views/nojs/handler/$id/page_1/header/entity_entity_test", ['options[target]' => $entity_test->id()], 'Apply');
|
||||
$this->drupalPostForm(NULL, [], 'Save');
|
||||
|
||||
// Confirm the targets were again saved correctly and not skipped based on
|
||||
// the previous form value.
|
||||
$view = View::load($id);
|
||||
$header = $view->getDisplay('default')['display_options']['header'];
|
||||
$this->assertEqual(['entity_block', 'entity_entity_test'], array_keys($header));
|
||||
|
||||
$this->assertEqual($block->id(), $header['entity_block']['target']);
|
||||
$this->assertEqual($entity_test->uuid(), $header['entity_entity_test']['target']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the Argument validator through the UI.
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class ArgumentValidatorTest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_argument'];
|
||||
|
||||
/**
|
||||
* Tests the 'Specify validation criteria' checkbox functionality.
|
||||
*/
|
||||
public function testSpecifyValidation() {
|
||||
// Specify a validation based on Node for the 'id' argument on the default
|
||||
// display and assert that this works.
|
||||
$this->saveArgumentHandlerWithValidationOptions(TRUE);
|
||||
$view = Views::getView('test_argument');
|
||||
$handler = $view->getHandler('default', 'argument', 'id');
|
||||
$this->assertTrue($handler['specify_validation'], 'Validation for this argument has been turned on.');
|
||||
$this->assertEqual('entity:node', $handler['validate']['type'], 'Validation for the argument is based on the node.');
|
||||
|
||||
// Uncheck the 'Specify validation criteria' checkbox and expect the
|
||||
// validation type to be reset back to 'none'.
|
||||
$this->saveArgumentHandlerWithValidationOptions(FALSE);
|
||||
$view = Views::getView('test_argument');
|
||||
$handler = $view->getHandler('default', 'argument', 'id');
|
||||
$this->assertFalse($handler['specify_validation'], 'Validation for this argument has been turned off.');
|
||||
$this->assertEqual('none', $handler['validate']['type'], 'Validation for the argument has been reverted to Basic Validation.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the test_argument view with changes made to the argument handler
|
||||
* both with and without specify_validation turned on.
|
||||
*
|
||||
* @param bool $specify_validation
|
||||
*/
|
||||
protected function saveArgumentHandlerWithValidationOptions($specify_validation) {
|
||||
$options = [
|
||||
'options[validate][type]' => 'entity---node',
|
||||
'options[specify_validation]' => $specify_validation,
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/views/nojs/handler/test_argument/default/argument/id', $options, t('Apply'));
|
||||
$this->drupalPostForm('admin/structure/views/view/test_argument', [], t('Save'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
/**
|
||||
* Tests the user tempstore cache in the UI.
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class CachedDataUITest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_view'];
|
||||
|
||||
/**
|
||||
* Tests the user tempstore views data in the UI.
|
||||
*/
|
||||
public function testCacheData() {
|
||||
$views_admin_user_uid = $this->fullAdminUser->id();
|
||||
|
||||
$temp_store = $this->container->get('user.shared_tempstore')->get('views');
|
||||
// The view should not be locked.
|
||||
$this->assertEqual($temp_store->getMetadata('test_view'), NULL, 'The view is not locked.');
|
||||
|
||||
$this->drupalGet('admin/structure/views/view/test_view/edit');
|
||||
// Make sure we have 'changes' to the view.
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/test_view/default/title', [], t('Apply'));
|
||||
$this->assertText('You have unsaved changes.');
|
||||
$this->assertEqual($temp_store->getMetadata('test_view')->owner, $views_admin_user_uid, 'View cache has been saved.');
|
||||
|
||||
$view_cache = $temp_store->get('test_view');
|
||||
// The view should be enabled.
|
||||
$this->assertTrue($view_cache->status(), 'The view is enabled.');
|
||||
// The view should now be locked.
|
||||
$this->assertEqual($temp_store->getMetadata('test_view')->owner, $views_admin_user_uid, 'The view is locked.');
|
||||
|
||||
// Cancel the view edit and make sure the cache is deleted.
|
||||
$this->drupalPostForm(NULL, [], t('Cancel'));
|
||||
$this->assertEqual($temp_store->getMetadata('test_view'), NULL, 'User tempstore data has been removed.');
|
||||
// Test we are redirected to the view listing page.
|
||||
$this->assertUrl('admin/structure/views', [], 'Redirected back to the view listing page.');
|
||||
|
||||
// Log in with another user and make sure the view is locked and break.
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/test_view/default/title', [], t('Apply'));
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
$this->drupalGet('admin/structure/views/view/test_view/edit');
|
||||
// Test that save and cancel buttons are not shown.
|
||||
$this->assertNoFieldById('edit-actions-submit', t('Save'));
|
||||
$this->assertNoFieldById('edit-actions-cancel', t('Cancel'));
|
||||
// Test we have the break lock link.
|
||||
$this->assertLinkByHref('admin/structure/views/view/test_view/break-lock');
|
||||
// Break the lock.
|
||||
$this->clickLink(t('break this lock'));
|
||||
$this->drupalPostForm(NULL, [], t('Break lock'));
|
||||
// Test that save and cancel buttons are shown.
|
||||
$this->assertFieldById('edit-actions-submit', t('Save'));
|
||||
$this->assertFieldById('edit-actions-cancel', t('Cancel'));
|
||||
// Test we can save the view.
|
||||
$this->drupalPostForm('admin/structure/views/view/test_view/edit', [], t('Save'));
|
||||
$this->assertRaw(t('The view %view has been saved.', ['%view' => 'Test view']));
|
||||
|
||||
// Test that a deleted view has no tempstore data.
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/test_view/default/title', [], t('Apply'));
|
||||
$this->drupalPostForm('admin/structure/views/view/test_view/delete', [], t('Delete'));
|
||||
// No view tempstore data should be returned for this view after deletion.
|
||||
$this->assertEqual($temp_store->getMetadata('test_view'), NULL, 'View tempstore data has been removed after deletion.');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the UI and functionality for the Custom boolean field handler options.
|
||||
*
|
||||
* @group views_ui
|
||||
* @see \Drupal\views\Plugin\views\field\Boolean
|
||||
*/
|
||||
class CustomBooleanTest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_view'];
|
||||
|
||||
/**
|
||||
* \Drupal\views\Tests\ViewTestBase::viewsData().
|
||||
*/
|
||||
public function viewsData() {
|
||||
$data = parent::viewsData();
|
||||
$data['views_test_data']['age']['field']['id'] = 'boolean';
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function dataSet() {
|
||||
$data = parent::dataSet();
|
||||
$data[0]['age'] = 0;
|
||||
$data[3]['age'] = 0;
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the setting and output of custom labels for boolean values.
|
||||
*/
|
||||
public function testCustomOption() {
|
||||
// Add the boolean field handler to the test view.
|
||||
$view = Views::getView('test_view');
|
||||
$view->setDisplay();
|
||||
|
||||
$view->displayHandlers->get('default')->overrideOption('fields', [
|
||||
'age' => [
|
||||
'id' => 'age',
|
||||
'table' => 'views_test_data',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
'plugin_id' => 'boolean',
|
||||
],
|
||||
]);
|
||||
$view->save();
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
$custom_true = 'Yay';
|
||||
$custom_false = 'Nay';
|
||||
|
||||
// Set up some custom value mappings for different types.
|
||||
$custom_values = [
|
||||
'plain' => [
|
||||
'true' => $custom_true,
|
||||
'false' => $custom_false,
|
||||
'test' => 'assertTrue',
|
||||
],
|
||||
'allowed tag' => [
|
||||
'true' => '<p>' . $custom_true . '</p>',
|
||||
'false' => '<p>' . $custom_false . '</p>',
|
||||
'test' => 'assertTrue',
|
||||
],
|
||||
'disallowed tag' => [
|
||||
'true' => '<script>' . $custom_true . '</script>',
|
||||
'false' => '<script>' . $custom_false . '</script>',
|
||||
'test' => 'assertFalse',
|
||||
],
|
||||
];
|
||||
|
||||
// Run the same tests on each type.
|
||||
foreach ($custom_values as $type => $values) {
|
||||
$options = [
|
||||
'options[type]' => 'custom',
|
||||
'options[type_custom_true]' => $values['true'],
|
||||
'options[type_custom_false]' => $values['false'],
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/views/nojs/handler/test_view/default/field/age', $options, 'Apply');
|
||||
|
||||
// Save the view.
|
||||
$this->drupalPostForm('admin/structure/views/view/test_view', [], 'Save');
|
||||
|
||||
$view = Views::getView('test_view');
|
||||
$output = $view->preview();
|
||||
$output = \Drupal::service('renderer')->renderRoot($output);
|
||||
$this->{$values['test']}(strpos($output, $values['true']), SafeMarkup::format('Expected custom boolean TRUE value %value in output for %type', ['%value' => $values['true'], '%type' => $type]));
|
||||
$this->{$values['test']}(strpos($output, $values['false']), SafeMarkup::format('Expected custom boolean FALSE value %value in output for %type', ['%value' => $values['false'], '%type' => $type]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the setting and output of custom labels for boolean values.
|
||||
*/
|
||||
public function testCustomOptionTemplate() {
|
||||
// Install theme to test with template system.
|
||||
\Drupal::service('theme_handler')->install(['views_test_theme']);
|
||||
|
||||
// Set the default theme for Views preview.
|
||||
$this->config('system.theme')
|
||||
->set('default', 'views_test_theme')
|
||||
->save();
|
||||
$this->assertEqual($this->config('system.theme')->get('default'), 'views_test_theme');
|
||||
|
||||
// Add the boolean field handler to the test view.
|
||||
$view = Views::getView('test_view');
|
||||
$view->setDisplay();
|
||||
|
||||
$view->displayHandlers->get('default')->overrideOption('fields', [
|
||||
'age' => [
|
||||
'id' => 'age',
|
||||
'table' => 'views_test_data',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
'plugin_id' => 'boolean',
|
||||
],
|
||||
]);
|
||||
$view->save();
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
$custom_true = 'Yay';
|
||||
$custom_false = 'Nay';
|
||||
|
||||
// Set up some custom value mappings for different types.
|
||||
$custom_values = [
|
||||
'plain' => [
|
||||
'true' => $custom_true,
|
||||
'false' => $custom_false,
|
||||
'test' => 'assertTrue',
|
||||
],
|
||||
'allowed tag' => [
|
||||
'true' => '<p>' . $custom_true . '</p>',
|
||||
'false' => '<p>' . $custom_false . '</p>',
|
||||
'test' => 'assertTrue',
|
||||
],
|
||||
'disallowed tag' => [
|
||||
'true' => '<script>' . $custom_true . '</script>',
|
||||
'false' => '<script>' . $custom_false . '</script>',
|
||||
'test' => 'assertFalse',
|
||||
],
|
||||
];
|
||||
|
||||
// Run the same tests on each type.
|
||||
foreach ($custom_values as $type => $values) {
|
||||
$options = [
|
||||
'options[type]' => 'custom',
|
||||
'options[type_custom_true]' => $values['true'],
|
||||
'options[type_custom_false]' => $values['false'],
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/views/nojs/handler/test_view/default/field/age', $options, 'Apply');
|
||||
|
||||
// Save the view.
|
||||
$this->drupalPostForm('admin/structure/views/view/test_view', [], 'Save');
|
||||
|
||||
$view = Views::getView('test_view');
|
||||
$output = $view->preview();
|
||||
$output = \Drupal::service('renderer')->renderRoot($output);
|
||||
$this->{$values['test']}(strpos($output, $values['true']), SafeMarkup::format('Expected custom boolean TRUE value %value in output for %type', ['%value' => $values['true'], '%type' => $type]));
|
||||
$this->{$values['test']}(strpos($output, $values['false']), SafeMarkup::format('Expected custom boolean FALSE value %value in output for %type', ['%value' => $values['false'], '%type' => $type]));
|
||||
|
||||
// Assert that we are using the correct template.
|
||||
$this->assertContains('llama', (string) $output);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\user\Entity\Role;
|
||||
use Drupal\user\RoleInterface;
|
||||
|
||||
/**
|
||||
* Tests enabling, disabling, and reverting default views via the listing page.
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class DefaultViewsTest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_view_status', 'test_page_display_menu', 'test_page_display_arguments'];
|
||||
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->placeBlock('page_title_block');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests default views.
|
||||
*/
|
||||
public function testDefaultViews() {
|
||||
// Make sure the view starts off as disabled (does not appear on the listing
|
||||
// page).
|
||||
$edit_href = 'admin/structure/views/view/glossary';
|
||||
$this->drupalGet('admin/structure/views');
|
||||
// @todo Disabled default views do now appear on the front page. Test this
|
||||
// behavior with templates instead.
|
||||
// $this->assertNoLinkByHref($edit_href);
|
||||
|
||||
// Enable the view, and make sure it is now visible on the main listing
|
||||
// page.
|
||||
$this->drupalGet('admin/structure/views');
|
||||
$this->clickViewsOperationLink(t('Enable'), '/glossary/');
|
||||
$this->assertUrl('admin/structure/views');
|
||||
$this->assertLinkByHref($edit_href);
|
||||
|
||||
// It should not be possible to revert the view yet.
|
||||
// @todo Figure out how to handle this with the new configuration system.
|
||||
// $this->assertNoLink(t('Revert'));
|
||||
// $revert_href = 'admin/structure/views/view/glossary/revert';
|
||||
// $this->assertNoLinkByHref($revert_href);
|
||||
|
||||
// Edit the view and change the title. Make sure that the new title is
|
||||
// displayed.
|
||||
$new_title = $this->randomMachineName(16);
|
||||
$edit = ['title' => $new_title];
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/glossary/page_1/title', $edit, t('Apply'));
|
||||
$this->drupalPostForm('admin/structure/views/view/glossary/edit/page_1', [], t('Save'));
|
||||
$this->drupalGet('glossary');
|
||||
$this->assertResponse(200);
|
||||
$this->assertText($new_title);
|
||||
|
||||
// Save another view in the UI.
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/archive/page_1/title', [], t('Apply'));
|
||||
$this->drupalPostForm('admin/structure/views/view/archive/edit/page_1', [], t('Save'));
|
||||
|
||||
// Check there is an enable link. i.e. The view has not been enabled after
|
||||
// editing.
|
||||
$this->drupalGet('admin/structure/views');
|
||||
$this->assertLinkByHref('admin/structure/views/view/archive/enable');
|
||||
// Enable it again so it can be tested for access permissions.
|
||||
$this->clickViewsOperationLink(t('Enable'), '/archive/');
|
||||
|
||||
// It should now be possible to revert the view. Do that, and make sure the
|
||||
// view title we added above no longer is displayed.
|
||||
// $this->drupalGet('admin/structure/views');
|
||||
// $this->assertLink(t('Revert'));
|
||||
// $this->assertLinkByHref($revert_href);
|
||||
// $this->drupalPostForm($revert_href, array(), t('Revert'));
|
||||
// $this->drupalGet('glossary');
|
||||
// $this->assertNoText($new_title);
|
||||
|
||||
// Duplicate the view and check that the normal schema of duplicated views is used.
|
||||
$this->drupalGet('admin/structure/views');
|
||||
$this->clickViewsOperationLink(t('Duplicate'), '/glossary');
|
||||
$edit = [
|
||||
'id' => 'duplicate_of_glossary',
|
||||
];
|
||||
$this->assertTitle(t('Duplicate of @label | @site-name', ['@label' => 'Glossary', '@site-name' => $this->config('system.site')->get('name')]));
|
||||
$this->drupalPostForm(NULL, $edit, t('Duplicate'));
|
||||
$this->assertUrl('admin/structure/views/view/duplicate_of_glossary', [], 'The normal duplicating name schema is applied.');
|
||||
|
||||
// Duplicate a view and set a custom name.
|
||||
$this->drupalGet('admin/structure/views');
|
||||
$this->clickViewsOperationLink(t('Duplicate'), '/glossary');
|
||||
$random_name = strtolower($this->randomMachineName());
|
||||
$this->drupalPostForm(NULL, ['id' => $random_name], t('Duplicate'));
|
||||
$this->assertUrl("admin/structure/views/view/$random_name", [], 'The custom view name got saved.');
|
||||
|
||||
// Now disable the view, and make sure it stops appearing on the main view
|
||||
// listing page but instead goes back to displaying on the disabled views
|
||||
// listing page.
|
||||
// @todo Test this behavior with templates instead.
|
||||
$this->drupalGet('admin/structure/views');
|
||||
$this->clickViewsOperationLink(t('Disable'), '/glossary/');
|
||||
// $this->assertUrl('admin/structure/views');
|
||||
// $this->assertNoLinkByHref($edit_href);
|
||||
// The easiest way to verify it appears on the disabled views listing page
|
||||
// is to try to click the "enable" link from there again.
|
||||
$this->drupalGet('admin/structure/views');
|
||||
$this->clickViewsOperationLink(t('Enable'), '/glossary/');
|
||||
$this->assertUrl('admin/structure/views');
|
||||
$this->assertLinkByHref($edit_href);
|
||||
|
||||
// Clear permissions for anonymous users to check access for default views.
|
||||
Role::load(RoleInterface::ANONYMOUS_ID)->revokePermission('access content')->save();
|
||||
|
||||
// Test the default views disclose no data by default.
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet('glossary');
|
||||
$this->assertResponse(403);
|
||||
$this->drupalGet('archive');
|
||||
$this->assertResponse(403);
|
||||
|
||||
// Test deleting a view.
|
||||
$this->drupalLogin($this->fullAdminUser);
|
||||
$this->drupalGet('admin/structure/views');
|
||||
$this->clickViewsOperationLink(t('Delete'), '/glossary/');
|
||||
// Submit the confirmation form.
|
||||
$this->drupalPostForm(NULL, [], t('Delete'));
|
||||
// Ensure the view is no longer listed.
|
||||
$this->assertUrl('admin/structure/views');
|
||||
$this->assertNoLinkByHref($edit_href);
|
||||
// Ensure the view is no longer available.
|
||||
$this->drupalGet($edit_href);
|
||||
$this->assertResponse(404);
|
||||
$this->assertText('Page not found');
|
||||
|
||||
// Delete all duplicated Glossary views.
|
||||
$this->drupalGet('admin/structure/views');
|
||||
$this->clickViewsOperationLink(t('Delete'), 'duplicate_of_glossary');
|
||||
// Submit the confirmation form.
|
||||
$this->drupalPostForm(NULL, [], t('Delete'));
|
||||
|
||||
$this->drupalGet('glossary');
|
||||
$this->assertResponse(200);
|
||||
|
||||
$this->drupalGet('admin/structure/views');
|
||||
$this->clickViewsOperationLink(t('Delete'), $random_name);
|
||||
// Submit the confirmation form.
|
||||
$this->drupalPostForm(NULL, [], t('Delete'));
|
||||
$this->drupalGet('glossary');
|
||||
$this->assertResponse(404);
|
||||
$this->assertText('Page not found');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that enabling views moves them to the correct table.
|
||||
*/
|
||||
public function testSplitListing() {
|
||||
// Build a re-usable xpath query.
|
||||
$xpath = '//div[@id="views-entity-list"]/div[@class = :status]/table//td/text()[contains(., :title)]';
|
||||
|
||||
$arguments = [
|
||||
':status' => 'views-list-section enabled',
|
||||
':title' => 'test_view_status',
|
||||
];
|
||||
|
||||
$this->drupalGet('admin/structure/views');
|
||||
|
||||
$elements = $this->xpath($xpath, $arguments);
|
||||
$this->assertIdentical(count($elements), 0, 'A disabled view is not found in the enabled views table.');
|
||||
|
||||
$arguments[':status'] = 'views-list-section disabled';
|
||||
$elements = $this->xpath($xpath, $arguments);
|
||||
$this->assertIdentical(count($elements), 1, 'A disabled view is found in the disabled views table.');
|
||||
|
||||
// Enable the view.
|
||||
$this->clickViewsOperationLink(t('Enable'), '/test_view_status/');
|
||||
|
||||
$elements = $this->xpath($xpath, $arguments);
|
||||
$this->assertIdentical(count($elements), 0, 'After enabling a view, it is not found in the disabled views table.');
|
||||
|
||||
$arguments[':status'] = 'views-list-section enabled';
|
||||
$elements = $this->xpath($xpath, $arguments);
|
||||
$this->assertIdentical(count($elements), 1, 'After enabling a view, it is found in the enabled views table.');
|
||||
|
||||
// Attempt to disable the view by path directly, with no token.
|
||||
$this->drupalGet('admin/structure/views/view/test_view_status/disable');
|
||||
$this->assertResponse(403);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that page displays show the correct path.
|
||||
*/
|
||||
public function testPathDestination() {
|
||||
$this->drupalGet('admin/structure/views');
|
||||
|
||||
// Check that links to views on default tabs are rendered correctly.
|
||||
$this->assertLinkByHref('test_page_display_menu');
|
||||
$this->assertNoLinkByHref('test_page_display_menu/default');
|
||||
$this->assertLinkByHref('test_page_display_menu/local');
|
||||
|
||||
// Check that a dynamic path is shown as text.
|
||||
$this->assertRaw('test_route_with_suffix/%/suffix');
|
||||
$this->assertNoLinkByHref(Url::fromUri('base:test_route_with_suffix/%/suffix')->toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Click a link to perform an operation on a view.
|
||||
*
|
||||
* In general, we expect lots of links titled "enable" or "disable" on the
|
||||
* various views listing pages, and they might have tokens in them. So we
|
||||
* need special code to find the correct one to click.
|
||||
*
|
||||
* @param $label
|
||||
* Text between the anchor tags of the desired link.
|
||||
* @param $unique_href_part
|
||||
* A unique string that is expected to occur within the href of the desired
|
||||
* link. For example, if the link URL is expected to look like
|
||||
* "admin/structure/views/view/glossary/*", then "/glossary/" could be
|
||||
* passed as the expected unique string.
|
||||
*
|
||||
* @return
|
||||
* The page content that results from clicking on the link, or FALSE on
|
||||
* failure. Failure also results in a failed assertion.
|
||||
*/
|
||||
public function clickViewsOperationLink($label, $unique_href_part) {
|
||||
$links = $this->xpath('//a[normalize-space(text())=:label]', [':label' => (string) $label]);
|
||||
foreach ($links as $link_index => $link) {
|
||||
$position = strpos($link->getAttribute('href'), $unique_href_part);
|
||||
if ($position !== FALSE) {
|
||||
$index = $link_index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->assertTrue(isset($index), format_string('Link to "@label" containing @part found.', ['@label' => $label, '@part' => $unique_href_part]));
|
||||
if (isset($index)) {
|
||||
return $this->clickLink((string) $label, $index);
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the UI for the attachment display plugin.
|
||||
*
|
||||
* @group views_ui
|
||||
* @see \Drupal\views\Plugin\views\display\Attachment
|
||||
*/
|
||||
class DisplayAttachmentTest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
* .
|
||||
*/
|
||||
public static $testViews = ['test_attachment_ui'];
|
||||
|
||||
/**
|
||||
* Tests the attachment UI.
|
||||
*/
|
||||
public function testAttachmentUI() {
|
||||
$this->drupalGet('admin/structure/views/view/test_attachment_ui/edit/attachment_1');
|
||||
$this->assertText(t('Not defined'), 'The right text appears if there is no attachment selection yet.');
|
||||
|
||||
$attachment_display_url = 'admin/structure/views/nojs/display/test_attachment_ui/attachment_1/displays';
|
||||
$this->drupalGet($attachment_display_url);
|
||||
// Display labels should be escaped.
|
||||
$this->assertEscaped('<em>Page</em>');
|
||||
|
||||
foreach (['default', 'page-1'] as $display_id) {
|
||||
$this->assertNoFieldChecked("edit-displays-$display_id", format_string('Make sure the @display_id can be marked as attached', ['@display_id' => $display_id]));
|
||||
}
|
||||
|
||||
// Save the attachments and test the value on the view.
|
||||
$this->drupalPostForm($attachment_display_url, ['displays[page_1]' => 1], t('Apply'));
|
||||
// Options summary should be escaped.
|
||||
$this->assertEscaped('<em>Page</em>');
|
||||
$this->assertNoRaw('<em>Page</em>');
|
||||
$result = $this->xpath('//a[@id = :id]', [':id' => 'views-attachment-1-displays']);
|
||||
$this->assertEqual($result[0]->getAttribute('title'), t('Page'));
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
|
||||
$view = Views::getView('test_attachment_ui');
|
||||
$view->initDisplay();
|
||||
$this->assertEqual(array_keys(array_filter($view->displayHandlers->get('attachment_1')->getOption('displays'))), ['page_1'], 'The attached displays got saved as expected');
|
||||
|
||||
$this->drupalPostForm($attachment_display_url, ['displays[default]' => 1, 'displays[page_1]' => 1], t('Apply'));
|
||||
$result = $this->xpath('//a[@id = :id]', [':id' => 'views-attachment-1-displays']);
|
||||
$this->assertEqual($result[0]->getAttribute('title'), t('Multiple displays'));
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
|
||||
$view = Views::getView('test_attachment_ui');
|
||||
$view->initDisplay();
|
||||
$this->assertEqual(array_keys($view->displayHandlers->get('attachment_1')->getOption('displays')), ['default', 'page_1'], 'The attached displays got saved as expected');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the attachment working after the attached page was deleted.
|
||||
*/
|
||||
public function testRemoveAttachedDisplay() {
|
||||
// Create a view.
|
||||
$view = $this->randomView();
|
||||
$path_prefix = 'admin/structure/views/view/' . $view['id'] . '/edit';
|
||||
$attachment_display_url = 'admin/structure/views/nojs/display/' . $view['id'] . '/attachment_1/displays';
|
||||
|
||||
// Open the Page display and create the attachment display.
|
||||
$this->drupalGet($path_prefix . '/page_1');
|
||||
$this->drupalPostForm(NULL, [], 'Add Attachment');
|
||||
$this->assertText(t('Not defined'), 'The right text appears if there is no attachment selection yet.');
|
||||
|
||||
// Attach the Attachment to the Page display.
|
||||
$this->drupalPostForm($attachment_display_url, ['displays[page_1]' => 1], t('Apply'));
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
|
||||
// Open the Page display and mark it as deleted.
|
||||
$this->drupalGet($path_prefix . '/page_1');
|
||||
$this->assertFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-delete', 'Delete Page', 'Make sure there is a delete button on the page display.');
|
||||
$this->drupalPostForm($path_prefix . '/page_1', [], 'Delete Page');
|
||||
|
||||
// Open the attachment display and save it.
|
||||
$this->drupalGet($path_prefix . '/attachment_1');
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
|
||||
// Check that there is no warning for the removed page display.
|
||||
$this->assertNoText("Plugin ID 'page_1' was not found.");
|
||||
|
||||
// Check that the attachment is no longer linked to the removed display.
|
||||
$this->assertText(t('Not defined'), 'The right text appears if there is no attachment selection yet.');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests creation, retrieval, updating, and deletion of displays in the Web UI.
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class DisplayCRUDTest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_display'];
|
||||
|
||||
/**
|
||||
* Modules to enable
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['contextual'];
|
||||
|
||||
/**
|
||||
* Tests adding a display.
|
||||
*/
|
||||
public function testAddDisplay() {
|
||||
// Show the master display.
|
||||
$this->config('views.settings')->set('ui.show.master_display', TRUE)->save();
|
||||
|
||||
$settings['page[create]'] = FALSE;
|
||||
$view = $this->randomView($settings);
|
||||
|
||||
$path_prefix = 'admin/structure/views/view/' . $view['id'] . '/edit';
|
||||
$this->drupalGet($path_prefix);
|
||||
|
||||
// Add a new display.
|
||||
$this->drupalPostForm(NULL, [], 'Add Page');
|
||||
$this->assertLinkByHref($path_prefix . '/page_1', 0, 'Make sure after adding a display the new display appears in the UI');
|
||||
|
||||
$this->assertNoLink('Master*', 'Make sure the master display is not marked as changed.');
|
||||
$this->assertLink('Page*', 0, 'Make sure the added display is marked as changed.');
|
||||
|
||||
$this->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/page_1/path", ['path' => 'test/path'], t('Apply'));
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests removing a display.
|
||||
*/
|
||||
public function testRemoveDisplay() {
|
||||
$view = $this->randomView();
|
||||
$path_prefix = 'admin/structure/views/view/' . $view['id'] . '/edit';
|
||||
|
||||
$this->drupalGet($path_prefix . '/default');
|
||||
$this->assertNoFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-delete', 'Delete Page', 'Make sure there is no delete button on the default display.');
|
||||
|
||||
$this->drupalGet($path_prefix . '/page_1');
|
||||
$this->assertFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-delete', 'Delete Page', 'Make sure there is a delete button on the page display.');
|
||||
|
||||
// Delete the page, so we can test the undo process.
|
||||
$this->drupalPostForm($path_prefix . '/page_1', [], 'Delete Page');
|
||||
$this->assertFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-undo-delete', 'Undo delete of Page', 'Make sure there a undo button on the page display after deleting.');
|
||||
$element = $this->xpath('//a[contains(@href, :href) and contains(@class, :class)]', [':href' => $path_prefix . '/page_1', ':class' => 'views-display-deleted-link']);
|
||||
$this->assertTrue(!empty($element), 'Make sure the display link is marked as to be deleted.');
|
||||
|
||||
$element = $this->xpath('//a[contains(@href, :href) and contains(@class, :class)]', [':href' => $path_prefix . '/page_1', ':class' => 'views-display-deleted-link']);
|
||||
$this->assertTrue(!empty($element), 'Make sure the display link is marked as to be deleted.');
|
||||
|
||||
// Undo the deleting of the display.
|
||||
$this->drupalPostForm($path_prefix . '/page_1', [], 'Undo delete of Page');
|
||||
$this->assertNoFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-undo-delete', 'Undo delete of Page', 'Make sure there is no undo button on the page display after reverting.');
|
||||
$this->assertFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-delete', 'Delete Page', 'Make sure there is a delete button on the page display after the reverting.');
|
||||
|
||||
// Now delete again and save the view.
|
||||
$this->drupalPostForm($path_prefix . '/page_1', [], 'Delete Page');
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
|
||||
$this->assertNoLinkByHref($path_prefix . '/page_1', 'Make sure there is no display tab for the deleted display.');
|
||||
|
||||
// Test deleting a display that has a modified machine name.
|
||||
$view = $this->randomView();
|
||||
$machine_name = 'new_machine_name';
|
||||
$path_prefix = 'admin/structure/views/view/' . $view['id'] . '/edit';
|
||||
$this->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/page_1/display_id", ['display_id' => $machine_name], 'Apply');
|
||||
$this->drupalPostForm(NULL, [], 'Delete Page');
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertNoLinkByHref($path_prefix . '/new_machine_name', 'Make sure there is no display tab for the deleted display.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the correct display is loaded by default.
|
||||
*/
|
||||
public function testDefaultDisplay() {
|
||||
$this->drupalGet('admin/structure/views/view/test_display');
|
||||
$elements = $this->xpath('//*[@id="views-page-1-display-title"]');
|
||||
$this->assertEqual(count($elements), 1, 'The page display is loaded as the default display.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the duplicating of a display.
|
||||
*/
|
||||
public function testDuplicateDisplay() {
|
||||
$view = $this->randomView();
|
||||
$path_prefix = 'admin/structure/views/view/' . $view['id'] . '/edit';
|
||||
$path = $view['page[path]'];
|
||||
|
||||
$this->drupalGet($path_prefix);
|
||||
$this->drupalPostForm(NULL, [], 'Duplicate Page');
|
||||
$this->assertLinkByHref($path_prefix . '/page_2', 0, 'Make sure after duplicating the new display appears in the UI');
|
||||
$this->assertUrl($path_prefix . '/page_2', [], 'The user got redirected to the new display.');
|
||||
|
||||
// Set the title and override the css classes.
|
||||
$random_title = $this->randomMachineName();
|
||||
$random_css = $this->randomMachineName();
|
||||
$this->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/page_2/title", ['title' => $random_title], t('Apply'));
|
||||
$this->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/page_2/css_class", ['override[dropdown]' => 'page_2', 'css_class' => $random_css], t('Apply'));
|
||||
|
||||
// Duplicate as a different display type.
|
||||
$this->drupalPostForm(NULL, [], 'Duplicate as Block');
|
||||
$this->assertLinkByHref($path_prefix . '/block_1', 0, 'Make sure after duplicating the new display appears in the UI');
|
||||
$this->assertUrl($path_prefix . '/block_1', [], 'The user got redirected to the new display.');
|
||||
$this->assertText(t('Block settings'));
|
||||
$this->assertNoText(t('Page settings'));
|
||||
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
$view = Views::getView($view['id']);
|
||||
$view->initDisplay();
|
||||
|
||||
$page_2 = $view->displayHandlers->get('page_2');
|
||||
$this->assertTrue($page_2, 'The new page display got saved.');
|
||||
$this->assertEqual($page_2->display['display_title'], 'Page');
|
||||
$this->assertEqual($page_2->display['display_options']['path'], $path);
|
||||
$block_1 = $view->displayHandlers->get('block_1');
|
||||
$this->assertTrue($block_1, 'The new block display got saved.');
|
||||
$this->assertEqual($block_1->display['display_plugin'], 'block');
|
||||
$this->assertEqual($block_1->display['display_title'], 'Block', 'The new display title got generated as expected.');
|
||||
$this->assertFalse(isset($block_1->display['display_options']['path']));
|
||||
$this->assertEqual($block_1->getOption('title'), $random_title, 'The overridden title option from the display got copied into the duplicate');
|
||||
$this->assertEqual($block_1->getOption('css_class'), $random_css, 'The overridden css_class option from the display got copied into the duplicate');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the display extender UI.
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class DisplayExtenderUITest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_view'];
|
||||
|
||||
/**
|
||||
* Tests the display extender UI.
|
||||
*/
|
||||
public function testDisplayExtenderUI() {
|
||||
$this->config('views.settings')->set('display_extenders', ['display_extender_test'])->save();
|
||||
|
||||
$view = Views::getView('test_view');
|
||||
$view_edit_url = "admin/structure/views/view/{$view->storage->id()}/edit";
|
||||
$display_option_url = 'admin/structure/views/nojs/display/test_view/default/test_extender_test_option';
|
||||
|
||||
$this->drupalGet($view_edit_url);
|
||||
$this->assertLinkByHref($display_option_url, 0, 'Make sure the option defined by the test display extender appears in the UI.');
|
||||
|
||||
$random_text = $this->randomMachineName();
|
||||
$this->drupalPostForm($display_option_url, ['test_extender_test_option' => $random_text], t('Apply'));
|
||||
$this->assertLink($random_text);
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
$view = Views::getView($view->storage->id());
|
||||
$view->initDisplay();
|
||||
$display_extender_options = $view->display_handler->getOption('display_extenders');
|
||||
$this->assertEqual($display_extender_options['display_extender_test']['test_extender_test_option'], $random_text, 'Make sure that the display extender option got saved.');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
/**
|
||||
* Tests the UI for feed display plugin.
|
||||
*
|
||||
* @group views_ui
|
||||
* @see \Drupal\views\Plugin\views\display\Feed
|
||||
*/
|
||||
class DisplayFeedTest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_display_feed', 'test_style_opml'];
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['views_ui', 'aggregator'];
|
||||
|
||||
/**
|
||||
* Tests feed display admin UI.
|
||||
*/
|
||||
public function testFeedUI() {
|
||||
// Test both RSS and OPML feeds.
|
||||
foreach (self::$testViews as $view_name) {
|
||||
$this->checkFeedViewUi($view_name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks views UI for a specific feed view.
|
||||
*
|
||||
* @param string $view_name
|
||||
* The view name to check against.
|
||||
*/
|
||||
protected function checkFeedViewUi($view_name) {
|
||||
$this->drupalGet('admin/structure/views');
|
||||
// Verify that the page lists the $view_name view.
|
||||
// Regression test: ViewListBuilder::getDisplayPaths() did not properly
|
||||
// check whether a DisplayPluginCollection was returned in iterating over
|
||||
// all displays.
|
||||
$this->assertText($view_name);
|
||||
|
||||
// Check the attach TO interface.
|
||||
$this->drupalGet('admin/structure/views/nojs/display/' . $view_name . '/feed_1/displays');
|
||||
// Display labels should be escaped.
|
||||
$this->assertEscaped('<em>Page</em>');
|
||||
|
||||
// Load all the options of the checkbox.
|
||||
$result = $this->xpath('//div[@id="edit-displays"]/div');
|
||||
$options = [];
|
||||
foreach ($result as $item) {
|
||||
$input_node = $item->find('css', 'input');
|
||||
if ($input_node->hasAttribute('value')) {
|
||||
$options[] = $input_node->getAttribute('value');
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEqual($options, ['default', 'page'], 'Make sure all displays appears as expected.');
|
||||
|
||||
// Post and save this and check the output.
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/' . $view_name . '/feed_1/displays', ['displays[page]' => 'page'], t('Apply'));
|
||||
// Options summary should be escaped.
|
||||
$this->assertEscaped('<em>Page</em>');
|
||||
$this->assertNoRaw('<em>Page</em>');
|
||||
|
||||
$this->drupalGet('admin/structure/views/view/' . $view_name . '/edit/feed_1');
|
||||
$this->assertFieldByXpath('//*[@id="views-feed-1-displays"]', '<em>Page</em>');
|
||||
|
||||
// Add the default display, so there should now be multiple displays.
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/' . $view_name . '/feed_1/displays', ['displays[default]' => 'default'], t('Apply'));
|
||||
$this->drupalGet('admin/structure/views/view/' . $view_name . '/edit/feed_1');
|
||||
$this->assertFieldByXpath('//*[@id="views-feed-1-displays"]', 'Multiple displays');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
use Drupal\Core\Menu\MenuTreeParameters;
|
||||
use Drupal\menu_link_content\Entity\MenuLinkContent;
|
||||
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
|
||||
|
||||
/**
|
||||
* Tests the UI of generic display path plugin.
|
||||
*
|
||||
* @group views_ui
|
||||
* @see \Drupal\views\Plugin\views\display\PathPluginBase
|
||||
*/
|
||||
class DisplayPathTest extends UITestBase {
|
||||
use AssertPageCacheContextsAndTagsTrait;
|
||||
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->placeBlock('page_title_block');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['menu_ui'];
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_view', 'test_page_display_menu'];
|
||||
|
||||
/**
|
||||
* Runs the tests.
|
||||
*/
|
||||
public function testPathUI() {
|
||||
$this->doBasicPathUITest();
|
||||
$this->doAdvancedPathsValidationTest();
|
||||
$this->doPathXssFilterTest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests basic functionality in configuring a view.
|
||||
*/
|
||||
protected function doBasicPathUITest() {
|
||||
$this->drupalGet('admin/structure/views/view/test_view');
|
||||
|
||||
// Add a new page display and check the appearing text.
|
||||
$this->drupalPostForm(NULL, [], 'Add Page');
|
||||
$this->assertText(t('No path is set'), 'The right text appears if no path was set.');
|
||||
$this->assertNoLink(t('View @display', ['@display' => 'page']), 'No view page link found on the page.');
|
||||
|
||||
// Save a path and make sure the summary appears as expected.
|
||||
$random_path = $this->randomMachineName();
|
||||
// @todo Once https://www.drupal.org/node/2351379 is resolved, Views will no
|
||||
// longer use Url::fromUri(), and this path will be able to contain ':'.
|
||||
$random_path = str_replace(':', '', $random_path);
|
||||
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/test_view/page_1/path', ['path' => $random_path], t('Apply'));
|
||||
$this->assertText('/' . $random_path, 'The custom path appears in the summary.');
|
||||
$display_link_text = t('View @display', ['@display' => 'Page']);
|
||||
$this->assertLink($display_link_text, 0, 'view page link found on the page.');
|
||||
$this->clickLink($display_link_text);
|
||||
$this->assertUrl($random_path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that View paths are properly filtered for XSS.
|
||||
*/
|
||||
public function doPathXssFilterTest() {
|
||||
$this->drupalGet('admin/structure/views/view/test_view');
|
||||
$this->drupalPostForm(NULL, [], 'Add Page');
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/test_view/page_2/path', ['path' => '<object>malformed_path</object>'], t('Apply'));
|
||||
$this->drupalPostForm(NULL, [], 'Add Page');
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/test_view/page_3/path', ['path' => '<script>alert("hello");</script>'], t('Apply'));
|
||||
$this->drupalPostForm(NULL, [], 'Add Page');
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/test_view/page_4/path', ['path' => '<script>alert("hello I have placeholders %");</script>'], t('Apply'));
|
||||
$this->drupalPostForm('admin/structure/views/view/test_view', [], t('Save'));
|
||||
$this->drupalGet('admin/structure/views');
|
||||
// The anchor text should be escaped.
|
||||
$this->assertEscaped('/<object>malformed_path</object>');
|
||||
$this->assertEscaped('/<script>alert("hello");</script>');
|
||||
$this->assertEscaped('/<script>alert("hello I have placeholders %");</script>');
|
||||
// Links should be url-encoded.
|
||||
$this->assertRaw('/%3Cobject%3Emalformed_path%3C/object%3E');
|
||||
$this->assertRaw('/%3Cscript%3Ealert%28%22hello%22%29%3B%3C/script%3E');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a couple of invalid path patterns.
|
||||
*/
|
||||
protected function doAdvancedPathsValidationTest() {
|
||||
$url = 'admin/structure/views/nojs/display/test_view/page_1/path';
|
||||
|
||||
$this->drupalPostForm($url, ['path' => '%/magrathea'], t('Apply'));
|
||||
$this->assertUrl($url);
|
||||
$this->assertText('"%" may not be used for the first segment of a path.');
|
||||
|
||||
$this->drupalPostForm($url, ['path' => 'user/%1/example'], t('Apply'));
|
||||
$this->assertUrl($url);
|
||||
$this->assertText("Numeric placeholders may not be used. Please use plain placeholders (%).");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests deleting a page display that has no path.
|
||||
*/
|
||||
public function testDeleteWithNoPath() {
|
||||
$this->drupalGet('admin/structure/views/view/test_view');
|
||||
$this->drupalPostForm(NULL, [], t('Add Page'));
|
||||
$this->drupalPostForm(NULL, [], t('Delete Page'));
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
$this->assertRaw(t('The view %view has been saved.', ['%view' => 'Test view']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the menu and tab option form.
|
||||
*/
|
||||
public function testMenuOptions() {
|
||||
$this->container->get('module_installer')->install(['menu_ui']);
|
||||
$this->drupalGet('admin/structure/views/view/test_view');
|
||||
|
||||
// Add a new page display.
|
||||
$this->drupalPostForm(NULL, [], 'Add Page');
|
||||
|
||||
// Add an invalid path (only fragment).
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/test_view/page_1/path', ['path' => '#foo'], t('Apply'));
|
||||
$this->assertText('Path is empty');
|
||||
|
||||
// Add an invalid path with a query.
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/test_view/page_1/path', ['path' => 'foo?bar'], t('Apply'));
|
||||
$this->assertText('No query allowed.');
|
||||
|
||||
// Add an invalid path with just a query.
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/test_view/page_1/path', ['path' => '?bar'], t('Apply'));
|
||||
$this->assertText('Path is empty');
|
||||
|
||||
// Provide a random, valid path string.
|
||||
$random_string = $this->randomMachineName();
|
||||
|
||||
// Save a path.
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/test_view/page_1/path', ['path' => $random_string], t('Apply'));
|
||||
$this->drupalGet('admin/structure/views/view/test_view');
|
||||
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/test_view/page_1/menu', ['menu[type]' => 'default tab', 'menu[title]' => 'Test tab title'], t('Apply'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertUrl('admin/structure/views/nojs/display/test_view/page_1/tab_options');
|
||||
|
||||
$this->drupalPostForm(NULL, ['tab_options[type]' => 'tab', 'tab_options[title]' => $this->randomString()], t('Apply'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertUrl('admin/structure/views/view/test_view/edit/page_1');
|
||||
|
||||
$this->drupalGet('admin/structure/views/view/test_view');
|
||||
$this->assertLink(t('Tab: @title', ['@title' => 'Test tab title']));
|
||||
// If it's a default tab, it should also have an additional settings link.
|
||||
$this->assertLinkByHref('admin/structure/views/nojs/display/test_view/page_1/tab_options');
|
||||
|
||||
// Ensure that you can select a parent in case the parent does not exist.
|
||||
$this->drupalGet('admin/structure/views/nojs/display/test_page_display_menu/page_5/menu');
|
||||
$this->assertResponse(200);
|
||||
$menu_parent = $this->xpath('//select[@id="edit-menu-parent"]');
|
||||
$menu_options = (array) $menu_parent[0]->findAll('css', 'option');
|
||||
unset($menu_options['@attributes']);
|
||||
|
||||
// Convert array to make the next assertion possible.
|
||||
$menu_options = array_map(function($element) {
|
||||
return $element->getText();
|
||||
}, $menu_options);
|
||||
|
||||
$this->assertEqual([
|
||||
'<User account menu>',
|
||||
'-- My account',
|
||||
'-- Log out',
|
||||
'<Administration>',
|
||||
'<Footer>',
|
||||
'<Main navigation>',
|
||||
'<Tools>',
|
||||
'-- Compose tips (disabled)',
|
||||
'-- Test menu link',
|
||||
], $menu_options);
|
||||
|
||||
// The cache contexts associated with the (in)accessible menu links are
|
||||
// bubbled.
|
||||
$this->assertCacheContext('user.permissions');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the regression in https://www.drupal.org/node/2532490.
|
||||
*/
|
||||
public function testDefaultMenuTabRegression() {
|
||||
$this->container->get('module_installer')->install(['menu_ui', 'menu_link_content', 'toolbar', 'system']);
|
||||
$admin_user = $this->drupalCreateUser([
|
||||
'administer views',
|
||||
'administer blocks',
|
||||
'bypass node access',
|
||||
'access user profiles',
|
||||
'view all revisions',
|
||||
'administer permissions',
|
||||
'administer menu',
|
||||
'link to any page',
|
||||
'access toolbar',
|
||||
]);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
$edit = [
|
||||
'title[0][value]' => 'Menu title',
|
||||
'link[0][uri]' => '/admin/foo',
|
||||
'menu_parent' => 'admin:system.admin'
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/menu/manage/admin/add', $edit, t('Save'));
|
||||
|
||||
$menu_items = \Drupal::entityManager()->getStorage('menu_link_content')->getQuery()
|
||||
->sort('id', 'DESC')
|
||||
->pager(1)
|
||||
->execute();
|
||||
$menu_item = end($menu_items);
|
||||
/** @var \Drupal\menu_link_content\MenuLinkContentInterface $menu_link_content */
|
||||
$menu_link_content = MenuLinkContent::load($menu_item);
|
||||
|
||||
$edit = [];
|
||||
$edit['label'] = $this->randomMachineName(16);
|
||||
$view_id = $edit['id'] = strtolower($this->randomMachineName(16));
|
||||
$edit['description'] = $this->randomMachineName(16);
|
||||
$edit['page[create]'] = TRUE;
|
||||
$edit['page[path]'] = 'admin/foo';
|
||||
|
||||
$this->drupalPostForm('admin/structure/views/add', $edit, t('Save and edit'));
|
||||
|
||||
$parameters = new MenuTreeParameters();
|
||||
$parameters->addCondition('id', $menu_link_content->getPluginId());
|
||||
$result = \Drupal::menuTree()->load('admin', $parameters);
|
||||
$plugin_definition = end($result)->link->getPluginDefinition();
|
||||
$this->assertEqual('view.' . $view_id . '.page_1', $plugin_definition['route_name']);
|
||||
|
||||
$this->clickLink(t('No menu'));
|
||||
|
||||
$this->drupalPostForm(NULL, [
|
||||
'menu[type]' => 'default tab',
|
||||
'menu[title]' => 'Menu title',
|
||||
], t('Apply'));
|
||||
|
||||
$this->assertText('Default tab options');
|
||||
|
||||
$this->drupalPostForm(NULL, [
|
||||
'tab_options[type]' => 'normal',
|
||||
'tab_options[title]' => 'Parent title',
|
||||
], t('Apply'));
|
||||
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
// Assert that saving the view will not cause an exception.
|
||||
$this->assertResponse(200);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\views\Entity\View;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the display UI.
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class DisplayTest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_display'];
|
||||
|
||||
/**
|
||||
* Modules to enable
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['contextual'];
|
||||
|
||||
/**
|
||||
* Tests adding a display.
|
||||
*/
|
||||
public function testAddDisplay() {
|
||||
$view = $this->randomView();
|
||||
$this->assertNoText('Block');
|
||||
$this->assertNoText('Block 2');
|
||||
|
||||
$this->drupalPostForm(NULL, [], t('Add @display', ['@display' => 'Block']));
|
||||
$this->assertText('Block');
|
||||
$this->assertNoText('Block 2');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests reordering of displays.
|
||||
*/
|
||||
public function testReorderDisplay() {
|
||||
$view = [
|
||||
'block[create]' => TRUE
|
||||
];
|
||||
$view = $this->randomView($view);
|
||||
|
||||
$this->clickLink(t('Reorder displays'));
|
||||
$this->assertTrue($this->xpath('//tr[@id="display-row-default"]'), 'Make sure the default display appears on the reorder listing');
|
||||
$this->assertTrue($this->xpath('//tr[@id="display-row-page_1"]'), 'Make sure the page display appears on the reorder listing');
|
||||
$this->assertTrue($this->xpath('//tr[@id="display-row-block_1"]'), 'Make sure the block display appears on the reorder listing');
|
||||
|
||||
// Ensure the view displays are in the expected order in configuration.
|
||||
$expected_display_order = ['default', 'block_1', 'page_1'];
|
||||
$this->assertEqual(array_keys(Views::getView($view['id'])->storage->get('display')), $expected_display_order, 'The correct display names are present.');
|
||||
// Put the block display in front of the page display.
|
||||
$edit = [
|
||||
'displays[page_1][weight]' => 2,
|
||||
'displays[block_1][weight]' => 1
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
|
||||
$view = Views::getView($view['id']);
|
||||
$displays = $view->storage->get('display');
|
||||
$this->assertEqual($displays['default']['position'], 0, 'Make sure the master display comes first.');
|
||||
$this->assertEqual($displays['block_1']['position'], 1, 'Make sure the block display comes before the page display.');
|
||||
$this->assertEqual($displays['page_1']['position'], 2, 'Make sure the page display comes after the block display.');
|
||||
|
||||
// Ensure the view displays are in the expected order in configuration.
|
||||
$this->assertEqual(array_keys($view->storage->get('display')), $expected_display_order, 'The correct display names are present.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests disabling of a display.
|
||||
*/
|
||||
public function testDisableDisplay() {
|
||||
$view = $this->randomView();
|
||||
$path_prefix = 'admin/structure/views/view/' . $view['id'] . '/edit';
|
||||
|
||||
$this->drupalGet($path_prefix);
|
||||
$this->assertFalse($this->xpath('//div[contains(@class, :class)]', [':class' => 'views-display-disabled']), 'Make sure the disabled display css class does not appear after initial adding of a view.');
|
||||
|
||||
$this->assertFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-disable', NULL, 'Make sure the disable button is visible.');
|
||||
$this->assertNoFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-enable', NULL, 'Make sure the enable button is not visible.');
|
||||
$this->drupalPostForm(NULL, [], 'Disable Page');
|
||||
$this->assertTrue($this->xpath('//div[contains(@class, :class)]', [':class' => 'views-display-disabled']), 'Make sure the disabled display css class appears once the display is marked as such.');
|
||||
|
||||
$this->assertNoFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-disable', NULL, 'Make sure the disable button is not visible.');
|
||||
$this->assertFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-enable', NULL, 'Make sure the enable button is visible.');
|
||||
$this->drupalPostForm(NULL, [], 'Enable Page');
|
||||
$this->assertFalse($this->xpath('//div[contains(@class, :class)]', [':class' => 'views-display-disabled']), 'Make sure the disabled display css class does not appears once the display is enabled again.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests views_ui_views_plugins_display_alter is altering plugin definitions.
|
||||
*/
|
||||
public function testDisplayPluginsAlter() {
|
||||
$definitions = Views::pluginManager('display')->getDefinitions();
|
||||
|
||||
$expected = [
|
||||
'route_name' => 'entity.view.edit_form',
|
||||
'route_parameters_names' => ['view' => 'id'],
|
||||
];
|
||||
|
||||
// Test the expected views_ui array exists on each definition.
|
||||
foreach ($definitions as $definition) {
|
||||
$this->assertIdentical($definition['contextual links']['entity.view.edit_form'], $expected, 'Expected views_ui array found in plugin definition.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests display areas.
|
||||
*/
|
||||
public function testDisplayAreas() {
|
||||
// Show the advanced column.
|
||||
$this->config('views.settings')->set('ui.show.advanced_column', TRUE)->save();
|
||||
|
||||
// Add a new data display to the view.
|
||||
$view = Views::getView('test_display');
|
||||
$view->storage->addDisplay('display_no_area_test');
|
||||
$view->save();
|
||||
|
||||
$this->drupalGet('admin/structure/views/view/test_display/edit/display_no_area_test_1');
|
||||
|
||||
$areas = [
|
||||
'header',
|
||||
'footer',
|
||||
'empty',
|
||||
];
|
||||
|
||||
// Assert that the expected text is found in each area category.
|
||||
foreach ($areas as $type) {
|
||||
$element = $this->xpath('//div[contains(@class, :class)]/div', [':class' => $type]);
|
||||
$this->assertEqual($element[0]->getHtml(), SafeMarkup::format('The selected display type does not use @type plugins', ['@type' => $type]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the link-display setting.
|
||||
*/
|
||||
public function testLinkDisplay() {
|
||||
// Test setting the link display in the UI form.
|
||||
$path = 'admin/structure/views/view/test_display/edit/block_1';
|
||||
$link_display_path = 'admin/structure/views/nojs/display/test_display/block_1/link_display';
|
||||
|
||||
// Test the link text displays 'None' and not 'Block 1'
|
||||
$this->drupalGet($path);
|
||||
$result = $this->xpath("//a[contains(@href, :path)]", [':path' => $link_display_path]);
|
||||
$this->assertEqual($result[0]->getHtml(), t('None'), 'Make sure that the link option summary shows "None" by default.');
|
||||
|
||||
$this->drupalGet($link_display_path);
|
||||
$this->assertFieldChecked('edit-link-display-0');
|
||||
|
||||
// Test the default radio option on the link display form.
|
||||
$this->drupalPostForm($link_display_path, ['link_display' => 'page_1'], t('Apply'));
|
||||
// The form redirects to the master display.
|
||||
$this->drupalGet($path);
|
||||
|
||||
$result = $this->xpath("//a[contains(@href, :path)]", [':path' => $link_display_path]);
|
||||
$this->assertEqual($result[0]->getHtml(), 'Page', 'Make sure that the link option summary shows the right linked display.');
|
||||
|
||||
$this->drupalPostForm($link_display_path, ['link_display' => 'custom_url', 'link_url' => 'a-custom-url'], t('Apply'));
|
||||
// The form redirects to the master display.
|
||||
$this->drupalGet($path);
|
||||
|
||||
$this->assertLink(t('Custom URL'), 0, 'The link option has custom URL as summary.');
|
||||
|
||||
// Test the default link_url value for new display
|
||||
$this->drupalPostForm(NULL, [], t('Add Block'));
|
||||
$this->assertUrl('admin/structure/views/view/test_display/edit/block_2');
|
||||
$this->clickLink(t('Custom URL'));
|
||||
$this->assertFieldByName('link_url', 'a-custom-url');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the view status is correctly reflected on the edit form.
|
||||
*/
|
||||
public function testViewStatus() {
|
||||
$view = $this->randomView();
|
||||
$id = $view['id'];
|
||||
|
||||
// The view should initially have the enabled class on it's form wrapper.
|
||||
$this->drupalGet('admin/structure/views/view/' . $id);
|
||||
$elements = $this->xpath('//div[contains(@class, :edit) and contains(@class, :status)]', [':edit' => 'views-edit-view', ':status' => 'enabled']);
|
||||
$this->assertTrue($elements, 'The enabled class was found on the form wrapper');
|
||||
|
||||
$view = Views::getView($id);
|
||||
$view->storage->disable()->save();
|
||||
|
||||
$this->drupalGet('admin/structure/views/view/' . $id);
|
||||
$elements = $this->xpath('//div[contains(@class, :edit) and contains(@class, :status)]', [':edit' => 'views-edit-view', ':status' => 'disabled']);
|
||||
$this->assertTrue($elements, 'The disabled class was found on the form wrapper.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that no XSS is possible for buttons.
|
||||
*/
|
||||
public function testDisplayTitleInButtonsXss() {
|
||||
$xss_markup = '"><script>alert(123)</script>';
|
||||
$view = $this->randomView();
|
||||
$view = View::load($view['id']);
|
||||
\Drupal::configFactory()->getEditable('views.settings')->set('ui.show.master_display', TRUE)->save();
|
||||
|
||||
foreach ([$xss_markup, '"><script>alert(123)</script>'] as $input) {
|
||||
$display =& $view->getDisplay('page_1');
|
||||
$display['display_title'] = $input;
|
||||
$view->save();
|
||||
|
||||
$this->drupalGet("admin/structure/views/view/{$view->id()}");
|
||||
$escaped = views_ui_truncate($input, 25);
|
||||
$this->assertEscaped($escaped);
|
||||
$this->assertNoRaw($xss_markup);
|
||||
|
||||
$this->drupalGet("admin/structure/views/view/{$view->id()}/edit/page_1");
|
||||
$this->assertEscaped("View $escaped");
|
||||
$this->assertNoRaw("View $xss_markup");
|
||||
$this->assertEscaped("Duplicate $escaped");
|
||||
$this->assertNoRaw("Duplicate $xss_markup");
|
||||
$this->assertEscaped("Delete $escaped");
|
||||
$this->assertNoRaw("Delete $xss_markup");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the action links on the edit display UI.
|
||||
*/
|
||||
public function testActionLinks() {
|
||||
// Change the display title of a display so it contains characters that will
|
||||
// be escaped when rendered.
|
||||
$display_title = "'<test>'";
|
||||
$this->drupalGet('admin/structure/views/view/test_display');
|
||||
$display_title_path = 'admin/structure/views/nojs/display/test_display/block_1/display_title';
|
||||
$this->drupalPostForm($display_title_path, ['display_title' => $display_title], t('Apply'));
|
||||
|
||||
// Ensure that the title is escaped as expected.
|
||||
$this->assertEscaped($display_title);
|
||||
$this->assertNoRaw($display_title);
|
||||
|
||||
// Ensure that the dropdown buttons are displayed correctly.
|
||||
$this->assertFieldByXpath('//input[@type="submit"]', 'Duplicate ' . $display_title);
|
||||
$this->assertFieldByXpath('//input[@type="submit"]', 'Delete ' . $display_title);
|
||||
$this->assertFieldByXpath('//input[@type="submit"]', 'Disable ' . $display_title);
|
||||
$this->assertNoFieldByXpath('//input[@type="submit"]', 'Enable ' . $display_title);
|
||||
|
||||
// Disable the display so we can test the rendering of the "Enable" button.
|
||||
$this->drupalPostForm(NULL, NULL, 'Disable ' . $display_title);
|
||||
$this->assertFieldByXpath('//input[@type="submit"]', 'Enable ' . $display_title);
|
||||
$this->assertNoFieldByXpath('//input[@type="submit"]', 'Disable ' . $display_title);
|
||||
|
||||
// Ensure that the title is escaped as expected.
|
||||
$this->assertEscaped($display_title);
|
||||
$this->assertNoRaw($display_title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the override option is hidden when it's not needed.
|
||||
*/
|
||||
public function testHideDisplayOverride() {
|
||||
// Test that the override option appears with two displays.
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/test_display/page_1/field/title');
|
||||
$this->assertText('All displays');
|
||||
|
||||
// Remove a display and test if the override option is hidden.
|
||||
$this->drupalPostForm('admin/structure/views/view/test_display/edit/block_1', [], t('Delete @display', ['@display' => 'Block']));
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/test_display/page_1/field/title');
|
||||
$this->assertNoText('All displays');
|
||||
|
||||
// Test that the override option is shown when display master is on.
|
||||
\Drupal::configFactory()->getEditable('views.settings')->set('ui.show.master_display', TRUE)->save();
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/test_display/page_1/field/title');
|
||||
$this->assertText('All displays');
|
||||
|
||||
// Test that the override option is shown if the current display is
|
||||
// overridden so that the option to revert is available.
|
||||
$this->drupalPostForm(NULL, ['override[dropdown]' => 'page_1'], t('Apply'));
|
||||
\Drupal::configFactory()->getEditable('views.settings')->set('ui.show.master_display', FALSE)->save();
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/test_display/page_1/field/title');
|
||||
$this->assertText('Revert to default');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
/**
|
||||
* Tests the UI for view duplicate tool.
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class DuplicateTest extends UITestBase {
|
||||
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->placeBlock('page_title_block');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if duplicated view exists and has correct label.
|
||||
*/
|
||||
public function testDuplicateView() {
|
||||
|
||||
// Create random view.
|
||||
$random_view = $this->randomView();
|
||||
|
||||
// Initialize array for duplicated view.
|
||||
$view = [];
|
||||
|
||||
// Generate random label and id for new view.
|
||||
$view['label'] = $this->randomMachineName(255);
|
||||
$view['id'] = strtolower($this->randomMachineName(128));
|
||||
|
||||
// Duplicate view.
|
||||
$this->drupalPostForm('admin/structure/views/view/' . $random_view['id'] . '/duplicate', $view, t('Duplicate'));
|
||||
|
||||
// Assert that the page url is correct.
|
||||
$this->assertUrl('admin/structure/views/view/' . $view['id'], [], 'Make sure the view saving was successful and the browser got redirected to the edit page.');
|
||||
|
||||
// Assert that the page title is correctly displayed.
|
||||
$this->assertText($view['label']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
use Drupal\Component\Serialization\Json;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the UI of field handlers.
|
||||
*
|
||||
* @group views_ui
|
||||
* @see \Drupal\views\Plugin\views\field\FieldPluginBase
|
||||
*/
|
||||
class FieldUITest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_view'];
|
||||
|
||||
/**
|
||||
* Tests the UI of field handlers.
|
||||
*/
|
||||
public function testFieldUI() {
|
||||
// Ensure the field is not marked as hidden on the first run.
|
||||
$this->drupalGet('admin/structure/views/view/test_view/edit');
|
||||
$this->assertText('Views test: Name');
|
||||
$this->assertNoText('Views test: Name [' . t('hidden') . ']');
|
||||
|
||||
// Hides the field and check whether the hidden label is appended.
|
||||
$edit_handler_url = 'admin/structure/views/nojs/handler/test_view/default/field/name';
|
||||
$this->drupalPostForm($edit_handler_url, ['options[exclude]' => TRUE], t('Apply'));
|
||||
|
||||
$this->assertText('Views test: Name [' . t('hidden') . ']');
|
||||
|
||||
// Ensure that the expected tokens appear in the UI.
|
||||
$edit_handler_url = 'admin/structure/views/nojs/handler/test_view/default/field/age';
|
||||
$this->drupalGet($edit_handler_url);
|
||||
$result = $this->xpath('//details[@id="edit-options-alter-help"]/div[@class="details-wrapper"]/div[@class="item-list"]/ul/li');
|
||||
$this->assertEqual($result[0]->getHtml(), '{{ age }} == Age');
|
||||
|
||||
$edit_handler_url = 'admin/structure/views/nojs/handler/test_view/default/field/id';
|
||||
$this->drupalGet($edit_handler_url);
|
||||
$result = $this->xpath('//details[@id="edit-options-alter-help"]/div[@class="details-wrapper"]/div[@class="item-list"]/ul/li');
|
||||
$this->assertEqual(trim($result[0]->getHtml()), '{{ age }} == Age');
|
||||
$this->assertEqual(trim($result[1]->getHtml()), '{{ id }} == ID');
|
||||
|
||||
$edit_handler_url = 'admin/structure/views/nojs/handler/test_view/default/field/name';
|
||||
$this->drupalGet($edit_handler_url);
|
||||
$result = $this->xpath('//details[@id="edit-options-alter-help"]/div[@class="details-wrapper"]/div[@class="item-list"]/ul/li');
|
||||
$this->assertEqual(trim($result[0]->getHtml()), '{{ age }} == Age');
|
||||
$this->assertEqual(trim($result[1]->getHtml()), '{{ id }} == ID');
|
||||
$this->assertEqual(trim($result[2]->getHtml()), '{{ name }} == Name');
|
||||
|
||||
$result = $this->xpath('//details[@id="edit-options-more"]');
|
||||
$this->assertEqual(empty($result), TRUE, "Container 'more' is empty and should not be displayed.");
|
||||
|
||||
// Ensure that dialog titles are not escaped.
|
||||
$edit_groupby_url = 'admin/structure/views/nojs/handler/test_view/default/field/name';
|
||||
$this->assertNoLinkByHref($edit_groupby_url, 0, 'No aggregation link found.');
|
||||
|
||||
// Enable aggregation on the view.
|
||||
$edit = [
|
||||
'group_by' => TRUE,
|
||||
];
|
||||
$this->drupalPostForm('/admin/structure/views/nojs/display/test_view/default/group_by', $edit, t('Apply'));
|
||||
|
||||
$this->assertLinkByHref($edit_groupby_url, 0, 'Aggregation link found.');
|
||||
|
||||
$edit_handler_url = '/admin/structure/views/ajax/handler-group/test_view/default/field/name';
|
||||
$this->drupalGet($edit_handler_url);
|
||||
$data = Json::decode($this->getSession()->getPage()->getContent());
|
||||
$this->assertEqual($data[3]['dialogOptions']['title'], 'Configure aggregation settings for field Views test: Name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the field labels.
|
||||
*/
|
||||
public function testFieldLabel() {
|
||||
// Create a view with unformatted style and make sure the fields have no
|
||||
// labels by default.
|
||||
$view = [];
|
||||
$view['label'] = $this->randomMachineName(16);
|
||||
$view['id'] = strtolower($this->randomMachineName(16));
|
||||
$view['description'] = $this->randomMachineName(16);
|
||||
$view['show[wizard_key]'] = 'node';
|
||||
$view['page[create]'] = TRUE;
|
||||
$view['page[style][style_plugin]'] = 'default';
|
||||
$view['page[title]'] = $this->randomMachineName(16);
|
||||
$view['page[path]'] = $view['id'];
|
||||
$this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
|
||||
|
||||
$view = Views::getView($view['id']);
|
||||
$view->initHandlers();
|
||||
$this->assertEqual($view->field['title']->options['label'], '', 'The field label for normal styles are empty.');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
/**
|
||||
* Tests the boolean filter UI.
|
||||
*
|
||||
* @group views_ui
|
||||
* @see \Drupal\views\Plugin\views\filter\BooleanOperator
|
||||
*/
|
||||
class FilterBooleanWebTest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_view'];
|
||||
|
||||
/**
|
||||
* Tests the filter boolean UI.
|
||||
*/
|
||||
public function testFilterBooleanUI() {
|
||||
$this->drupalPostForm('admin/structure/views/nojs/add-handler/test_view/default/filter', ['name[views_test_data.status]' => TRUE], t('Add and configure @handler', ['@handler' => t('filter criteria')]));
|
||||
|
||||
// Check the field widget label. 'title' should be used as a fallback.
|
||||
$result = $this->cssSelect('#edit-options-value--wrapper legend span');
|
||||
$this->assertEqual($result[0]->getHtml(), 'Status');
|
||||
|
||||
$this->drupalPostForm(NULL, [], t('Expose filter'));
|
||||
$this->drupalPostForm(NULL, [], t('Grouped filters'));
|
||||
|
||||
$edit = [];
|
||||
$edit['options[group_info][group_items][1][title]'] = 'Published';
|
||||
$edit['options[group_info][group_items][1][operator]'] = '=';
|
||||
$edit['options[group_info][group_items][1][value]'] = 1;
|
||||
$edit['options[group_info][group_items][2][title]'] = 'Not published';
|
||||
$edit['options[group_info][group_items][2][operator]'] = '=';
|
||||
$edit['options[group_info][group_items][2][value]'] = 0;
|
||||
$edit['options[group_info][group_items][3][title]'] = 'Not published2';
|
||||
$edit['options[group_info][group_items][3][operator]'] = '!=';
|
||||
$edit['options[group_info][group_items][3][value]'] = 1;
|
||||
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/test_view/default/filter/status');
|
||||
|
||||
$result = $this->xpath('//input[@name="options[group_info][group_items][1][value]"]');
|
||||
$this->assertEqual($result[1]->getAttribute('checked'), 'checked');
|
||||
$result = $this->xpath('//input[@name="options[group_info][group_items][2][value]"]');
|
||||
$this->assertEqual($result[2]->getAttribute('checked'), 'checked');
|
||||
$result = $this->xpath('//input[@name="options[group_info][group_items][3][value]"]');
|
||||
$this->assertEqual($result[1]->getAttribute('checked'), 'checked');
|
||||
|
||||
// Test that there is a remove link for each group.
|
||||
$this->assertEqual(count($this->cssSelect('a.views-remove-link')), 3);
|
||||
|
||||
// Test selecting a default and removing an item.
|
||||
$edit = [];
|
||||
$edit['options[group_info][default_group]'] = 2;
|
||||
$edit['options[group_info][group_items][3][remove]'] = 1;
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/test_view/default/filter/status');
|
||||
$this->assertFieldByName('options[group_info][default_group]', 2, 'Second item was set as the default.');
|
||||
$this->assertNoField('options[group_info][group_items][3][remove]', 'Third item was removed.');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
use Drupal\Tests\SchemaCheckTestTrait;
|
||||
|
||||
/**
|
||||
* Tests the numeric filter UI.
|
||||
*
|
||||
* @group views_ui
|
||||
* @see \Drupal\views\Plugin\views\filter\NumericFilter
|
||||
*/
|
||||
class FilterNumericWebTest extends UITestBase {
|
||||
use SchemaCheckTestTrait;
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_view'];
|
||||
|
||||
/**
|
||||
* Tests the filter numeric UI.
|
||||
*/
|
||||
public function testFilterNumericUI() {
|
||||
// Add a page display to the test_view to be able to test the filtering.
|
||||
$path = 'test_view-path';
|
||||
$this->drupalPostForm('admin/structure/views/view/test_view/edit', [], 'Add Page');
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/test_view/page_1/path', ['path' => $path], 'Apply');
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
|
||||
$this->drupalPostForm('admin/structure/views/nojs/add-handler/test_view/default/filter', ['name[views_test_data.age]' => TRUE], t('Add and configure @handler', ['@handler' => t('filter criteria')]));
|
||||
|
||||
$this->drupalPostForm(NULL, [], t('Expose filter'));
|
||||
$this->drupalPostForm(NULL, [], t('Grouped filters'));
|
||||
|
||||
$edit = [];
|
||||
$edit['options[group_info][group_items][1][title]'] = 'Old';
|
||||
$edit['options[group_info][group_items][1][operator]'] = '>';
|
||||
$edit['options[group_info][group_items][1][value][value]'] = 27;
|
||||
$edit['options[group_info][group_items][2][title]'] = 'Young';
|
||||
$edit['options[group_info][group_items][2][operator]'] = '<=';
|
||||
$edit['options[group_info][group_items][2][value][value]'] = 27;
|
||||
$edit['options[group_info][group_items][3][title]'] = 'From 26 to 28';
|
||||
$edit['options[group_info][group_items][3][operator]'] = 'between';
|
||||
$edit['options[group_info][group_items][3][value][min]'] = 26;
|
||||
$edit['options[group_info][group_items][3][value][max]'] = 28;
|
||||
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/test_view/default/filter/age');
|
||||
foreach ($edit as $name => $value) {
|
||||
$this->assertFieldByName($name, $value);
|
||||
}
|
||||
|
||||
$this->drupalPostForm('admin/structure/views/view/test_view', [], t('Save'));
|
||||
$this->assertConfigSchemaByName('views.view.test_view');
|
||||
|
||||
// Test that the exposed filter works as expected.
|
||||
$this->drupalGet('test_view-path');
|
||||
$this->assertText('John');
|
||||
$this->assertText('Paul');
|
||||
$this->assertText('Ringo');
|
||||
$this->assertText('George');
|
||||
$this->assertText('Meredith');
|
||||
$this->drupalPostForm(NULL, ['age' => '2'], 'Apply');
|
||||
$this->assertText('John');
|
||||
$this->assertText('Paul');
|
||||
$this->assertNoText('Ringo');
|
||||
$this->assertText('George');
|
||||
$this->assertNoText('Meredith');
|
||||
|
||||
// Change the filter to a single filter to test the schema when the operator
|
||||
// is not exposed.
|
||||
$this->drupalPostForm('admin/structure/views/nojs/handler/test_view/default/filter/age', [], t('Single filter'));
|
||||
$edit = [];
|
||||
$edit['options[value][value]'] = 25;
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
$this->drupalPostForm('admin/structure/views/view/test_view', [], t('Save'));
|
||||
$this->assertConfigSchemaByName('views.view.test_view');
|
||||
|
||||
// Test that the filter works as expected.
|
||||
$this->drupalGet('test_view-path');
|
||||
$this->assertText('John');
|
||||
$this->assertNoText('Paul');
|
||||
$this->assertNoText('Ringo');
|
||||
$this->assertNoText('George');
|
||||
$this->assertNoText('Meredith');
|
||||
$this->drupalPostForm(NULL, ['age' => '26'], t('Apply'));
|
||||
$this->assertNoText('John');
|
||||
$this->assertText('Paul');
|
||||
$this->assertNoText('Ringo');
|
||||
$this->assertNoText('George');
|
||||
$this->assertNoText('Meredith');
|
||||
|
||||
// Change the filter to a 'between' filter to test if the label and
|
||||
// description are set for the 'minimum' filter element.
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/test_view/default/filter/age');
|
||||
$edit = [];
|
||||
$edit['options[expose][label]'] = 'Age between';
|
||||
$edit['options[expose][description]'] = 'Description of the exposed filter';
|
||||
$edit['options[operator]'] = 'between';
|
||||
$edit['options[value][min]'] = 26;
|
||||
$edit['options[value][max]'] = 28;
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
$this->drupalPostForm('admin/structure/views/view/test_view', [], t('Save'));
|
||||
$this->assertConfigSchemaByName('views.view.test_view');
|
||||
|
||||
$this->drupalPostForm(NULL, [], t('Update preview'));
|
||||
// Check the max field label.
|
||||
$this->assertRaw('<label for="edit-age-max">And</label>', 'Max field label found');
|
||||
$this->assertRaw('<label for="edit-age-min">Age between</label>', 'Min field label found');
|
||||
// Check that the description is shown in the right place.
|
||||
$this->assertEqual(trim($this->cssSelect('.form-item-age-min .description')[0]->getText()), 'Description of the exposed filter');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
/**
|
||||
* Tests for the filters from the UI.
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class FilterUITest extends UITestBase {
|
||||
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_filter_in_operator_ui', 'test_filter_groups'];
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['views_ui', 'node'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
$this->drupalCreateContentType(['type' => 'page']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that an option for a filter is saved as expected from the UI.
|
||||
*/
|
||||
public function testFilterInOperatorUi() {
|
||||
$admin_user = $this->drupalCreateUser(['administer views', 'administer site configuration']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
$path = 'admin/structure/views/nojs/handler/test_filter_in_operator_ui/default/filter/type';
|
||||
$this->drupalGet($path);
|
||||
// Verifies that "Limit list to selected items" option is not selected.
|
||||
$this->assertFieldByName('options[expose][reduce]', FALSE);
|
||||
|
||||
// Select "Limit list to selected items" option and apply.
|
||||
$edit = [
|
||||
'options[expose][reduce]' => TRUE,
|
||||
];
|
||||
$this->drupalPostForm($path, $edit, t('Apply'));
|
||||
|
||||
// Verifies that the option was saved as expected.
|
||||
$this->drupalGet($path);
|
||||
$this->assertFieldByName('options[expose][reduce]', TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the filters from the UI.
|
||||
*/
|
||||
public function testFiltersUI() {
|
||||
$admin_user = $this->drupalCreateUser(['administer views', 'administer site configuration']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
$this->drupalGet('admin/structure/views/view/test_filter_groups');
|
||||
|
||||
$this->assertLink('Content: ID (= 1)', 0, 'Content: ID (= 1) link appears correctly.');
|
||||
|
||||
// Tests that we can create a new filter group from UI.
|
||||
$this->drupalGet('admin/structure/views/nojs/rearrange-filter/test_filter_groups/page');
|
||||
$this->assertNoRaw('<span>Group 3</span>', 'Group 3 has not been added yet.');
|
||||
|
||||
// Create 2 new groups.
|
||||
$this->drupalPostForm(NULL, [], t('Create new filter group'));
|
||||
$this->drupalPostForm(NULL, [], t('Create new filter group'));
|
||||
|
||||
// Remove the new group 3.
|
||||
$this->drupalPostForm(NULL, [], t('Remove group 3'));
|
||||
|
||||
// Verify that the group 4 is now named as 3.
|
||||
$this->assertRaw('<span>Group 3</span>', 'Group 3 still exists.');
|
||||
|
||||
// Remove the group 3 again.
|
||||
$this->drupalPostForm(NULL, [], t('Remove group 3'));
|
||||
|
||||
// Group 3 now does not exist.
|
||||
$this->assertNoRaw('<span>Group 3</span>', 'Group 3 has not been added yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the identifier settings and restrictions.
|
||||
*/
|
||||
public function testFilterIdentifier() {
|
||||
$admin_user = $this->drupalCreateUser(['administer views', 'administer site configuration']);
|
||||
$this->drupalLogin($admin_user);
|
||||
$path = 'admin/structure/views/nojs/handler/test_filter_in_operator_ui/default/filter/type';
|
||||
|
||||
// Set an empty identifier.
|
||||
$edit = [
|
||||
'options[expose][identifier]' => '',
|
||||
];
|
||||
$this->drupalPostForm($path, $edit, t('Apply'));
|
||||
$this->assertText('The identifier is required if the filter is exposed.');
|
||||
|
||||
// Set the identifier to 'value'.
|
||||
$edit = [
|
||||
'options[expose][identifier]' => 'value',
|
||||
];
|
||||
$this->drupalPostForm($path, $edit, t('Apply'));
|
||||
$this->assertText('This identifier is not allowed.');
|
||||
|
||||
// Set the identifier to a value with a restricted character.
|
||||
$edit = [
|
||||
'options[expose][identifier]' => 'value value',
|
||||
];
|
||||
$this->drupalPostForm($path, $edit, t('Apply'));
|
||||
$this->assertText('This identifier has illegal characters.');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
/**
|
||||
* Tests UI of aggregate functionality..
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class GroupByTest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_views_groupby_save'];
|
||||
|
||||
/**
|
||||
* Tests whether basic saving works.
|
||||
*
|
||||
* @todo This should check the change of the settings as well.
|
||||
*/
|
||||
public function testGroupBySave() {
|
||||
$this->drupalGet('admin/structure/views/view/test_views_groupby_save/edit');
|
||||
|
||||
$edit_groupby_url = 'admin/structure/views/nojs/handler-group/test_views_groupby_save/default/field/id';
|
||||
$this->assertNoLinkByHref($edit_groupby_url, 0, 'No aggregation link found.');
|
||||
|
||||
// Enable aggregation on the view.
|
||||
$edit = [
|
||||
'group_by' => TRUE,
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/test_views_groupby_save/default/group_by', $edit, t('Apply'));
|
||||
|
||||
$this->assertLinkByHref($edit_groupby_url, 0, 'Aggregation link found.');
|
||||
|
||||
// Change the groupby type in the UI.
|
||||
$this->drupalPostForm($edit_groupby_url, ['options[group_type]' => 'count'], t('Apply'));
|
||||
$this->assertLink('COUNT(Views test: ID)', 0, 'The count setting is displayed in the UI');
|
||||
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
|
||||
$view = $this->container->get('entity.manager')->getStorage('view')->load('test_views_groupby_save');
|
||||
$display = $view->getDisplay('default');
|
||||
$this->assertTrue($display['display_options']['group_by'], 'The groupby setting was saved on the view.');
|
||||
$this->assertEqual($display['display_options']['fields']['id']['group_type'], 'count', 'Count groupby_type was saved on the view.');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,282 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
use Drupal\views\ViewExecutable;
|
||||
|
||||
/**
|
||||
* Tests handler UI for views.
|
||||
*
|
||||
* @group views_ui
|
||||
* @see \Drupal\views\Plugin\views\HandlerBase
|
||||
*/
|
||||
class HandlerTest extends UITestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['node_test_views'];
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_view_empty', 'test_view_broken', 'node', 'test_node_view'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->placeBlock('page_title_block');
|
||||
ViewTestData::createTestViews(get_class($this), ['node_test_views']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides \Drupal\views\Tests\ViewTestBase::schemaDefinition().
|
||||
*
|
||||
* Adds a uid column to test the relationships.
|
||||
*/
|
||||
protected function schemaDefinition() {
|
||||
$schema = parent::schemaDefinition();
|
||||
|
||||
$schema['views_test_data']['fields']['uid'] = [
|
||||
'description' => "The {users}.uid of the author of the beatle entry.",
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0
|
||||
];
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides \Drupal\views\Tests\ViewTestBase::viewsData().
|
||||
*
|
||||
* Adds:
|
||||
* - a relationship for the uid column.
|
||||
* - a dummy field with no help text.
|
||||
*/
|
||||
protected function viewsData() {
|
||||
$data = parent::viewsData();
|
||||
$data['views_test_data']['uid'] = [
|
||||
'title' => t('UID'),
|
||||
'help' => t('The test data UID'),
|
||||
'relationship' => [
|
||||
'id' => 'standard',
|
||||
'base' => 'users_field_data',
|
||||
'base field' => 'uid'
|
||||
]
|
||||
];
|
||||
|
||||
// Create a dummy field with no help text.
|
||||
$data['views_test_data']['no_help'] = $data['views_test_data']['name'];
|
||||
$data['views_test_data']['no_help']['field']['title'] = t('No help');
|
||||
$data['views_test_data']['no_help']['field']['real field'] = 'name';
|
||||
unset($data['views_test_data']['no_help']['help']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests UI CRUD.
|
||||
*/
|
||||
public function testUICRUD() {
|
||||
$handler_types = ViewExecutable::getHandlerTypes();
|
||||
foreach ($handler_types as $type => $type_info) {
|
||||
// Test adding handlers.
|
||||
$add_handler_url = "admin/structure/views/nojs/add-handler/test_view_empty/default/$type";
|
||||
|
||||
// Area handler types need to use a different handler.
|
||||
if (in_array($type, ['header', 'footer', 'empty'])) {
|
||||
$this->drupalPostForm($add_handler_url, ['name[views.area]' => TRUE], t('Add and configure @handler', ['@handler' => $type_info['ltitle']]));
|
||||
$id = 'area';
|
||||
$edit_handler_url = "admin/structure/views/nojs/handler/test_view_empty/default/$type/$id";
|
||||
}
|
||||
elseif ($type == 'relationship') {
|
||||
$this->drupalPostForm($add_handler_url, ['name[views_test_data.uid]' => TRUE], t('Add and configure @handler', ['@handler' => $type_info['ltitle']]));
|
||||
$id = 'uid';
|
||||
$edit_handler_url = "admin/structure/views/nojs/handler/test_view_empty/default/$type/$id";
|
||||
}
|
||||
else {
|
||||
$this->drupalPostForm($add_handler_url, ['name[views_test_data.job]' => TRUE], t('Add and configure @handler', ['@handler' => $type_info['ltitle']]));
|
||||
$id = 'job';
|
||||
$edit_handler_url = "admin/structure/views/nojs/handler/test_view_empty/default/$type/$id";
|
||||
}
|
||||
|
||||
$this->assertUrl($edit_handler_url, [], 'The user got redirected to the handler edit form.');
|
||||
$random_label = $this->randomMachineName();
|
||||
$this->drupalPostForm(NULL, ['options[admin_label]' => $random_label], t('Apply'));
|
||||
|
||||
$this->assertUrl('admin/structure/views/view/test_view_empty/edit/default', [], 'The user got redirected to the views edit form.');
|
||||
|
||||
$this->assertLinkByHref($edit_handler_url, 0, 'The handler edit link appears in the UI.');
|
||||
$links = $this->xpath('//a[starts-with(normalize-space(text()), :label)]', [':label' => $random_label]);
|
||||
$this->assertTrue(isset($links[0]), 'The handler edit link has the right label');
|
||||
|
||||
// Save the view and have a look whether the handler was added as expected.
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
$view = $this->container->get('entity.manager')->getStorage('view')->load('test_view_empty');
|
||||
$display = $view->getDisplay('default');
|
||||
$this->assertTrue(isset($display['display_options'][$type_info['plural']][$id]), 'Ensure the field was added to the view itself.');
|
||||
|
||||
// Remove the item and check that it's removed
|
||||
$this->drupalPostForm($edit_handler_url, [], t('Remove'));
|
||||
$this->assertNoLinkByHref($edit_handler_url, 0, 'The handler edit link does not appears in the UI after removing.');
|
||||
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
$view = $this->container->get('entity.manager')->getStorage('view')->load('test_view_empty');
|
||||
$display = $view->getDisplay('default');
|
||||
$this->assertFalse(isset($display['display_options'][$type_info['plural']][$id]), 'Ensure the field was removed from the view itself.');
|
||||
}
|
||||
|
||||
// Test adding a field of the user table using the uid relationship.
|
||||
$type_info = $handler_types['relationship'];
|
||||
$add_handler_url = "admin/structure/views/nojs/add-handler/test_view_empty/default/relationship";
|
||||
$this->drupalPostForm($add_handler_url, ['name[views_test_data.uid]' => TRUE], t('Add and configure @handler', ['@handler' => $type_info['ltitle']]));
|
||||
|
||||
$add_handler_url = "admin/structure/views/nojs/add-handler/test_view_empty/default/field";
|
||||
$type_info = $handler_types['field'];
|
||||
$this->drupalPostForm($add_handler_url, ['name[users_field_data.name]' => TRUE], t('Add and configure @handler', ['@handler' => $type_info['ltitle']]));
|
||||
$id = 'name';
|
||||
$edit_handler_url = "admin/structure/views/nojs/handler/test_view_empty/default/field/$id";
|
||||
|
||||
$this->assertUrl($edit_handler_url, [], 'The user got redirected to the handler edit form.');
|
||||
$this->assertFieldByName('options[relationship]', 'uid', 'Ensure the relationship select is filled with the UID relationship.');
|
||||
$this->drupalPostForm(NULL, [], t('Apply'));
|
||||
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
$view = $this->container->get('entity.manager')->getStorage('view')->load('test_view_empty');
|
||||
$display = $view->getDisplay('default');
|
||||
$this->assertTrue(isset($display['display_options'][$type_info['plural']][$id]), 'Ensure the field was added to the view itself.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests escaping of field labels in help text.
|
||||
*/
|
||||
public function testHandlerHelpEscaping() {
|
||||
// Setup a field with two instances using a different label.
|
||||
// Ensure that the label is escaped properly.
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'article']);
|
||||
$this->drupalCreateContentType(['type' => 'page']);
|
||||
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => 'field_test',
|
||||
'entity_type' => 'node',
|
||||
'type' => 'string',
|
||||
])->save();
|
||||
|
||||
FieldConfig::create([
|
||||
'field_name' => 'field_test',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'page',
|
||||
'label' => 'The giraffe" label'
|
||||
])->save();
|
||||
|
||||
FieldConfig::create([
|
||||
'field_name' => 'field_test',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'article',
|
||||
'label' => 'The <em>giraffe"</em> label <script>alert("the return of the xss")</script>'
|
||||
])->save();
|
||||
|
||||
$this->drupalGet('admin/structure/views/nojs/add-handler/content/default/field');
|
||||
$this->assertEscaped('The <em>giraffe"</em> label <script>alert("the return of the xss")</script>');
|
||||
$this->assertEscaped('Appears in: page, article. Also known as: Content: The giraffe" label');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests broken handlers.
|
||||
*/
|
||||
public function testBrokenHandlers() {
|
||||
$handler_types = ViewExecutable::getHandlerTypes();
|
||||
foreach ($handler_types as $type => $type_info) {
|
||||
$this->drupalGet('admin/structure/views/view/test_view_broken/edit');
|
||||
|
||||
$href = "admin/structure/views/nojs/handler/test_view_broken/default/$type/id_broken";
|
||||
|
||||
$result = $this->xpath('//a[contains(@href, :href)]', [':href' => $href]);
|
||||
$this->assertEqual(count($result), 1, SafeMarkup::format('Handler (%type) edit link found.', ['%type' => $type]));
|
||||
|
||||
$text = 'Broken/missing handler';
|
||||
|
||||
$this->assertIdentical($result[0]->getText(), $text, 'Ensure the broken handler text was found.');
|
||||
|
||||
$this->drupalGet($href);
|
||||
$result = $this->xpath('//h1[@class="page-title"]');
|
||||
$this->assertContains($text, $result[0]->getText(), 'Ensure the broken handler text was found.');
|
||||
|
||||
$original_configuration = [
|
||||
'field' => 'id_broken',
|
||||
'id' => 'id_broken',
|
||||
'relationship' => 'none',
|
||||
'table' => 'views_test_data',
|
||||
'plugin_id' => 'numeric',
|
||||
];
|
||||
|
||||
foreach ($original_configuration as $key => $value) {
|
||||
$this->assertText(SafeMarkup::format('@key: @value', ['@key' => $key, '@value' => $value]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that neither node type or node ID appears multiple times.
|
||||
*
|
||||
* @see \Drupal\views\EntityViewsData
|
||||
*/
|
||||
public function testNoDuplicateFields() {
|
||||
$handler_types = ['field', 'filter', 'sort', 'argument'];
|
||||
|
||||
foreach ($handler_types as $handler_type) {
|
||||
$add_handler_url = 'admin/structure/views/nojs/add-handler/test_node_view/default/' . $handler_type;
|
||||
$this->drupalGet($add_handler_url);
|
||||
|
||||
$this->assertNoDuplicateField('ID', 'Content');
|
||||
$this->assertNoDuplicateField('ID', 'Content revision');
|
||||
$this->assertNoDuplicateField('Content type', 'Content');
|
||||
$this->assertNoDuplicateField('UUID', 'Content');
|
||||
$this->assertNoDuplicateField('Revision ID', 'Content');
|
||||
$this->assertNoDuplicateField('Revision ID', 'Content revision');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that no missing help text is shown.
|
||||
*
|
||||
* @see \Drupal\views\EntityViewsData
|
||||
*/
|
||||
public function testErrorMissingHelp() {
|
||||
// Test that the error message is not shown for entity fields but an empty
|
||||
// description field is shown instead.
|
||||
$this->drupalGet('admin/structure/views/nojs/add-handler/test_node_view/default/field');
|
||||
$this->assertNoText('Error: missing help');
|
||||
$this->assertRaw('<td class="description"></td>', 'Empty description found');
|
||||
|
||||
// Test that no error message is shown for other fields.
|
||||
$this->drupalGet('admin/structure/views/nojs/add-handler/test_view_empty/default/field');
|
||||
$this->assertNoText('Error: missing help');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that fields only appear once.
|
||||
*
|
||||
* @param string $field_name
|
||||
* The field name.
|
||||
* @param string $entity_type
|
||||
* The entity type to which the field belongs.
|
||||
*/
|
||||
public function assertNoDuplicateField($field_name, $entity_type) {
|
||||
$elements = $this->xpath('//td[.=:entity_type]/preceding-sibling::td[@class="title" and .=:title]', [':title' => $field_name, ':entity_type' => $entity_type]);
|
||||
$this->assertEqual(1, count($elements), $field_name . ' appears just once in ' . $entity_type . '.');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
/**
|
||||
* Tests configuration schema against new views.
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class NewViewConfigSchemaTest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['views_ui', 'node', 'comment', 'file', 'taxonomy', 'dblog', 'aggregator'];
|
||||
|
||||
/**
|
||||
* Tests creating brand new views.
|
||||
*/
|
||||
public function testNewViews() {
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer views']));
|
||||
|
||||
// Create views with all core Views wizards.
|
||||
$wizards = [
|
||||
// Wizard with their own classes.
|
||||
'node',
|
||||
'node_revision',
|
||||
'users',
|
||||
'comment',
|
||||
'file_managed',
|
||||
'taxonomy_term',
|
||||
'watchdog',
|
||||
// Standard derivative classes.
|
||||
'standard:aggregator_feed',
|
||||
'standard:aggregator_item',
|
||||
];
|
||||
foreach ($wizards as $wizard_key) {
|
||||
$edit = [];
|
||||
$edit['label'] = $this->randomString();
|
||||
$edit['id'] = strtolower($this->randomMachineName());
|
||||
$edit['show[wizard_key]'] = $wizard_key;
|
||||
$edit['description'] = $this->randomString();
|
||||
$this->drupalPostForm('admin/structure/views/add', $edit, t('Save and edit'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
/**
|
||||
* Tests that displays can be correctly overridden via the user interface.
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class OverrideDisplaysTest extends UITestBase {
|
||||
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that displays can be overridden via the UI.
|
||||
*/
|
||||
public function testOverrideDisplays() {
|
||||
// Create a basic view that shows all content, with a page and a block
|
||||
// display.
|
||||
$view['label'] = $this->randomMachineName(16);
|
||||
$view['id'] = strtolower($this->randomMachineName(16));
|
||||
$view['page[create]'] = 1;
|
||||
$view['page[path]'] = $this->randomMachineName(16);
|
||||
$view['block[create]'] = 1;
|
||||
$view_path = $view['page[path]'];
|
||||
$this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
|
||||
|
||||
// Configure its title. Since the page and block both started off with the
|
||||
// same (empty) title in the views wizard, we expect the wizard to have set
|
||||
// things up so that they both inherit from the default display, and we
|
||||
// therefore only need to change that to have it take effect for both.
|
||||
$edit = [];
|
||||
$edit['title'] = $original_title = $this->randomMachineName(16);
|
||||
$edit['override[dropdown]'] = 'default';
|
||||
$this->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/page_1/title", $edit, t('Apply'));
|
||||
$this->drupalPostForm("admin/structure/views/view/{$view['id']}/edit/page_1", [], t('Save'));
|
||||
|
||||
// Add a node that will appear in the view, so that the block will actually
|
||||
// be displayed.
|
||||
$this->drupalCreateContentType(['type' => 'page']);
|
||||
$this->drupalCreateNode();
|
||||
|
||||
// Make sure the title appears in the page.
|
||||
$this->drupalGet($view_path);
|
||||
$this->assertResponse(200);
|
||||
$this->assertText($original_title);
|
||||
|
||||
// Confirm that the view block is available in the block administration UI.
|
||||
$this->drupalGet('admin/structure/block/list/' . $this->config('system.theme')->get('default'));
|
||||
$this->clickLink('Place block');
|
||||
$this->assertText($view['label']);
|
||||
|
||||
// Place the block.
|
||||
$this->drupalPlaceBlock("views_block:{$view['id']}-block_1");
|
||||
|
||||
// Make sure the title appears in the block.
|
||||
$this->drupalGet('');
|
||||
$this->assertText($original_title);
|
||||
|
||||
// Change the title for the page display only, and make sure that the
|
||||
// original title still appears on the page.
|
||||
$edit = [];
|
||||
$edit['title'] = $new_title = $this->randomMachineName(16);
|
||||
$edit['override[dropdown]'] = 'page_1';
|
||||
$this->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/page_1/title", $edit, t('Apply'));
|
||||
$this->drupalPostForm("admin/structure/views/view/{$view['id']}/edit/page_1", [], t('Save'));
|
||||
$this->drupalGet($view_path);
|
||||
$this->assertResponse(200);
|
||||
$this->assertText($new_title);
|
||||
$this->assertText($original_title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the wizard correctly sets up default and overridden displays.
|
||||
*/
|
||||
public function testWizardMixedDefaultOverriddenDisplays() {
|
||||
// Create a basic view with a page, block, and feed. Give the page and feed
|
||||
// identical titles, but give the block a different one, so we expect the
|
||||
// page and feed to inherit their titles from the default display, but the
|
||||
// block to override it.
|
||||
$view['label'] = $this->randomMachineName(16);
|
||||
$view['id'] = strtolower($this->randomMachineName(16));
|
||||
$view['page[create]'] = 1;
|
||||
$view['page[title]'] = $this->randomMachineName(16);
|
||||
$view['page[path]'] = $this->randomMachineName(16);
|
||||
$view['page[feed]'] = 1;
|
||||
$view['page[feed_properties][path]'] = $this->randomMachineName(16);
|
||||
$view['block[create]'] = 1;
|
||||
$view['block[title]'] = $this->randomMachineName(16);
|
||||
$this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
|
||||
|
||||
// Add a node that will appear in the view, so that the block will actually
|
||||
// be displayed.
|
||||
$this->drupalCreateContentType(['type' => 'page']);
|
||||
$this->drupalCreateNode();
|
||||
|
||||
// Make sure that the feed, page and block all start off with the correct
|
||||
// titles.
|
||||
$this->drupalGet($view['page[path]']);
|
||||
$this->assertResponse(200);
|
||||
$this->assertText($view['page[title]']);
|
||||
$this->assertNoText($view['block[title]']);
|
||||
$this->drupalGet($view['page[feed_properties][path]']);
|
||||
$this->assertResponse(200);
|
||||
$this->assertText($view['page[title]']);
|
||||
$this->assertNoText($view['block[title]']);
|
||||
|
||||
// Confirm that the block is available in the block administration UI.
|
||||
$this->drupalGet('admin/structure/block/list/' . $this->config('system.theme')->get('default'));
|
||||
$this->clickLink('Place block');
|
||||
$this->assertText($view['label']);
|
||||
|
||||
// Put the block into the first sidebar region, and make sure it will not
|
||||
// display on the view's page display (since we will be searching for the
|
||||
// presence/absence of the view's title in both the page and the block).
|
||||
$this->drupalPlaceBlock("views_block:{$view['id']}-block_1", [
|
||||
'visibility' => [
|
||||
'request_path' => [
|
||||
'pages' => '/' . $view['page[path]'],
|
||||
'negate' => TRUE,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->drupalGet('');
|
||||
$this->assertText($view['block[title]']);
|
||||
$this->assertNoText($view['page[title]']);
|
||||
|
||||
// Edit the page and change the title. This should automatically change
|
||||
// the feed's title also, but not the block.
|
||||
$edit = [];
|
||||
$edit['title'] = $new_default_title = $this->randomMachineName(16);
|
||||
$this->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/page_1/title", $edit, t('Apply'));
|
||||
$this->drupalPostForm("admin/structure/views/view/{$view['id']}/edit/page_1", [], t('Save'));
|
||||
$this->drupalGet($view['page[path]']);
|
||||
$this->assertResponse(200);
|
||||
$this->assertText($new_default_title);
|
||||
$this->assertNoText($view['page[title]']);
|
||||
$this->assertNoText($view['block[title]']);
|
||||
$this->drupalGet($view['page[feed_properties][path]']);
|
||||
$this->assertResponse(200);
|
||||
$this->assertText($new_default_title);
|
||||
$this->assertNoText($view['page[title]']);
|
||||
$this->assertNoText($view['block[title]']);
|
||||
$this->drupalGet('');
|
||||
$this->assertNoText($new_default_title);
|
||||
$this->assertNoText($view['page[title]']);
|
||||
$this->assertText($view['block[title]']);
|
||||
|
||||
// Edit the block and change the title. This should automatically change
|
||||
// the block title only, and leave the defaults alone.
|
||||
$edit = [];
|
||||
$edit['title'] = $new_block_title = $this->randomMachineName(16);
|
||||
$this->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/block_1/title", $edit, t('Apply'));
|
||||
$this->drupalPostForm("admin/structure/views/view/{$view['id']}/edit/block_1", [], t('Save'));
|
||||
$this->drupalGet($view['page[path]']);
|
||||
$this->assertResponse(200);
|
||||
$this->assertText($new_default_title);
|
||||
$this->drupalGet($view['page[feed_properties][path]']);
|
||||
$this->assertResponse(200);
|
||||
$this->assertText($new_default_title);
|
||||
$this->assertNoText($new_block_title);
|
||||
$this->drupalGet('');
|
||||
$this->assertText($new_block_title);
|
||||
$this->assertNoText($view['block[title]']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the revert to all displays select-option works as expected.
|
||||
*/
|
||||
public function testRevertAllDisplays() {
|
||||
// Create a basic view with a page, block.
|
||||
// Because there is both a title on page and block we expect the title on
|
||||
// the block be overridden.
|
||||
$view['label'] = $this->randomMachineName(16);
|
||||
$view['id'] = strtolower($this->randomMachineName(16));
|
||||
$view['page[create]'] = 1;
|
||||
$view['page[title]'] = $this->randomMachineName(16);
|
||||
$view['page[path]'] = $this->randomMachineName(16);
|
||||
$view['block[create]'] = 1;
|
||||
$view['block[title]'] = $this->randomMachineName(16);
|
||||
$this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
|
||||
|
||||
// Revert the title of the block to the default ones, but submit some new
|
||||
// values to be sure that the new value is not stored.
|
||||
$edit = [];
|
||||
$edit['title'] = $new_block_title = $this->randomMachineName();
|
||||
$edit['override[dropdown]'] = 'default_revert';
|
||||
|
||||
$this->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/block_1/title", $edit, t('Apply'));
|
||||
$this->drupalPostForm("admin/structure/views/view/{$view['id']}/edit/block_1", [], t('Save'));
|
||||
$this->assertText($view['page[title]']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
use Drupal\views\Views;
|
||||
use Drupal\views\Entity\View;
|
||||
|
||||
/**
|
||||
* Tests query plugins.
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class QueryTest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_view'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function viewsData() {
|
||||
$data = parent::viewsData();
|
||||
$data['views_test_data']['table']['base']['query_id'] = 'query_test';
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests query plugins settings.
|
||||
*/
|
||||
public function testQueryUI() {
|
||||
$view = View::load('test_view');
|
||||
$display = &$view->getDisplay('default');
|
||||
$display['display_options']['query'] = ['type' => 'query_test'];
|
||||
$view->save();
|
||||
|
||||
// Save some query settings.
|
||||
$query_settings_path = "admin/structure/views/nojs/display/test_view/default/query";
|
||||
$random_value = $this->randomMachineName();
|
||||
$this->drupalPostForm($query_settings_path, ['query[options][test_setting]' => $random_value], t('Apply'));
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
|
||||
// Check that the settings are saved into the view itself.
|
||||
$view = Views::getView('test_view');
|
||||
$view->initDisplay();
|
||||
$view->initQuery();
|
||||
$this->assertEqual($random_value, $view->query->options['test_setting'], 'Query settings got saved');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the reordering of fields via AJAX.
|
||||
*
|
||||
* @group views_ui
|
||||
* @see \Drupal\views_ui\Form\Ajax\Rearrange
|
||||
*/
|
||||
class RearrangeFieldsTest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_view'];
|
||||
|
||||
/**
|
||||
* Gets the fields from the View.
|
||||
*/
|
||||
protected function getViewFields($view_name = 'test_view', $display_id = 'default') {
|
||||
$view = Views::getView($view_name);
|
||||
$view->setDisplay($display_id);
|
||||
$fields = [];
|
||||
foreach ($view->displayHandlers->get('default')->getHandlers('field') as $field => $handler) {
|
||||
$fields[] = $field;
|
||||
}
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the fields are in the correct order.
|
||||
*
|
||||
* @param $view_name
|
||||
* The name of the view.
|
||||
* @param $fields
|
||||
* Array of field names.
|
||||
*/
|
||||
protected function assertFieldOrder($view_name, $fields) {
|
||||
$this->drupalGet('admin/structure/views/nojs/rearrange/' . $view_name . '/default/field');
|
||||
|
||||
foreach ($fields as $idx => $field) {
|
||||
$this->assertFieldById('edit-fields-' . $field . '-weight', $idx + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests field sorting.
|
||||
*/
|
||||
public function testRearrangeFields() {
|
||||
$view_name = 'test_view';
|
||||
|
||||
// Checks that the order on the rearrange form matches the creation order.
|
||||
$this->assertFieldOrder($view_name, $this->getViewFields($view_name));
|
||||
|
||||
// Checks that a field is not deleted if a value is not passed back.
|
||||
$fields = [];
|
||||
$this->drupalPostForm('admin/structure/views/nojs/rearrange/' . $view_name . '/default/field', $fields, t('Apply'));
|
||||
$this->assertFieldOrder($view_name, $this->getViewFields($view_name));
|
||||
|
||||
// Checks that revers the new field order is respected.
|
||||
$reversedFields = array_reverse($this->getViewFields($view_name));
|
||||
$fields = [];
|
||||
foreach ($reversedFields as $delta => $field) {
|
||||
$fields['fields[' . $field . '][weight]'] = $delta;
|
||||
}
|
||||
$this->drupalPostForm('admin/structure/views/nojs/rearrange/' . $view_name . '/default/field', $fields, t('Apply'));
|
||||
$this->assertFieldOrder($view_name, $reversedFields);
|
||||
|
||||
// Checks that there is a remove link for each field.
|
||||
$this->assertEqual(count($this->cssSelect('a.views-remove-link')), count($fields));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
/**
|
||||
* Tests the redirecting after saving a views.
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class RedirectTest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_view', 'test_redirect_view'];
|
||||
|
||||
/**
|
||||
* Tests the redirecting.
|
||||
*/
|
||||
public function testRedirect() {
|
||||
$view_name = 'test_view';
|
||||
|
||||
$random_destination = $this->randomMachineName();
|
||||
$edit_path = "admin/structure/views/view/$view_name/edit";
|
||||
|
||||
$this->drupalPostForm($edit_path, [], t('Save'), ['query' => ['destination' => $random_destination]]);
|
||||
$this->assertUrl($random_destination, [], 'Make sure the user got redirected to the expected page defined in the destination.');
|
||||
|
||||
// Setup a view with a certain page display path. If you change the path
|
||||
// but have the old url in the destination the user should be redirected to
|
||||
// the new path.
|
||||
$view_name = 'test_redirect_view';
|
||||
$new_path = $this->randomMachineName();
|
||||
|
||||
$edit_path = "admin/structure/views/view/$view_name/edit";
|
||||
$path_edit_path = "admin/structure/views/nojs/display/$view_name/page_1/path";
|
||||
|
||||
$this->drupalPostForm($path_edit_path, ['path' => $new_path], t('Apply'));
|
||||
$this->drupalPostForm($edit_path, [], t('Save'), ['query' => ['destination' => 'test-redirect-view']]);
|
||||
$this->assertUrl($new_path, [], 'Make sure the user got redirected to the expected page after changing the URL of a page display.');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
||||
/**
|
||||
* Tests the Views fields report page.
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class ReportFieldsTest extends UITestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $testViews = ['test_field_field_test'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['entity_test'];
|
||||
|
||||
/**
|
||||
* Tests the Views fields report page.
|
||||
*/
|
||||
public function testReportFields() {
|
||||
$this->drupalGet('admin/reports/fields/views-fields');
|
||||
$this->assertRaw('Used in views', 'Title appears correctly');
|
||||
$this->assertRaw('No fields have been used in views yet.', 'No results message appears correctly.');
|
||||
|
||||
// Set up the field_test field.
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => 'field_test',
|
||||
'type' => 'integer',
|
||||
'entity_type' => 'entity_test',
|
||||
]);
|
||||
$field_storage->save();
|
||||
|
||||
$field = FieldConfig::create([
|
||||
'field_name' => 'field_test',
|
||||
'entity_type' => 'entity_test',
|
||||
'bundle' => 'entity_test',
|
||||
]);
|
||||
$field->save();
|
||||
|
||||
$this->drupalGet('admin/reports/fields/views-fields');
|
||||
// Assert that the newly created field appears in the overview.
|
||||
$this->assertRaw('<td>field_test</td>', 'Field name appears correctly');
|
||||
$this->assertRaw('>test_field_field_test</a>', 'View name appears correctly');
|
||||
$this->assertRaw('Used in views', 'Title appears correctly');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
/**
|
||||
* Tests existence of the views plugin report.
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class ReportTest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['views', 'views_ui'];
|
||||
|
||||
/**
|
||||
* Stores an admin user used by the different tests.
|
||||
*
|
||||
* @var \Drupal\user\User
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
/**
|
||||
* Tests the existence of the views plugin report.
|
||||
*/
|
||||
public function testReport() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Test the report page.
|
||||
$this->drupalGet('admin/reports/views-plugins');
|
||||
$this->assertResponse(200, "Views report page exists");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
/**
|
||||
* Tests all ui related settings under admin/structure/views/settings.
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class SettingsTest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Stores an admin user used by the different tests.
|
||||
*
|
||||
* @var \Drupal\user\User
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
$this->drupalPlaceBlock('local_tasks_block');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the settings for the edit ui.
|
||||
*/
|
||||
public function testEditUI() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Test the settings tab exists.
|
||||
$this->drupalGet('admin/structure/views');
|
||||
$this->assertLinkByHref('admin/structure/views/settings');
|
||||
|
||||
// Test the confirmation message.
|
||||
$this->drupalPostForm('admin/structure/views/settings', [], t('Save configuration'));
|
||||
$this->assertText(t('The configuration options have been saved.'));
|
||||
|
||||
// Configure to always show the master display.
|
||||
$edit = [
|
||||
'ui_show_master_display' => TRUE,
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/views/settings', $edit, t('Save configuration'));
|
||||
|
||||
$view = [];
|
||||
$view['label'] = $this->randomMachineName(16);
|
||||
$view['id'] = strtolower($this->randomMachineName(16));
|
||||
$view['description'] = $this->randomMachineName(16);
|
||||
$view['page[create]'] = TRUE;
|
||||
$view['page[title]'] = $this->randomMachineName(16);
|
||||
$view['page[path]'] = $this->randomMachineName(16);
|
||||
$this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
|
||||
|
||||
// Configure to not always show the master display.
|
||||
// If you have a view without a page or block the master display should be
|
||||
// still shown.
|
||||
$edit = [
|
||||
'ui_show_master_display' => FALSE,
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/views/settings', $edit, t('Save configuration'));
|
||||
|
||||
$view['page[create]'] = FALSE;
|
||||
$this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
|
||||
|
||||
// Create a view with an additional display, so master should be hidden.
|
||||
$view['page[create]'] = TRUE;
|
||||
$view['id'] = strtolower($this->randomMachineName());
|
||||
$this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
|
||||
|
||||
$this->assertNoLink(t('Master'));
|
||||
|
||||
// Configure to always show the advanced settings.
|
||||
// @todo It doesn't seem to be a way to test this as this works just on js.
|
||||
|
||||
// Configure to show the embeddable display.
|
||||
$edit = [
|
||||
'ui_show_display_embed' => TRUE,
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/views/settings', $edit, t('Save configuration'));
|
||||
|
||||
$view['id'] = strtolower($this->randomMachineName());
|
||||
$this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
|
||||
$this->assertFieldById('edit-displays-top-add-display-embed', NULL);
|
||||
|
||||
$edit = [
|
||||
'ui_show_display_embed' => FALSE,
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/views/settings', $edit, t('Save configuration'));
|
||||
|
||||
$this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
|
||||
$this->assertNoFieldById('edit-displays-top-add-display-embed');
|
||||
|
||||
// Configure to hide/show the sql at the preview.
|
||||
$edit = [
|
||||
'ui_show_sql_query_enabled' => FALSE,
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/views/settings', $edit, t('Save configuration'));
|
||||
|
||||
$view['id'] = strtolower($this->randomMachineName());
|
||||
$this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
|
||||
|
||||
$this->drupalPostForm(NULL, [], t('Update preview'));
|
||||
$xpath = $this->xpath('//div[@class="views-query-info"]/pre');
|
||||
$this->assertEqual(count($xpath), 0, 'The views sql is hidden.');
|
||||
|
||||
$edit = [
|
||||
'ui_show_sql_query_enabled' => TRUE,
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/views/settings', $edit, t('Save configuration'));
|
||||
|
||||
$view['id'] = strtolower($this->randomMachineName());
|
||||
$this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
|
||||
|
||||
$this->drupalPostForm(NULL, [], t('Update preview'));
|
||||
$xpath = $this->xpath('//div[@class="views-query-info"]//pre');
|
||||
$this->assertEqual(count($xpath), 1, 'The views sql is shown.');
|
||||
$this->assertFalse(strpos($xpath[0]->getText(), 'db_condition_placeholder') !== FALSE, 'No placeholders are shown in the views sql.');
|
||||
$this->assertTrue(strpos($xpath[0]->getText(), "node_field_data.status = '1'") !== FALSE, 'The placeholders in the views sql is replace by the actual value.');
|
||||
|
||||
// Test the advanced settings form.
|
||||
|
||||
// Test the confirmation message.
|
||||
$this->drupalPostForm('admin/structure/views/settings/advanced', [], t('Save configuration'));
|
||||
$this->assertText(t('The configuration options have been saved.'));
|
||||
|
||||
$edit = [
|
||||
'skip_cache' => TRUE,
|
||||
'sql_signature' => TRUE,
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/views/settings/advanced', $edit, t('Save configuration'));
|
||||
|
||||
$this->assertFieldChecked('edit-skip-cache', 'The skip_cache option is checked.');
|
||||
$this->assertFieldChecked('edit-sql-signature', 'The sql_signature option is checked.');
|
||||
|
||||
// Test the "Clear Views' cache" button.
|
||||
$this->drupalPostForm('admin/structure/views/settings/advanced', [], t("Clear Views' cache"));
|
||||
$this->assertText(t('The cache has been cleared.'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the UI of storage properties of views.
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class StorageTest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_view'];
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['views_ui', 'language'];
|
||||
|
||||
/**
|
||||
* Tests changing label, description and tag.
|
||||
*
|
||||
* @see views_ui_edit_details_form
|
||||
*/
|
||||
public function testDetails() {
|
||||
$view_name = 'test_view';
|
||||
|
||||
ConfigurableLanguage::createFromLangcode('fr')->save();
|
||||
|
||||
$edit = [
|
||||
'label' => $this->randomMachineName(),
|
||||
'tag' => $this->randomMachineName(),
|
||||
'description' => $this->randomMachineName(30),
|
||||
'langcode' => 'fr',
|
||||
];
|
||||
|
||||
$this->drupalPostForm("admin/structure/views/nojs/edit-details/$view_name/default", $edit, t('Apply'));
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
|
||||
$view = Views::getView($view_name);
|
||||
|
||||
foreach (['label', 'tag', 'description', 'langcode'] as $property) {
|
||||
$this->assertEqual($view->storage->get($property), $edit[$property], format_string('Make sure the property @property got probably saved.', ['@property' => $property]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the UI of views when using the table style.
|
||||
*
|
||||
* @group views_ui
|
||||
* @see \Drupal\views\Plugin\views\style\Table.
|
||||
*/
|
||||
class StyleTableTest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Tests created a table style view.
|
||||
*/
|
||||
public function testWizard() {
|
||||
// Create a new view and check that the first field has a label.
|
||||
$view = [];
|
||||
$view['label'] = $this->randomMachineName(16);
|
||||
$view['id'] = strtolower($this->randomMachineName(16));
|
||||
$view['show[wizard_key]'] = 'node';
|
||||
$view['page[create]'] = TRUE;
|
||||
$view['page[style][style_plugin]'] = 'table';
|
||||
$view['page[title]'] = $this->randomMachineName(16);
|
||||
$view['page[path]'] = $view['id'];
|
||||
$this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
|
||||
|
||||
$view = Views::getView($view['id']);
|
||||
$view->initHandlers();
|
||||
$this->assertEqual($view->field['title']->options['label'], 'Title', 'The field label for table styles is not empty.');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the UI of style plugins.
|
||||
*
|
||||
* @group views_ui
|
||||
* @see \Drupal\views_test_data\Plugin\views\style\StyleTest.
|
||||
*/
|
||||
class StyleUITest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_view'];
|
||||
|
||||
/**
|
||||
* Tests changing the style plugin and changing some options of a style.
|
||||
*/
|
||||
public function testStyleUI() {
|
||||
$view_name = 'test_view';
|
||||
$view_edit_url = "admin/structure/views/view/$view_name/edit";
|
||||
|
||||
$style_plugin_url = "admin/structure/views/nojs/display/$view_name/default/style";
|
||||
$style_options_url = "admin/structure/views/nojs/display/$view_name/default/style_options";
|
||||
|
||||
$this->drupalGet($style_plugin_url);
|
||||
$this->assertFieldByName('style[type]', 'default', 'The default style plugin selected in the UI should be unformatted list.');
|
||||
|
||||
$edit = [
|
||||
'style[type]' => 'test_style'
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
$this->assertFieldByName('style_options[test_option]', NULL, 'Make sure the custom settings form from the test plugin appears.');
|
||||
$random_name = $this->randomMachineName();
|
||||
$edit = [
|
||||
'style_options[test_option]' => $random_name
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
$this->drupalGet($style_options_url);
|
||||
$this->assertFieldByName('style_options[test_option]', $random_name, 'Make sure the custom settings form field has the expected value stored.');
|
||||
|
||||
$this->drupalPostForm($view_edit_url, [], t('Save'));
|
||||
$this->assertLink(t('Test style plugin'), 0, 'Make sure the test style plugin is shown in the UI');
|
||||
|
||||
$view = Views::getView($view_name);
|
||||
$view->initDisplay();
|
||||
$style = $view->display_handler->getOption('style');
|
||||
$this->assertEqual($style['type'], 'test_style', 'Make sure that the test_style got saved as used style plugin.');
|
||||
$this->assertEqual($style['options']['test_option'], $random_name, 'Make sure that the custom settings field got saved as expected.');
|
||||
|
||||
// Test that fields are working correctly in the UI for style plugins when
|
||||
// a field row plugin is selected.
|
||||
$this->drupalPostForm("admin/structure/views/view/$view_name/edit", [], 'Add Page');
|
||||
$this->drupalPostForm("admin/structure/views/nojs/display/$view_name/page_1/row", ['row[type]' => 'fields'], t('Apply'));
|
||||
// If fields are being used this text will not be shown.
|
||||
$this->assertNoText(t('The selected style or row format does not use fields.'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\views\Entity\View;
|
||||
|
||||
/**
|
||||
* Tests the token display for the TokenizeAreaPluginBase UI.
|
||||
*
|
||||
* @see \Drupal\views\Plugin\views\area\Entity
|
||||
* @group views_ui
|
||||
*/
|
||||
class TokenizeAreaUITest extends UITestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['entity_test'];
|
||||
|
||||
/**
|
||||
* Test that the right tokens are shown as available for replacement.
|
||||
*/
|
||||
public function testTokenUI() {
|
||||
$entity_test = EntityTest::create(['bundle' => 'entity_test']);
|
||||
$entity_test->save();
|
||||
|
||||
$default = $this->randomView([]);
|
||||
$id = $default['id'];
|
||||
$view = View::load($id);
|
||||
|
||||
$this->drupalGet($view->toUrl('edit-form'));
|
||||
|
||||
// Add a global NULL argument to the view for testing argument tokens.
|
||||
$this->drupalPostForm("admin/structure/views/nojs/add-handler/$id/page_1/argument", ['name[views.null]' => 1], 'Add and configure contextual filters');
|
||||
$this->drupalPostForm(NULL, [], 'Apply');
|
||||
|
||||
$this->drupalPostForm("admin/structure/views/nojs/add-handler/$id/page_1/header", ['name[views.area]' => 'views.area'], 'Add and configure header');
|
||||
// Test that field tokens are shown.
|
||||
$this->assertText('{{ title }} == Content: Title');
|
||||
// Test that argument tokens are shown.
|
||||
$this->assertText('{{ arguments.null }} == Global: Null title');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
|
||||
/**
|
||||
* Tests that translated strings in views UI don't override original strings.
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class TranslatedViewTest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = [
|
||||
'config_translation',
|
||||
'views_ui',
|
||||
];
|
||||
|
||||
/**
|
||||
* Languages to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $langcodes = [
|
||||
'fr',
|
||||
];
|
||||
|
||||
/**
|
||||
* Administrator user for tests.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$permissions = [
|
||||
'administer site configuration',
|
||||
'administer views',
|
||||
'translate configuration',
|
||||
'translate interface',
|
||||
];
|
||||
|
||||
// Create and log in user.
|
||||
$this->adminUser = $this->drupalCreateUser($permissions);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Add languages.
|
||||
foreach ($this->langcodes as $langcode) {
|
||||
ConfigurableLanguage::createFromLangcode($langcode)->save();
|
||||
}
|
||||
$this->resetAll();
|
||||
$this->rebuildContainer();
|
||||
}
|
||||
|
||||
public function testTranslatedStrings() {
|
||||
$translation_url = 'admin/structure/views/view/files/translate/fr/add';
|
||||
$edit_url = 'admin/structure/views/view/files';
|
||||
|
||||
// Check origial string.
|
||||
$this->drupalGet($edit_url);
|
||||
$this->assertTitle('Files (File) | Drupal');
|
||||
|
||||
// Translate the label of the view.
|
||||
$this->drupalGet($translation_url);
|
||||
$edit = [
|
||||
'translation[config_names][views.view.files][label]' => 'Fichiers',
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save translation'));
|
||||
|
||||
// Check if the label is translated.
|
||||
$this->drupalGet($edit_url, ['language' => \Drupal::languageManager()->getLanguage('fr')]);
|
||||
$this->assertTitle('Files (File) | Drupal');
|
||||
$this->assertNoText('Fichiers');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
|
||||
/**
|
||||
* Provides a base class for testing the Views UI.
|
||||
*/
|
||||
abstract class UITestBase extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* An admin user with the 'administer views' permission.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
/**
|
||||
* An admin user with administrative permissions for views, blocks, and nodes.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $fullAdminUser;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['node', 'views_ui', 'block', 'taxonomy'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
|
||||
$this->adminUser = $this->drupalCreateUser(['administer views']);
|
||||
|
||||
$this->fullAdminUser = $this->drupalCreateUser(['administer views',
|
||||
'administer blocks',
|
||||
'bypass node access',
|
||||
'access user profiles',
|
||||
'view all revisions',
|
||||
'administer permissions',
|
||||
]);
|
||||
$this->drupalLogin($this->fullAdminUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* A helper method which creates a random view.
|
||||
*/
|
||||
public function randomView(array $view = []) {
|
||||
// Create a new view in the UI.
|
||||
$default = [];
|
||||
$default['label'] = $this->randomMachineName(16);
|
||||
$default['id'] = strtolower($this->randomMachineName(16));
|
||||
$default['description'] = $this->randomMachineName(16);
|
||||
$default['page[create]'] = TRUE;
|
||||
$default['page[path]'] = $default['id'];
|
||||
|
||||
$view += $default;
|
||||
|
||||
$this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function drupalGet($path, array $options = [], array $headers = []) {
|
||||
$url = $this->buildUrl($path, $options);
|
||||
|
||||
// Ensure that each nojs page is accessible via ajax as well.
|
||||
if (strpos($url, 'nojs') !== FALSE) {
|
||||
$url = str_replace('nojs', 'ajax', $url);
|
||||
$result = $this->drupalGet($url, $options);
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
$this->assertEquals('application/json', $this->getSession()->getResponseHeader('Content-Type'));
|
||||
$this->assertTrue(json_decode($result), 'Ensure that the AJAX request returned valid content.');
|
||||
}
|
||||
|
||||
return parent::drupalGet($path, $options, $headers);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
/**
|
||||
* Tests covering Preview of unsaved Views.
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class UnsavedPreviewTest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['content'];
|
||||
|
||||
/**
|
||||
* An admin user with the 'administer views' permission.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['node', 'views_ui'];
|
||||
|
||||
/**
|
||||
* Sets up a Drupal site for running functional and integration tests.
|
||||
*/
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp(FALSE);
|
||||
|
||||
$this->adminUser = $this->drupalCreateUser(['administer views']);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests previews of unsaved new page displays.
|
||||
*/
|
||||
public function testUnsavedPageDisplayPreview() {
|
||||
$this->drupalCreateContentType(['type' => 'page']);
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$this->drupalCreateNode();
|
||||
}
|
||||
|
||||
$this->drupalGet('admin/structure/views/view/content');
|
||||
$this->assertResponse(200);
|
||||
|
||||
$this->drupalPostForm(NULL, [], t('Add Page'));
|
||||
$this->assertResponse(200);
|
||||
|
||||
$this->drupalGet('admin/structure/views/nojs/display/content/page_2/path');
|
||||
$this->assertResponse(200);
|
||||
|
||||
$this->drupalPostForm(NULL, ['path' => 'foobarbaz'], t('Apply'));
|
||||
$this->assertResponse(200);
|
||||
|
||||
$this->drupalPostForm(NULL, [], t('Update preview'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertText(t('This display has no path'));
|
||||
|
||||
$this->drupalGet('admin/structure/views/view/content/edit/page_2');
|
||||
$this->assertResponse(200);
|
||||
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
$this->assertResponse(200);
|
||||
|
||||
$this->drupalPostForm(NULL, [], t('Update preview'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertLinkByHref('foobarbaz');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
use Drupal\views\Entity\View;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the views list.
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class ViewsListTest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['block', 'views_ui'];
|
||||
|
||||
/**
|
||||
* A user with permission to administer views.
|
||||
*
|
||||
* @var \Drupal\user\Entity\User
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->drupalPlaceBlock('local_tasks_block');
|
||||
$this->drupalPlaceBlock('local_actions_block');
|
||||
$this->adminUser = $this->drupalCreateUser(['administer views']);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the views list does not use a pager.
|
||||
*/
|
||||
public function testViewsListLimit() {
|
||||
// Check if we can access the main views admin page.
|
||||
$this->drupalGet('admin/structure/views');
|
||||
$this->assertResponse(200);
|
||||
$this->assertLink(t('Add view'));
|
||||
|
||||
// Count default views to be subtracted from the limit.
|
||||
$views = count(Views::getEnabledViews());
|
||||
|
||||
// Create multiples views.
|
||||
$limit = 51;
|
||||
$values = $this->config('views.view.test_view_storage')->get();
|
||||
for ($i = 1; $i <= $limit - $views; $i++) {
|
||||
$values['id'] = 'test_view_storage_new' . $i;
|
||||
unset($values['uuid']);
|
||||
$created = View::create($values);
|
||||
$created->save();
|
||||
}
|
||||
$this->drupalGet('admin/structure/views');
|
||||
|
||||
// Check that all the rows are listed.
|
||||
$this->assertEqual(count($this->xpath('//tbody/tr[contains(@class,"views-ui-list-enabled")]')), $limit);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
use Drupal\Tests\views\Functional\Wizard\WizardTestBase;
|
||||
|
||||
/**
|
||||
* Tests the wizard.
|
||||
*
|
||||
* @group views_ui
|
||||
* @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 {
|
||||
|
||||
/**
|
||||
* Tests filling in the wizard with really long strings.
|
||||
*/
|
||||
public function testWizardFieldLength() {
|
||||
$view = [];
|
||||
$view['label'] = $this->randomMachineName(256);
|
||||
$view['id'] = strtolower($this->randomMachineName(129));
|
||||
$view['page[create]'] = TRUE;
|
||||
$view['page[path]'] = $this->randomMachineName(255);
|
||||
$view['page[title]'] = $this->randomMachineName(256);
|
||||
$view['page[feed]'] = TRUE;
|
||||
$view['page[feed_properties][path]'] = $this->randomMachineName(255);
|
||||
$view['block[create]'] = TRUE;
|
||||
$view['block[title]'] = $this->randomMachineName(256);
|
||||
$view['rest_export[create]'] = TRUE;
|
||||
$view['rest_export[path]'] = $this->randomMachineName(255);
|
||||
|
||||
$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.');
|
||||
$this->assertText('REST export path cannot be longer than 254 characters but is currently 255 characters long.');
|
||||
|
||||
$view['label'] = $this->randomMachineName(255);
|
||||
$view['id'] = strtolower($this->randomMachineName(128));
|
||||
$view['page[create]'] = TRUE;
|
||||
$view['page[path]'] = $this->randomMachineName(254);
|
||||
$view['page[title]'] = $this->randomMachineName(255);
|
||||
$view['page[feed]'] = TRUE;
|
||||
$view['page[feed_properties][path]'] = $this->randomMachineName(254);
|
||||
$view['block[create]'] = TRUE;
|
||||
$view['block[title]'] = $this->randomMachineName(255);
|
||||
$view['rest_export[create]'] = TRUE;
|
||||
$view['rest_export[path]'] = $this->randomMachineName(254);
|
||||
|
||||
$this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
|
||||
$this->assertUrl('admin/structure/views/view/' . $view['id'], [], '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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\Functional;
|
||||
|
||||
/**
|
||||
* Tests the Xss vulnerability.
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class XssTest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['node', 'user', 'views_ui', 'views_ui_test'];
|
||||
|
||||
public function testViewsUi() {
|
||||
$this->drupalGet('admin/structure/views/view/sa_contrib_2013_035');
|
||||
$this->assertEscaped('<marquee>test</marquee>', 'Field admin label is properly escaped.');
|
||||
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/sa_contrib_2013_035/page_1/header/area');
|
||||
$this->assertEscaped('{{ title }} == <marquee>test</marquee>', 'Token label is properly escaped.');
|
||||
$this->assertEscaped('{{ title_1 }} == <script>alert("XSS")</script>', 'Token label is properly escaped.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the admin UI for double escaping.
|
||||
*/
|
||||
public function testNoDoubleEscaping() {
|
||||
$this->drupalGet('admin/structure/views');
|
||||
$this->assertNoEscaped('<');
|
||||
|
||||
$this->drupalGet('admin/structure/views/view/sa_contrib_2013_035');
|
||||
$this->assertNoEscaped('<');
|
||||
|
||||
$this->drupalGet('admin/structure/views/nojs/handler/sa_contrib_2013_035/page_1/header/area');
|
||||
$this->assertNoEscaped('<');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\FunctionalJavascript;
|
||||
|
||||
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
|
||||
use Drupal\simpletest\NodeCreationTrait;
|
||||
use Drupal\views\Entity\View;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
|
||||
/**
|
||||
* Tests the display UI.
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class DisplayTest extends JavascriptTestBase {
|
||||
|
||||
use NodeCreationTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'block',
|
||||
'contextual',
|
||||
'node',
|
||||
'views',
|
||||
'views_ui',
|
||||
'views_test_config',
|
||||
];
|
||||
|
||||
public static $testViews = ['test_content_ajax', 'test_display'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
ViewTestData::createTestViews(self::class, ['views_test_config']);
|
||||
|
||||
$admin_user = $this->drupalCreateUser([
|
||||
'administer site configuration',
|
||||
'administer views',
|
||||
'administer nodes',
|
||||
'access content overview',
|
||||
'access contextual links',
|
||||
]);
|
||||
|
||||
// Disable automatic live preview to make the sequence of calls clearer.
|
||||
\Drupal::configFactory()->getEditable('views.settings')->set('ui.always_live_preview', FALSE)->save();
|
||||
$this->drupalLogin($admin_user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests adding a display.
|
||||
*/
|
||||
public function testAddDisplay() {
|
||||
$this->drupalGet('admin/structure/views/view/test_content_ajax');
|
||||
$page = $this->getSession()->getPage();
|
||||
|
||||
$page->find('css', '#views-display-menu-tabs .add')->click();
|
||||
|
||||
// Wait for the animation to complete.
|
||||
$this->assertSession()->assertWaitOnAjaxRequest();
|
||||
|
||||
// Add the diplay.
|
||||
$page->find('css', '#edit-displays-top-add-display-block')->click();
|
||||
|
||||
$element = $page->findById('views-display-menu-tabs')->findLink('Block');
|
||||
$this->assertNotEmpty($element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests contextual links on Views page displays.
|
||||
*/
|
||||
public function testPageContextualLinks() {
|
||||
$view = View::load('test_display');
|
||||
$view->enable()->save();
|
||||
$this->container->get('router.builder')->rebuildIfNeeded();
|
||||
|
||||
// Create node so the view has content and the contextual area is higher
|
||||
// than 0 pixels.
|
||||
$this->drupalCreateContentType(['type' => 'page']);
|
||||
$this->createNode();
|
||||
|
||||
// When no "main content" block is placed, we find a contextual link
|
||||
// placeholder for editing just the view.
|
||||
$this->drupalGet('test-display');
|
||||
$page = $this->getSession()->getPage();
|
||||
$this->assertSession()->assertWaitOnAjaxRequest();
|
||||
|
||||
$selector = '.view-test-display';
|
||||
$this->toggleContextualTriggerVisibility($selector);
|
||||
|
||||
$element = $this->getSession()->getPage()->find('css', $selector);
|
||||
$element->find('css', '.contextual button')->press();
|
||||
|
||||
$contextual_container_id = 'entity.view.edit_form:view=test_display:location=page&name=test_display&display_id=page_1&langcode=en';
|
||||
$contextual_container = $page->find('css', '[data-contextual-id="' . $contextual_container_id . '"]');
|
||||
$this->assertNotEmpty($contextual_container);
|
||||
|
||||
$edit_link = $contextual_container->findLink('Edit view');
|
||||
$this->assertNotEmpty($edit_link);
|
||||
|
||||
// When a "main content" is placed, we still find a contextual link
|
||||
// placeholder for editing just the view (not the main content block).
|
||||
// @see system_block_view_system_main_block_alter()
|
||||
$this->drupalPlaceBlock('system_main_block', ['id' => 'main_content']);
|
||||
$contextual_container = $page->find('css', '[data-contextual-id="' . $contextual_container_id . '"]');
|
||||
$this->assertNotEmpty($contextual_container);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the visibility of a contextual trigger.
|
||||
*
|
||||
* @param string $selector
|
||||
* The selector for the element that contains the contextual Rink.
|
||||
*/
|
||||
protected function toggleContextualTriggerVisibility($selector) {
|
||||
// Hovering over the element itself with should be enough, but does not
|
||||
// work. Manually remove the visually-hidden class.
|
||||
$this->getSession()->executeScript("jQuery('{$selector} .contextual .trigger').toggleClass('visually-hidden');");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\FunctionalJavascript;
|
||||
|
||||
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
|
||||
|
||||
/**
|
||||
* Tests the View UI filter criteria group dialog.
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class FilterCriteriaTest extends JavascriptTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['node', 'views', 'views_ui'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$admin_user = $this->drupalCreateUser([
|
||||
'administer site configuration',
|
||||
'administer views',
|
||||
'administer nodes',
|
||||
'access content overview',
|
||||
]);
|
||||
|
||||
// Disable automatic live preview to make the sequence of calls clearer.
|
||||
\Drupal::configFactory()->getEditable('views.settings')->set('ui.always_live_preview', FALSE)->save();
|
||||
$this->drupalLogin($admin_user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests dialog for filter criteria.
|
||||
*/
|
||||
public function testFilterCriteriaDialog() {
|
||||
$this->drupalGet('admin/structure/views/view/content_recent');
|
||||
$assert_session = $this->assertSession();
|
||||
$page = $this->getSession()->getPage();
|
||||
|
||||
// Use the 'And/Or Rearrange' link for fields to open a dialog.
|
||||
$dropbutton = $page->find('css', '.views-ui-display-tab-bucket.filter .dropbutton-toggle button');
|
||||
$dropbutton->click();
|
||||
$add_link = $page->findById('views-rearrange-filter');
|
||||
$this->assertTrue($add_link->isVisible(), 'And/Or Rearrange button found.');
|
||||
$add_link->click();
|
||||
$assert_session->assertWaitOnAjaxRequest();
|
||||
|
||||
// Add a new filter group.
|
||||
$create_new_filter_group = $page->findById('views-add-group-link');
|
||||
$this->assertTrue($create_new_filter_group->isVisible(), 'Add group link found.');
|
||||
$create_new_filter_group->click();
|
||||
$assert_session->assertWaitOnAjaxRequest();
|
||||
|
||||
// Assert the existence of the new filter group by checking the remove group
|
||||
// link.
|
||||
$remove_link = $page->findLink('Remove group');
|
||||
$this->assertTrue($remove_link->isVisible(), 'New group found.');
|
||||
|
||||
// Remove the group again and assert the group is not present anymore.
|
||||
$remove_link->click();
|
||||
$assert_session->assertWaitOnAjaxRequest();
|
||||
$remove_link = $page->findLink('Remove group');
|
||||
$this->assertEmpty($remove_link, 'Remove button not available');
|
||||
|
||||
// Checks that the admin summary is not double escaped.
|
||||
$this->drupalGet('admin/structure/views/view/who_s_online');
|
||||
$page = $this->getSession()->getPage();
|
||||
$this->assertNotNull($page->findLink('User: Last access (>= -15 minutes)'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views_ui\FunctionalJavascript;
|
||||
|
||||
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
|
||||
|
||||
/**
|
||||
* Tests the JavaScript filtering of options in add handler form.
|
||||
*
|
||||
* @group views_ui
|
||||
*/
|
||||
class FilterOptionsTest extends JavascriptTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['node', 'views', 'views_ui', 'views_ui_test_field'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$admin_user = $this->drupalCreateUser([
|
||||
'administer views',
|
||||
]);
|
||||
$this->drupalLogin($admin_user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests filtering options in the 'Add fields' dialog.
|
||||
*/
|
||||
public function testFilterOptionsAddFields() {
|
||||
$this->drupalGet('admin/structure/views/view/content');
|
||||
|
||||
$session = $this->getSession();
|
||||
$web_assert = $this->assertSession();
|
||||
$page = $session->getPage();
|
||||
|
||||
// Open the dialog.
|
||||
$page->clickLink('views-add-field');
|
||||
|
||||
// Wait for the popup to open and the search field to be available.
|
||||
$options_search = $web_assert->waitForField('override[controls][options_search]');
|
||||
|
||||
// Test that the both special fields are visible.
|
||||
$this->assertTrue($page->findField('name[views.views_test_field_1]')->isVisible());
|
||||
$this->assertTrue($page->findField('name[views.views_test_field_2]')->isVisible());
|
||||
|
||||
// Test the ".title" field in search.
|
||||
$options_search->setValue('FIELD_1_TITLE');
|
||||
$page->waitFor(10, function () use ($page) {
|
||||
return !$page->findField('name[views.views_test_field_2]')->isVisible();
|
||||
});
|
||||
$this->assertTrue($page->findField('name[views.views_test_field_1]')->isVisible());
|
||||
$this->assertFalse($page->findField('name[views.views_test_field_2]')->isVisible());
|
||||
|
||||
// Test the ".description" field in search.
|
||||
$options_search->setValue('FIELD_2_DESCRIPTION');
|
||||
$page->waitFor(10, function () use ($page) {
|
||||
return !$page->findField('name[views.views_test_field_1]')->isVisible();
|
||||
});
|
||||
$this->assertTrue($page->findField('name[views.views_test_field_2]')->isVisible());
|
||||
$this->assertFalse($page->findField('name[views.views_test_field_1]')->isVisible());
|
||||
|
||||
// Test the "label" field not in search.
|
||||
$options_search->setValue('FIELD_1_LABEL');
|
||||
$page->waitFor(10, function () use ($page) {
|
||||
return !$page->findField('name[views.views_test_field_2]')->isVisible();
|
||||
});
|
||||
$this->assertFalse($page->findField('name[views.views_test_field_2]')->isVisible());
|
||||
$this->assertFalse($page->findField('name[views.views_test_field_1]')->isVisible());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,12 +39,12 @@ class LibraryCachingTest extends JavascriptTestBase {
|
||||
$add_link = $page->findById('views-add-field');
|
||||
$this->assertTrue($add_link->isVisible(), 'Add fields button found.');
|
||||
$add_link->click();
|
||||
$this->getSession()->wait(5000, "jQuery('.ui-dialog-titlebar').length > 0");
|
||||
$this->assertJsCondition("jQuery('.ui-dialog-titlebar').length > 0");
|
||||
// Close the dialog and open it again. No no libraries will be loaded, but a
|
||||
// cache entry will be made for not loading any libraries.
|
||||
$page->pressButton('Close');
|
||||
$add_link->click();
|
||||
$this->getSession()->wait(5000, "jQuery('.ui-dialog-titlebar').length > 0");
|
||||
$this->assertJsCondition("jQuery('.ui-dialog-titlebar').length > 0");
|
||||
$page->pressButton('Close');
|
||||
|
||||
// Reload the page.
|
||||
@@ -55,14 +55,14 @@ class LibraryCachingTest extends JavascriptTestBase {
|
||||
$preview = $page->findById('preview-submit');
|
||||
// The first click will load all the libraries.
|
||||
$preview->click();
|
||||
$this->getSession()->wait(5000, "jQuery('.ajax-progress').length === 0");
|
||||
$this->assertJsCondition("jQuery('.ajax-progress').length === 0");
|
||||
// The second click will not load any new libraries.
|
||||
$preview->click();
|
||||
$this->getSession()->wait(5000, "jQuery('.ajax-progress').length === 0");
|
||||
$this->assertJsCondition("jQuery('.ajax-progress').length === 0");
|
||||
// Check to see if the dialogs still open.
|
||||
$add_link = $page->findById('views-add-field');
|
||||
$add_link->click();
|
||||
$this->getSession()->wait(5000, "jQuery('.ui-dialog-titlebar').length > 0");
|
||||
$this->assertJsCondition("jQuery('.ui-dialog-titlebar').length > 0");
|
||||
$page->pressButton('Close');
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,10 @@ class ViewsListingTest extends JavascriptTestBase {
|
||||
* Tests the filtering on the Views listing page.
|
||||
*/
|
||||
public function testFilterViewsListing() {
|
||||
$enabled_views_count = 6;
|
||||
$disabled_views_count = 2;
|
||||
$content_views_count = 3;
|
||||
|
||||
$this->drupalGet('admin/structure/views');
|
||||
|
||||
$session = $this->assertSession();
|
||||
@@ -47,8 +51,8 @@ class ViewsListingTest extends JavascriptTestBase {
|
||||
$disabled_rows = $this->filterVisibleElements($disabled_rows);
|
||||
|
||||
// Test that we see some rows of views in both tables.
|
||||
$this->assertCount(6, $enabled_rows);
|
||||
$this->assertCount(2, $disabled_rows);
|
||||
$this->assertCount($enabled_views_count, $enabled_rows);
|
||||
$this->assertCount($disabled_views_count, $disabled_rows);
|
||||
|
||||
// Filter on the string 'people'. This should only show the people view.
|
||||
$search_input = $page->find('css', '.views-filter-text.form-search');
|
||||
@@ -70,8 +74,8 @@ class ViewsListingTest extends JavascriptTestBase {
|
||||
$disabled_rows = $page->findAll('css', 'tr.views-ui-list-disabled');
|
||||
$disabled_rows = $this->filterVisibleElements($disabled_rows);
|
||||
|
||||
$this->assertCount(3, $enabled_rows);
|
||||
$this->assertCount(2, $disabled_rows);
|
||||
$this->assertCount($content_views_count, $enabled_rows);
|
||||
$this->assertCount($disabled_views_count, $disabled_rows);
|
||||
|
||||
// Reset the search string and check that we are back to the initial stage.
|
||||
$search_input->setValue('');
|
||||
@@ -83,8 +87,8 @@ class ViewsListingTest extends JavascriptTestBase {
|
||||
$disabled_rows = $page->findAll('css', 'tr.views-ui-list-disabled');
|
||||
$disabled_rows = $this->filterVisibleElements($disabled_rows);
|
||||
|
||||
$this->assertCount(6, $enabled_rows);
|
||||
$this->assertCount(2, $disabled_rows);
|
||||
$this->assertCount($enabled_views_count, $enabled_rows);
|
||||
$this->assertCount($disabled_views_count, $disabled_rows);
|
||||
|
||||
// Disable a View and see if it moves to the disabled listing.
|
||||
$enabled_view = $page->find('css', 'tr.views-ui-list-enabled');
|
||||
@@ -103,8 +107,8 @@ class ViewsListingTest extends JavascriptTestBase {
|
||||
$disabled_rows = $this->filterVisibleElements($disabled_rows);
|
||||
|
||||
// Test that one enabled View has been moved to the disabled list.
|
||||
$this->assertCount(5, $enabled_rows);
|
||||
$this->assertCount(3, $disabled_rows);
|
||||
$this->assertCount($enabled_views_count - 1, $enabled_rows);
|
||||
$this->assertCount($disabled_views_count + 1, $disabled_rows);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,7 @@ class ViewsWizardTest extends JavascriptTestBase {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['node', 'views', 'views_ui', 'block'];
|
||||
public static $modules = ['node', 'views', 'views_ui', 'block', 'user'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -56,6 +56,27 @@ class ViewsWizardTest extends JavascriptTestBase {
|
||||
// Add a block display.
|
||||
$page->findField('block[create]')->click();
|
||||
$this->assertEquals($label_value, $page->findField('block[title]')->getValue());
|
||||
|
||||
// Select the entity type to display and test that the type selector is
|
||||
// shown when expected.
|
||||
$page->selectFieldOption('show[wizard_key]', 'node');
|
||||
$this->assertSession()->assertWaitOnAjaxRequest();
|
||||
$this->assertNull($page->findField('show[type]'), 'The "of type" filter is not added for nodes when there are no node types.');
|
||||
$this->assertEquals('teasers', $page->findField('page[style][row_plugin]')->getValue(), 'The page display format shows the expected default value.');
|
||||
$this->assertEquals('titles_linked', $page->findField('block[style][row_plugin]')->getValue(), 'The block display format shows the expected default value.');
|
||||
|
||||
$page->selectFieldOption('show[wizard_key]', 'users');
|
||||
$this->assertSession()->assertWaitOnAjaxRequest();
|
||||
$this->assertNull($page->findField('show[type]'), 'The "of type" filter is not added for users.');
|
||||
$this->assertEquals('fields', $page->findField('page[style][row_plugin]')->getValue(), 'The page display format was updated to a valid value.');
|
||||
$this->assertEquals('fields', $page->findField('block[style][row_plugin]')->getValue(), 'The block display format was updated to a valid value.');
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page']);
|
||||
$page->selectFieldOption('show[wizard_key]', 'node');
|
||||
$this->assertSession()->assertWaitOnAjaxRequest();
|
||||
$this->assertNotNull($page->findField('show[type]'), 'The "of type" filter is added for nodes when there is at least one node type.');
|
||||
$this->assertEquals('fields', $page->findField('page[style][row_plugin]')->getValue(), 'The page display format was not changed from a valid value.');
|
||||
$this->assertEquals('fields', $page->findField('block[style][row_plugin]')->getValue(), 'The block display format was not changed from a valid value.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ class TagTest extends ViewsKernelTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('views', 'views_ui', 'user');
|
||||
public static $modules = ['views', 'views_ui', 'user'];
|
||||
|
||||
/**
|
||||
* Tests the views_ui_autocomplete_tag function.
|
||||
@@ -28,15 +28,15 @@ class TagTest extends ViewsKernelTestBase {
|
||||
\Drupal::moduleHandler()->loadInclude('views_ui', 'inc', 'admin');
|
||||
|
||||
// Save 15 views with a tag.
|
||||
$tags = array();
|
||||
$tags = [];
|
||||
for ($i = 0; $i < 16; $i++) {
|
||||
$suffix = $i % 2 ? 'odd' : 'even';
|
||||
$tag = 'autocomplete_tag_test_' . $suffix . $this->randomMachineName();
|
||||
$tags[] = $tag;
|
||||
View::create(array('tag' => $tag, 'id' => $this->randomMachineName()))->save();
|
||||
View::create(['tag' => $tag, 'id' => $this->randomMachineName()])->save();
|
||||
}
|
||||
|
||||
// Make sure just ten results are returns.
|
||||
// Make sure just ten results are returned.
|
||||
$controller = ViewsUIController::create($this->container);
|
||||
$request = $this->container->get('request_stack')->getCurrentRequest();
|
||||
$request->query->set('q', 'autocomplete_tag_test');
|
||||
@@ -46,7 +46,7 @@ class TagTest extends ViewsKernelTestBase {
|
||||
|
||||
// Make sure the returned array has the proper format.
|
||||
$suggestions = array_map(function ($tag) {
|
||||
return array('value' => $tag, 'label' => Html::escape($tag));
|
||||
return ['value' => $tag, 'label' => Html::escape($tag)];
|
||||
}, $tags);
|
||||
foreach ($matches as $match) {
|
||||
$this->assertTrue(in_array($match, $suggestions), 'Make sure the returned array has the proper format.');
|
||||
@@ -59,7 +59,7 @@ class TagTest extends ViewsKernelTestBase {
|
||||
$matches = (array) json_decode($result->getContent(), TRUE);
|
||||
$this->assertEqual(count($matches), 8, 'Make sure that only a subset is returned.');
|
||||
foreach ($matches as $tag) {
|
||||
$this->assertTrue(array_search($tag['value'], $tags) !== FALSE, format_string('Make sure the returned tag @tag actually exists.', array('@tag' => $tag['value'])));
|
||||
$this->assertTrue(array_search($tag['value'], $tags) !== FALSE, format_string('Make sure the returned tag @tag actually exists.', ['@tag' => $tag['value']]));
|
||||
}
|
||||
|
||||
// Make sure an invalid result doesn't return anything.
|
||||
|
||||
@@ -17,8 +17,8 @@ class RearrangeFilterTest extends UnitTestCase {
|
||||
*/
|
||||
public function testStaticMethods() {
|
||||
// Test the RearrangeFilter::arrayKeyPlus method.
|
||||
$original = array(0 => 'one', 1 => 'two', 2 => 'three');
|
||||
$expected = array(1 => 'one', 2 => 'two', 3 => 'three');
|
||||
$original = [0 => 'one', 1 => 'two', 2 => 'three'];
|
||||
$expected = [1 => 'one', 2 => 'two', 3 => 'three'];
|
||||
$this->assertSame(RearrangeFilter::arrayKeyPlus($original), $expected);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,54 +38,54 @@ class ViewListBuilderTest extends UnitTestCase {
|
||||
|
||||
$display_manager->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->will($this->returnValueMap(array(
|
||||
array(
|
||||
->will($this->returnValueMap([
|
||||
[
|
||||
'default',
|
||||
TRUE,
|
||||
array(
|
||||
[
|
||||
'id' => 'default',
|
||||
'title' => 'Master',
|
||||
'theme' => 'views_view',
|
||||
'no_ui' => TRUE,
|
||||
'admin' => '',
|
||||
)
|
||||
),
|
||||
array(
|
||||
]
|
||||
],
|
||||
[
|
||||
'page',
|
||||
TRUE,
|
||||
array(
|
||||
[
|
||||
'id' => 'page',
|
||||
'title' => 'Page',
|
||||
'uses_menu_links' => TRUE,
|
||||
'uses_route' => TRUE,
|
||||
'contextual_links_locations' => array('page'),
|
||||
'contextual_links_locations' => ['page'],
|
||||
'theme' => 'views_view',
|
||||
'admin' => 'Page admin label',
|
||||
)
|
||||
),
|
||||
array(
|
||||
]
|
||||
],
|
||||
[
|
||||
'embed',
|
||||
TRUE,
|
||||
array(
|
||||
[
|
||||
'id' => 'embed',
|
||||
'title' => 'embed',
|
||||
'theme' => 'views_view',
|
||||
'admin' => 'Embed admin label',
|
||||
)
|
||||
),
|
||||
)));
|
||||
]
|
||||
],
|
||||
]));
|
||||
|
||||
|
||||
$default_display = $this->getMock('Drupal\views\Plugin\views\display\DefaultDisplay',
|
||||
array('initDisplay'),
|
||||
array(array(), 'default', $display_manager->getDefinition('default'))
|
||||
['initDisplay'],
|
||||
[[], 'default', $display_manager->getDefinition('default')]
|
||||
);
|
||||
$route_provider = $this->getMock('Drupal\Core\Routing\RouteProviderInterface');
|
||||
$state = $this->getMock('\Drupal\Core\State\StateInterface');
|
||||
$menu_storage = $this->getMock('\Drupal\Core\Entity\EntityStorageInterface');
|
||||
$page_display = $this->getMock('Drupal\views\Plugin\views\display\Page',
|
||||
array('initDisplay', 'getPath'),
|
||||
array(array(), 'default', $display_manager->getDefinition('page'), $route_provider, $state, $menu_storage)
|
||||
['initDisplay', 'getPath'],
|
||||
[[], 'default', $display_manager->getDefinition('page'), $route_provider, $state, $menu_storage]
|
||||
);
|
||||
$page_display->expects($this->any())
|
||||
->method('getPath')
|
||||
@@ -94,11 +94,11 @@ class ViewListBuilderTest extends UnitTestCase {
|
||||
$this->returnValue('<object>malformed_path</object>'),
|
||||
$this->returnValue('<script>alert("placeholder_page/%")</script>')));
|
||||
|
||||
$embed_display = $this->getMock('Drupal\views\Plugin\views\display\Embed', array('initDisplay'),
|
||||
array(array(), 'default', $display_manager->getDefinition('embed'))
|
||||
$embed_display = $this->getMock('Drupal\views\Plugin\views\display\Embed', ['initDisplay'],
|
||||
[[], 'default', $display_manager->getDefinition('embed')]
|
||||
);
|
||||
|
||||
$values = array();
|
||||
$values = [];
|
||||
$values['status'] = FALSE;
|
||||
$values['display']['default']['id'] = 'default';
|
||||
$values['display']['default']['display_title'] = 'Display';
|
||||
@@ -125,13 +125,13 @@ class ViewListBuilderTest extends UnitTestCase {
|
||||
|
||||
$display_manager->expects($this->any())
|
||||
->method('createInstance')
|
||||
->will($this->returnValueMap(array(
|
||||
array('default', $values['display']['default'], $default_display),
|
||||
array('page', $values['display']['page_1'], $page_display),
|
||||
array('page', $values['display']['page_2'], $page_display),
|
||||
array('page', $values['display']['page_3'], $page_display),
|
||||
array('embed', $values['display']['embed'], $embed_display),
|
||||
)));
|
||||
->will($this->returnValueMap([
|
||||
['default', $values['display']['default'], $default_display],
|
||||
['page', $values['display']['page_1'], $page_display],
|
||||
['page', $values['display']['page_2'], $page_display],
|
||||
['page', $values['display']['page_3'], $page_display],
|
||||
['embed', $values['display']['embed'], $embed_display],
|
||||
]));
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$user = $this->getMock('Drupal\Core\Session\AccountInterface');
|
||||
@@ -152,21 +152,34 @@ class ViewListBuilderTest extends UnitTestCase {
|
||||
$view_list_builder = new TestViewListBuilder($entity_type, $storage, $display_manager);
|
||||
$view_list_builder->setStringTranslation($this->getStringTranslationStub());
|
||||
|
||||
// Create new view with test values.
|
||||
$view = new View($values, 'view');
|
||||
|
||||
// Get the row object created by ViewListBuilder for this test view.
|
||||
$row = $view_list_builder->buildRow($view);
|
||||
|
||||
$expected_displays = array(
|
||||
'Embed admin label',
|
||||
'Page admin label',
|
||||
'Page admin label',
|
||||
'Page admin label',
|
||||
);
|
||||
$this->assertEquals($expected_displays, $row['data']['view_name']['data']['#displays']);
|
||||
// Expected output array for view's displays.
|
||||
$expected_displays = [
|
||||
'0' => [
|
||||
'display' => 'Embed admin label',
|
||||
'path' => FALSE,
|
||||
],
|
||||
'1' => [
|
||||
'display' => 'Page admin label',
|
||||
'path' => '/<object>malformed_path</object>',
|
||||
],
|
||||
'2' => [
|
||||
'display' => 'Page admin label',
|
||||
'path' => '/<script>alert("placeholder_page/%")</script>',
|
||||
],
|
||||
'3' => [
|
||||
'display' => 'Page admin label',
|
||||
'path' => '/test_page',
|
||||
],
|
||||
];
|
||||
|
||||
$display_paths = $row['data']['path']['data']['#items'];
|
||||
// These values will be escaped by Twig when rendered.
|
||||
$this->assertEquals('/test_page, /<object>malformed_path</object>, /<script>alert("placeholder_page/%")</script>', implode(', ', $display_paths));
|
||||
// Compare the expected and generated output.
|
||||
$this->assertEquals($expected_displays, $row['data']['displays']['data']['#displays']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -174,7 +187,7 @@ class ViewListBuilderTest extends UnitTestCase {
|
||||
class TestViewListBuilder extends ViewListBuilder {
|
||||
|
||||
public function buildOperations(EntityInterface $entity) {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,14 +18,14 @@ class ViewUIObjectTest extends UnitTestCase {
|
||||
* Tests entity method decoration.
|
||||
*/
|
||||
public function testEntityDecoration() {
|
||||
$method_args = array();
|
||||
$method_args['setOriginalId'] = array(12);
|
||||
$method_args['setStatus'] = array(TRUE);
|
||||
$method_args['enforceIsNew'] = array(FALSE);
|
||||
$method_args['label'] = array(LanguageInterface::LANGCODE_NOT_SPECIFIED);
|
||||
$method_args = [];
|
||||
$method_args['setOriginalId'] = [12];
|
||||
$method_args['setStatus'] = [TRUE];
|
||||
$method_args['enforceIsNew'] = [FALSE];
|
||||
$method_args['label'] = [LanguageInterface::LANGCODE_NOT_SPECIFIED];
|
||||
|
||||
$reflection = new \ReflectionClass('Drupal\Core\Config\Entity\ConfigEntityInterface');
|
||||
$interface_methods = array();
|
||||
$interface_methods = [];
|
||||
foreach ($reflection->getMethods() as $reflection_method) {
|
||||
$interface_methods[] = $reflection_method->getName();
|
||||
|
||||
@@ -38,15 +38,15 @@ class ViewUIObjectTest extends UnitTestCase {
|
||||
// dependency management.
|
||||
if (!in_array($reflection_method->getName(), ['isNew', 'isSyncing', 'isUninstalling', 'getConfigDependencyKey', 'getConfigDependencyName', 'calculateDependencies'])) {
|
||||
if (count($reflection_method->getParameters()) == 0) {
|
||||
$method_args[$reflection_method->getName()] = array();
|
||||
$method_args[$reflection_method->getName()] = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$storage = $this->getMock('Drupal\views\Entity\View', $interface_methods, array(array(), 'view'));
|
||||
$storage = $this->getMock('Drupal\views\Entity\View', $interface_methods, [[], 'view']);
|
||||
$executable = $this->getMockBuilder('Drupal\views\ViewExecutable')
|
||||
->disableOriginalConstructor()
|
||||
->setConstructorArgs(array($storage))
|
||||
->setConstructorArgs([$storage])
|
||||
->getMock();
|
||||
$storage->set('executable', $executable);
|
||||
|
||||
@@ -58,7 +58,7 @@ class ViewUIObjectTest extends UnitTestCase {
|
||||
foreach ($args as $arg) {
|
||||
$method_mock->with($this->equalTo($arg));
|
||||
}
|
||||
call_user_func_array(array($view_ui, $method), $args);
|
||||
call_user_func_array([$view_ui, $method], $args);
|
||||
}
|
||||
|
||||
$storage->expects($this->once())
|
||||
@@ -70,10 +70,10 @@ class ViewUIObjectTest extends UnitTestCase {
|
||||
* Tests the isLocked method.
|
||||
*/
|
||||
public function testIsLocked() {
|
||||
$storage = $this->getMock('Drupal\views\Entity\View', array(), array(array(), 'view'));
|
||||
$storage = $this->getMock('Drupal\views\Entity\View', [], [[], 'view']);
|
||||
$executable = $this->getMockBuilder('Drupal\views\ViewExecutable')
|
||||
->disableOriginalConstructor()
|
||||
->setConstructorArgs(array($storage))
|
||||
->setConstructorArgs([$storage])
|
||||
->getMock();
|
||||
$storage->set('executable', $executable);
|
||||
$account = $this->getMock('Drupal\Core\Session\AccountInterface');
|
||||
@@ -91,20 +91,20 @@ class ViewUIObjectTest extends UnitTestCase {
|
||||
$this->assertFalse($view_ui->isLocked());
|
||||
|
||||
// Set the lock object with a different owner than the mocked account above.
|
||||
$lock = (object) array(
|
||||
$lock = (object) [
|
||||
'owner' => 2,
|
||||
'data' => array(),
|
||||
'data' => [],
|
||||
'updated' => (int) $_SERVER['REQUEST_TIME'],
|
||||
);
|
||||
];
|
||||
$view_ui->lock = $lock;
|
||||
$this->assertTrue($view_ui->isLocked());
|
||||
|
||||
// Set a different lock object with the same object as the mocked account.
|
||||
$lock = (object) array(
|
||||
$lock = (object) [
|
||||
'owner' => 1,
|
||||
'data' => array(),
|
||||
'data' => [],
|
||||
'updated' => (int) $_SERVER['REQUEST_TIME'],
|
||||
);
|
||||
];
|
||||
$view_ui->lock = $lock;
|
||||
$this->assertFalse($view_ui->isLocked());
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ configure: entity.view.collection
|
||||
dependencies:
|
||||
- views
|
||||
|
||||
# Information added by Drupal.org packaging script on 2016-08-03
|
||||
version: '8.1.8'
|
||||
# Information added by Drupal.org packaging script on 2017-08-16
|
||||
version: '8.3.7'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1470233790
|
||||
datestamp: 1502903957
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
views_add_local_action:
|
||||
route_name: views_ui.add
|
||||
title: 'Add new view'
|
||||
title: 'Add view'
|
||||
appears_on:
|
||||
- entity.view.collection
|
||||
|
||||
@@ -19,15 +19,15 @@ function views_ui_help($route_name, RouteMatchInterface $route_match) {
|
||||
case 'help.page.views_ui':
|
||||
$output = '';
|
||||
$output .= '<h3>' . t('About') . '</h3>';
|
||||
$output .= '<p>' . t('The Views UI module provides an interface for managing views for the <a href=":views">Views module</a>. For more information, see the <a href=":handbook">online documentation for the Views UI module</a>.', array(':views' => \Drupal::url('help.page', array('name' => 'views')), ':handbook' => 'https://www.drupal.org/documentation/modules/views_ui')) . '</p>';
|
||||
$output .= '<p>' . t('The Views UI module provides an interface for managing views for the <a href=":views">Views module</a>. For more information, see the <a href=":handbook">online documentation for the Views UI module</a>.', [':views' => \Drupal::url('help.page', ['name' => 'views']), ':handbook' => 'https://www.drupal.org/documentation/modules/views_ui']) . '</p>';
|
||||
$output .= '<h3>' . t('Uses') . '</h3>';
|
||||
$output .= '<dl>';
|
||||
$output .= '<dt>' . t('Creating and managing views') . '</dt>';
|
||||
$output .= '<dd>' . t('Views can be created from the <a href=":list">Views list page</a> by using the "Add new view" action. Existing views can be managed from the <a href=":list">Views list page</a> by locating the view in the "Enabled" or "Disabled" list and selecting the desired operation action, for example "Edit".', array(':list' => \Drupal::url('entity.view.collection', array('name' => 'views_ui')))) . '</dd>';
|
||||
$output .= '<dd>' . t('Views can be created from the <a href=":list">Views list page</a> by using the "Add view" action. Existing views can be managed from the <a href=":list">Views list page</a> by locating the view in the "Enabled" or "Disabled" list and selecting the desired operation action, for example "Edit".', [':list' => \Drupal::url('entity.view.collection', ['name' => 'views_ui'])]) . '</dd>';
|
||||
$output .= '<dt>' . t('Enabling and disabling views') . '<dt>';
|
||||
$output .= '<dd>' . t('Views can be enabled or disabled from the <a href=":list">Views list page</a>. To enable a view, find the view within the "Disabled" list and select the "Enable" operation. To disable a view find the view within the "Enabled" list and select the "Disable" operation.', array(':list' => \Drupal::url('entity.view.collection', array('name' => 'views_ui')))) . '</dd>';
|
||||
$output .= '<dd>' . t('Views can be enabled or disabled from the <a href=":list">Views list page</a>. To enable a view, find the view within the "Disabled" list and select the "Enable" operation. To disable a view find the view within the "Enabled" list and select the "Disable" operation.', [':list' => \Drupal::url('entity.view.collection', ['name' => 'views_ui'])]) . '</dd>';
|
||||
$output .= '<dt>' . t('Exporting and importing views') . '</dt>';
|
||||
$output .= '<dd>' . t('Views can be exported and imported as configuration files by using the <a href=":config">Configuration Manager module</a>.', array(':config' => (\Drupal::moduleHandler()->moduleExists('config')) ? \Drupal::url('help.page', array('name' => 'config')) : '#')) . '</dd>';
|
||||
$output .= '<dd>' . t('Views can be exported and imported as configuration files by using the <a href=":config">Configuration Manager module</a>.', [':config' => (\Drupal::moduleHandler()->moduleExists('config')) ? \Drupal::url('help.page', ['name' => 'config']) : '#']) . '</dd>';
|
||||
$output .= '</dl>';
|
||||
return $output;
|
||||
}
|
||||
@@ -61,56 +61,69 @@ function views_ui_entity_type_build(array &$entity_types) {
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
function views_ui_theme() {
|
||||
return array(
|
||||
return [
|
||||
// edit a view
|
||||
'views_ui_display_tab_setting' => array(
|
||||
'variables' => array('description' => '', 'link' => '', 'settings_links' => array(), 'overridden' => FALSE, 'defaulted' => FALSE, 'description_separator' => TRUE, 'class' => array()),
|
||||
'views_ui_display_tab_setting' => [
|
||||
'variables' => ['description' => '', 'link' => '', 'settings_links' => [], 'overridden' => FALSE, 'defaulted' => FALSE, 'description_separator' => TRUE, 'class' => []],
|
||||
'file' => 'views_ui.theme.inc',
|
||||
),
|
||||
'views_ui_display_tab_bucket' => array(
|
||||
],
|
||||
'views_ui_display_tab_bucket' => [
|
||||
'render element' => 'element',
|
||||
'file' => 'views_ui.theme.inc',
|
||||
),
|
||||
'views_ui_rearrange_filter_form' => array(
|
||||
],
|
||||
'views_ui_rearrange_filter_form' => [
|
||||
'render element' => 'form',
|
||||
'file' => 'views_ui.theme.inc',
|
||||
),
|
||||
'views_ui_expose_filter_form' => array(
|
||||
],
|
||||
'views_ui_expose_filter_form' => [
|
||||
'render element' => 'form',
|
||||
'file' => 'views_ui.theme.inc',
|
||||
),
|
||||
],
|
||||
|
||||
// list views
|
||||
'views_ui_view_info' => array(
|
||||
'variables' => array('view' => NULL, 'displays' => NULL),
|
||||
// Legacy theme hook for displaying views info.
|
||||
'views_ui_view_info' => [
|
||||
'variables' => ['view' => NULL, 'displays' => NULL],
|
||||
'file' => 'views_ui.theme.inc',
|
||||
),
|
||||
],
|
||||
|
||||
// List views.
|
||||
'views_ui_views_listing_table' => [
|
||||
'variables' => [
|
||||
'headers' => NULL,
|
||||
'rows' => NULL,
|
||||
'attributes' => [],
|
||||
],
|
||||
'file' => 'views_ui.theme.inc',
|
||||
],
|
||||
'views_ui_view_displays_list' => [
|
||||
'variables' => ['displays' => []],
|
||||
],
|
||||
|
||||
// Group of filters.
|
||||
'views_ui_build_group_filter_form' => array(
|
||||
'views_ui_build_group_filter_form' => [
|
||||
'render element' => 'form',
|
||||
'file' => 'views_ui.theme.inc',
|
||||
),
|
||||
],
|
||||
|
||||
// On behalf of a plugin
|
||||
'views_ui_style_plugin_table' => array(
|
||||
'views_ui_style_plugin_table' => [
|
||||
'render element' => 'form',
|
||||
'file' => 'views_ui.theme.inc',
|
||||
),
|
||||
],
|
||||
|
||||
// When previewing a view.
|
||||
'views_ui_view_preview_section' => array(
|
||||
'variables' => array('view' => NULL, 'section' => NULL, 'content' => NULL, 'links' => ''),
|
||||
'views_ui_view_preview_section' => [
|
||||
'variables' => ['view' => NULL, 'section' => NULL, 'content' => NULL, 'links' => ''],
|
||||
'file' => 'views_ui.theme.inc',
|
||||
),
|
||||
],
|
||||
|
||||
// Generic container wrapper, to use instead of theme_container when an id
|
||||
// is not desired.
|
||||
'views_ui_container' => array(
|
||||
'variables' => array('children' => NULL, 'attributes' => array()),
|
||||
'views_ui_container' => [
|
||||
'variables' => ['children' => NULL, 'attributes' => []],
|
||||
'file' => 'views_ui.theme.inc',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,21 +134,23 @@ function views_ui_preprocess_views_view(&$variables) {
|
||||
|
||||
// Render title for the admin preview.
|
||||
if (!empty($view->live_preview)) {
|
||||
$variables['title']['#markup'] = $view->getTitle();
|
||||
$variables['title'] = [
|
||||
'#markup' => $view->getTitle()
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($view->live_preview) && \Drupal::moduleHandler()->moduleExists('contextual')) {
|
||||
$view->setShowAdminLinks(FALSE);
|
||||
foreach (array('title', 'header', 'exposed', 'rows', 'pager', 'more', 'footer', 'empty', 'attachment_after', 'attachment_before') as $section) {
|
||||
foreach (['title', 'header', 'exposed', 'rows', 'pager', 'more', 'footer', 'empty', 'attachment_after', 'attachment_before'] as $section) {
|
||||
if (!empty($variables[$section])) {
|
||||
$variables[$section] = array(
|
||||
$variables[$section] = [
|
||||
'#theme' => 'views_ui_view_preview_section',
|
||||
'#view' => $view,
|
||||
'#section' => $section,
|
||||
'#content' => $variables[$section],
|
||||
'#theme_wrappers' => array('views_ui_container'),
|
||||
'#attributes' => array('class' => array('contextual-region')),
|
||||
);
|
||||
'#theme_wrappers' => ['views_ui_container'],
|
||||
'#attributes' => ['class' => ['contextual-region']],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -154,28 +169,28 @@ function views_ui_preprocess_views_view(&$variables) {
|
||||
function views_ui_view_preview_section_handler_links(ViewExecutable $view, $type, $title = FALSE) {
|
||||
$display = $view->display_handler->display;
|
||||
$handlers = $view->display_handler->getHandlers($type);
|
||||
$links = array();
|
||||
$links = [];
|
||||
|
||||
$types = ViewExecutable::getHandlerTypes();
|
||||
if ($title) {
|
||||
$links[$type . '-title'] = array(
|
||||
$links[$type . '-title'] = [
|
||||
'title' => $types[$type]['title'],
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($handlers as $id => $handler) {
|
||||
$field_name = $handler->adminLabel(TRUE);
|
||||
$links[$type . '-edit-' . $id] = array(
|
||||
'title' => t('Edit @section', array('@section' => $field_name)),
|
||||
$links[$type . '-edit-' . $id] = [
|
||||
'title' => t('Edit @section', ['@section' => $field_name]),
|
||||
'url' => Url::fromRoute('views_ui.form_handler', ['js' => 'nojs', 'view' => $view->storage->id(), 'display_id' => $display['id'], 'type' => $type, 'id' => $id]),
|
||||
'attributes' => array('class' => array('views-ajax-link')),
|
||||
);
|
||||
'attributes' => ['class' => ['views-ajax-link']],
|
||||
];
|
||||
}
|
||||
$links[$type . '-add'] = array(
|
||||
$links[$type . '-add'] = [
|
||||
'title' => t('Add new'),
|
||||
'url' => Url::fromRoute('views_ui.form_add_handler', ['js' => 'nojs', 'view' => $view->storage->id(), 'display_id' => $display['id'], 'type' => $type]),
|
||||
'attributes' => array('class' => array('views-ajax-link')),
|
||||
);
|
||||
'attributes' => ['class' => ['views-ajax-link']],
|
||||
];
|
||||
|
||||
return $links;
|
||||
}
|
||||
@@ -185,13 +200,13 @@ function views_ui_view_preview_section_handler_links(ViewExecutable $view, $type
|
||||
*/
|
||||
function views_ui_view_preview_section_display_category_links(ViewExecutable $view, $type, $title) {
|
||||
$display = $view->display_handler->display;
|
||||
$links = array(
|
||||
$type . '-edit' => array(
|
||||
'title' => t('Edit @section', array('@section' => $title)),
|
||||
$links = [
|
||||
$type . '-edit' => [
|
||||
'title' => t('Edit @section', ['@section' => $title]),
|
||||
'url' => Url::fromRoute('views_ui.form_display', ['js' => 'nojs', 'view' => $view->storage->id(), 'display_id' => $display['id'], 'type' => $type]),
|
||||
'attributes' => array('class' => array('views-ajax-link')),
|
||||
),
|
||||
);
|
||||
'attributes' => ['class' => ['views-ajax-link']],
|
||||
],
|
||||
];
|
||||
|
||||
return $links;
|
||||
}
|
||||
@@ -200,7 +215,7 @@ function views_ui_view_preview_section_display_category_links(ViewExecutable $vi
|
||||
* Returns all contextual links for the main content part of the view.
|
||||
*/
|
||||
function views_ui_view_preview_section_rows_links(ViewExecutable $view) {
|
||||
$links = array();
|
||||
$links = [];
|
||||
$links = array_merge($links, views_ui_view_preview_section_handler_links($view, 'filter', TRUE));
|
||||
$links = array_merge($links, views_ui_view_preview_section_handler_links($view, 'field', TRUE));
|
||||
$links = array_merge($links, views_ui_view_preview_section_handler_links($view, 'sort', TRUE));
|
||||
@@ -218,10 +233,10 @@ function views_ui_views_plugins_display_alter(&$plugins) {
|
||||
// paths underneath "admin/structure/views/view/{$view->id()}" (i.e., paths
|
||||
// for editing and performing other contextual actions on the view).
|
||||
foreach ($plugins as &$display) {
|
||||
$display['contextual links']['entity.view.edit_form'] = array(
|
||||
$display['contextual links']['entity.view.edit_form'] = [
|
||||
'route_name' => 'entity.view.edit_form',
|
||||
'route_parameters_names' => array('view' => 'id'),
|
||||
);
|
||||
'route_parameters_names' => ['view' => 'id'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,7 +247,7 @@ function views_ui_contextual_links_view_alter(&$element, $items) {
|
||||
// Remove contextual links from being rendered, when so desired, such as
|
||||
// within a View preview.
|
||||
if (views_ui_contextual_links_suppress()) {
|
||||
$element['#links'] = array();
|
||||
$element['#links'] = [];
|
||||
}
|
||||
// Append the display ID to the Views UI edit links, so that clicking on the
|
||||
// contextual link takes you directly to the correct display tab on the edit
|
||||
@@ -290,7 +305,7 @@ function views_ui_contextual_links_suppress_pop() {
|
||||
* node.views.inc as well.
|
||||
*/
|
||||
function views_ui_views_analyze(ViewExecutable $view) {
|
||||
$ret = array();
|
||||
$ret = [];
|
||||
// Check for something other than the default display:
|
||||
if (count($view->displayHandlers) < 2) {
|
||||
$ret[] = Analyzer::formatMessage(t('This view has only a default display and therefore will not be placed anywhere on your site; perhaps you want to add a page or a block display.'), 'warning');
|
||||
@@ -305,7 +320,7 @@ function views_ui_views_analyze(ViewExecutable $view) {
|
||||
if ($display->hasPath() && $path = $display->getOption('path')) {
|
||||
$normal_path = \Drupal::service('path.alias_manager')->getPathByAlias($path);
|
||||
if ($path != $normal_path) {
|
||||
$ret[] = Analyzer::formatMessage(t('You have configured display %display with a path which is an path alias as well. This might lead to unwanted effects so better use an internal path.', array('%display' => $display->display['display_title'])), 'warning');
|
||||
$ret[] = Analyzer::formatMessage(t('You have configured display %display with a path which is an path alias as well. This might lead to unwanted effects so better use an internal path.', ['%display' => $display->display['display_title']]), 'warning');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
administer views:
|
||||
title: 'Administer views'
|
||||
description: 'Access the views administration pages.'
|
||||
restrict access: true
|
||||
|
||||
@@ -10,7 +10,7 @@ views_ui.add:
|
||||
path: '/admin/structure/views/add'
|
||||
defaults:
|
||||
_entity_form: 'view.add'
|
||||
_title: 'Add new view'
|
||||
_title: 'Add view'
|
||||
requirements:
|
||||
_entity_create_access: view
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ use Drupal\Core\Render\Element;
|
||||
use Drupal\Core\Render\Element\Checkboxes;
|
||||
use Drupal\Core\Render\Element\Radios;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Core\Template\Attribute;
|
||||
|
||||
/**
|
||||
* Prepares variables for Views UI display tab setting templates.
|
||||
@@ -42,6 +43,31 @@ function template_preprocess_views_ui_display_tab_setting(&$variables) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares variables for Views UI view listing templates.
|
||||
*
|
||||
* Default template: views-ui-view-listing-table.html.twig.
|
||||
*
|
||||
* @param array $variables
|
||||
* An associative array containing:
|
||||
* - headers: An associative array containing the headers for the view
|
||||
* listing table.
|
||||
* - rows: An associative array containing the rows data for the view
|
||||
* listing table.
|
||||
*/
|
||||
function template_preprocess_views_ui_views_listing_table(&$variables) {
|
||||
// Convert the attributes to valid attribute objects.
|
||||
foreach ($variables['headers'] as $key => $header) {
|
||||
$variables['headers'][$key]['attributes'] = new Attribute($header['#attributes']);
|
||||
}
|
||||
|
||||
if (!empty($variables['rows'])) {
|
||||
foreach ($variables['rows'] as $key => $row) {
|
||||
$variables['rows'][$key]['attributes'] = new Attribute($row['#attributes']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares variables for Views UI display tab bucket templates.
|
||||
*
|
||||
@@ -63,7 +89,7 @@ function template_preprocess_views_ui_display_tab_bucket(&$variables) {
|
||||
$variables['overridden'] = isset($element['#overridden']) ? $element['#overridden'] : NULL;
|
||||
$variables['content'] = $element['#children'];
|
||||
$variables['title'] = $element['#title'];
|
||||
$variables['actions'] = !empty($element['#actions']) ? $element['#actions'] : array();
|
||||
$variables['actions'] = !empty($element['#actions']) ? $element['#actions'] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,14 +105,14 @@ function template_preprocess_views_ui_build_group_filter_form(&$variables) {
|
||||
$form = $variables['form'];
|
||||
|
||||
// Prepare table of options.
|
||||
$header = array(
|
||||
$header = [
|
||||
t('Default'),
|
||||
t('Weight'),
|
||||
t('Label'),
|
||||
t('Operator'),
|
||||
t('Value'),
|
||||
t('Operations'),
|
||||
);
|
||||
];
|
||||
|
||||
// Prepare default selectors.
|
||||
$form_state = new FormState();
|
||||
@@ -94,15 +120,15 @@ function template_preprocess_views_ui_build_group_filter_form(&$variables) {
|
||||
$form['default_group_multiple'] = Checkboxes::processCheckboxes($form['default_group_multiple'], $form_state, $form);
|
||||
$form['default_group']['All']['#title'] = '';
|
||||
|
||||
$rows[] = array(
|
||||
$rows[] = [
|
||||
['data' => $form['default_group']['All']],
|
||||
'',
|
||||
array(
|
||||
[
|
||||
'data' => \Drupal::config('views.settings')->get('ui.exposed_filter_any_label') == 'old_any' ? t('<Any>') : t('- Any -'),
|
||||
'colspan' => 4,
|
||||
'class' => array('class' => 'any-default-radios-row'),
|
||||
),
|
||||
);
|
||||
'class' => ['class' => 'any-default-radios-row'],
|
||||
],
|
||||
];
|
||||
// Remove the 'All' default_group form element because it's added to the
|
||||
// table row.
|
||||
unset($variables['form']['default_group']['All']);
|
||||
@@ -135,32 +161,32 @@ function template_preprocess_views_ui_build_group_filter_form(&$variables) {
|
||||
'#title' => SafeMarkup::format('<span>@text</span>', ['@text' => t('Remove')]),
|
||||
];
|
||||
$remove = [$form['group_items'][$group_id]['remove'], $link];
|
||||
$data = array(
|
||||
$data = [
|
||||
'default' => ['data' => $default],
|
||||
'weight' => ['data' => $form['group_items'][$group_id]['weight']],
|
||||
'title' => ['data' => $form['group_items'][$group_id]['title']],
|
||||
'operator' => ['data' => $form['group_items'][$group_id]['operator']],
|
||||
'value' => ['data' => $form['group_items'][$group_id]['value']],
|
||||
'remove' => ['data' => $remove],
|
||||
);
|
||||
$rows[] = array('data' => $data, 'id' => 'views-row-' . $group_id, 'class' => array('draggable'));
|
||||
];
|
||||
$rows[] = ['data' => $data, 'id' => 'views-row-' . $group_id, 'class' => ['draggable']];
|
||||
}
|
||||
$variables['table'] = array(
|
||||
$variables['table'] = [
|
||||
'#type' => 'table',
|
||||
'#header' => $header,
|
||||
'#rows' => $rows,
|
||||
'#attributes' => array(
|
||||
'class' => array('views-filter-groups'),
|
||||
'#attributes' => [
|
||||
'class' => ['views-filter-groups'],
|
||||
'id' => 'views-filter-groups',
|
||||
),
|
||||
'#tabledrag' => array(
|
||||
array(
|
||||
],
|
||||
'#tabledrag' => [
|
||||
[
|
||||
'action' => 'order',
|
||||
'relationship' => 'sibling',
|
||||
'group' => 'weight',
|
||||
)
|
||||
),
|
||||
);
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
// Hide fields used in table.
|
||||
unset($variables['form']['group_items']);
|
||||
@@ -177,7 +203,7 @@ function template_preprocess_views_ui_build_group_filter_form(&$variables) {
|
||||
*/
|
||||
function template_preprocess_views_ui_rearrange_filter_form(&$variables) {
|
||||
$form = &$variables['form'];
|
||||
$rows = $ungroupable_rows = array();
|
||||
$rows = $ungroupable_rows = [];
|
||||
// Enable grouping only if > 1 group.
|
||||
$variables['grouping'] = count(array_keys($form['#group_options'])) > 1;
|
||||
|
||||
@@ -186,41 +212,41 @@ function template_preprocess_views_ui_rearrange_filter_form(&$variables) {
|
||||
if ($group_id !== 'ungroupable') {
|
||||
// Set up tabledrag so that it changes the group dropdown when rows are
|
||||
// dragged between groups.
|
||||
$options = array(
|
||||
$options = [
|
||||
'table_id' => 'views-rearrange-filters',
|
||||
'action' => 'match',
|
||||
'relationship' => 'sibling',
|
||||
'group' => 'views-group-select',
|
||||
'subgroup' => 'views-group-select-' . $group_id,
|
||||
);
|
||||
];
|
||||
drupal_attach_tabledrag($form['override'], $options);
|
||||
|
||||
// Title row, spanning all columns.
|
||||
$row = array();
|
||||
$row = [];
|
||||
// Add a cell to the first row, containing the group operator.
|
||||
$row[] = array(
|
||||
'class' => array('group', 'group-operator', 'container-inline'),
|
||||
$row[] = [
|
||||
'class' => ['group', 'group-operator', 'container-inline'],
|
||||
'data' => $form['filter_groups']['groups'][$group_id],
|
||||
'rowspan' => max(array(2, count($contents) + 1)),
|
||||
);
|
||||
'rowspan' => max([2, count($contents) + 1]),
|
||||
];
|
||||
// Title.
|
||||
$row[] = array(
|
||||
'class' => array('group', 'group-title'),
|
||||
'data' => array(
|
||||
$row[] = [
|
||||
'class' => ['group', 'group-title'],
|
||||
'data' => [
|
||||
'#prefix' => '<span>',
|
||||
'#markup' => $form['#group_options'][$group_id],
|
||||
'#suffix' => '</span>',
|
||||
),
|
||||
],
|
||||
'colspan' => 4,
|
||||
);
|
||||
$rows[] = array(
|
||||
'class' => array('views-group-title'),
|
||||
];
|
||||
$rows[] = [
|
||||
'class' => ['views-group-title'],
|
||||
'data' => $row,
|
||||
'id' => 'views-group-title-' . $group_id,
|
||||
);
|
||||
];
|
||||
|
||||
// Row which will only appear if the group has nothing in it.
|
||||
$row = array();
|
||||
$row = [];
|
||||
$class = 'group-' . (count($contents) ? 'populated' : 'empty');
|
||||
$instructions = '<span>' . t('No filters have been added.') . '</span> <span class="js-only">' . t('Drag to add filters.') . '</span>';
|
||||
// When JavaScript is enabled, the button for removing the group (if it's
|
||||
@@ -229,63 +255,63 @@ function template_preprocess_views_ui_rearrange_filter_form(&$variables) {
|
||||
if (!empty($form['remove_groups'][$group_id]['#type']) && $form['remove_groups'][$group_id]['#type'] == 'submit') {
|
||||
$form['remove_groups'][$group_id]['#attributes']['class'][] = 'js-hide';
|
||||
}
|
||||
$row[] = array(
|
||||
$row[] = [
|
||||
'colspan' => 5,
|
||||
'data' => array(
|
||||
array('#markup' => $instructions),
|
||||
'data' => [
|
||||
['#markup' => $instructions],
|
||||
$form['remove_groups'][$group_id],
|
||||
),
|
||||
);
|
||||
$rows[] = array(
|
||||
'class' => array(
|
||||
],
|
||||
];
|
||||
$rows[] = [
|
||||
'class' => [
|
||||
'group-message',
|
||||
'group-' . $group_id . '-message',
|
||||
$class,
|
||||
),
|
||||
],
|
||||
'data' => $row,
|
||||
'id' => 'views-group-' . $group_id,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($contents as $id) {
|
||||
if (isset($form['filters'][$id]['name'])) {
|
||||
$row = array();
|
||||
$row = [];
|
||||
$row[]['data'] = $form['filters'][$id]['name'];
|
||||
$form['filters'][$id]['weight']['#attributes']['class'] = array('weight');
|
||||
$form['filters'][$id]['weight']['#attributes']['class'] = ['weight'];
|
||||
$row[]['data'] = $form['filters'][$id]['weight'];
|
||||
$form['filters'][$id]['group']['#attributes']['class'] = array('views-group-select views-group-select-' . $group_id);
|
||||
$form['filters'][$id]['group']['#attributes']['class'] = ['views-group-select views-group-select-' . $group_id];
|
||||
$row[]['data'] = $form['filters'][$id]['group'];
|
||||
$form['filters'][$id]['removed']['#attributes']['class'][] = 'js-hide';
|
||||
|
||||
$remove_link = array(
|
||||
$remove_link = [
|
||||
'#type' => 'link',
|
||||
'#url' => Url::fromRoute('<none>'),
|
||||
'#title' => SafeMarkup::format('<span>@text</span>', array('@text' => t('Remove'))),
|
||||
'#title' => SafeMarkup::format('<span>@text</span>', ['@text' => t('Remove')]),
|
||||
'#weight' => '1',
|
||||
'#options' => array(
|
||||
'attributes' => array(
|
||||
'#options' => [
|
||||
'attributes' => [
|
||||
'id' => 'views-remove-link-' . $id,
|
||||
'class' => array(
|
||||
'class' => [
|
||||
'views-hidden',
|
||||
'views-button-remove',
|
||||
'views-groups-remove-link',
|
||||
'views-remove-link',
|
||||
),
|
||||
],
|
||||
'alt' => t('Remove this item'),
|
||||
'title' => t('Remove this item'),
|
||||
),
|
||||
),
|
||||
);
|
||||
$row[]['data'] = array(
|
||||
],
|
||||
],
|
||||
];
|
||||
$row[]['data'] = [
|
||||
$form['filters'][$id]['removed'],
|
||||
$remove_link,
|
||||
);
|
||||
];
|
||||
|
||||
$row = array(
|
||||
$row = [
|
||||
'data' => $row,
|
||||
'class' => array('draggable'),
|
||||
'class' => ['draggable'],
|
||||
'id' => 'views-row-' . $id,
|
||||
);
|
||||
];
|
||||
|
||||
if ($group_id !== 'ungroupable') {
|
||||
$rows[] = $row;
|
||||
@@ -302,56 +328,56 @@ function template_preprocess_views_ui_rearrange_filter_form(&$variables) {
|
||||
}
|
||||
|
||||
if (!empty($ungroupable_rows)) {
|
||||
$header = array(
|
||||
$header = [
|
||||
t('Ungroupable filters'),
|
||||
t('Weight'),
|
||||
array(
|
||||
[
|
||||
'data' => t('Group'),
|
||||
'class' => array('views-hide-label'),
|
||||
),
|
||||
array(
|
||||
'class' => ['views-hide-label'],
|
||||
],
|
||||
[
|
||||
'data' => t('Remove'),
|
||||
'class' => array('views-hide-label'),
|
||||
),
|
||||
);
|
||||
$variables['ungroupable_table'] = array(
|
||||
'class' => ['views-hide-label'],
|
||||
],
|
||||
];
|
||||
$variables['ungroupable_table'] = [
|
||||
'#type' => 'table',
|
||||
'#header' => $header,
|
||||
'#rows' => $ungroupable_rows,
|
||||
'#attributes' => array(
|
||||
'#attributes' => [
|
||||
'id' => 'views-rearrange-filters-ungroupable',
|
||||
'class' => array('arrange'),
|
||||
),
|
||||
'#tabledrag' => array(
|
||||
array(
|
||||
'class' => ['arrange'],
|
||||
],
|
||||
'#tabledrag' => [
|
||||
[
|
||||
'action' => 'order',
|
||||
'relationship' => 'sibling',
|
||||
'group' => 'weight',
|
||||
)
|
||||
),
|
||||
);
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
if (empty($rows)) {
|
||||
$rows[] = array(array('data' => t('No fields available.'), 'colspan' => '2'));
|
||||
$rows[] = [['data' => t('No fields available.'), 'colspan' => '2']];
|
||||
}
|
||||
|
||||
// Set up tabledrag so that the weights are changed when rows are dragged.
|
||||
$variables['table'] = array(
|
||||
$variables['table'] = [
|
||||
'#type' => 'table',
|
||||
'#rows' => $rows,
|
||||
'#attributes' => array(
|
||||
'#attributes' => [
|
||||
'id' => 'views-rearrange-filters',
|
||||
'class' => array('arrange'),
|
||||
),
|
||||
'#tabledrag' => array(
|
||||
array(
|
||||
'class' => ['arrange'],
|
||||
],
|
||||
'#tabledrag' => [
|
||||
[
|
||||
'action' => 'order',
|
||||
'relationship' => 'sibling',
|
||||
'group' => 'weight',
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// When JavaScript is enabled, the button for adding a new group should be
|
||||
// hidden, since it will be replaced by a link on the client side.
|
||||
@@ -371,72 +397,72 @@ function template_preprocess_views_ui_rearrange_filter_form(&$variables) {
|
||||
function template_preprocess_views_ui_style_plugin_table(&$variables) {
|
||||
$form = $variables['form'];
|
||||
|
||||
$header = array(
|
||||
$header = [
|
||||
t('Field'),
|
||||
t('Column'),
|
||||
t('Align'),
|
||||
t('Separator'),
|
||||
array(
|
||||
[
|
||||
'data' => t('Sortable'),
|
||||
'align' => 'center',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'data' => t('Default order'),
|
||||
'align' => 'center',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'data' => t('Default sort'),
|
||||
'align' => 'center',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'data' => t('Hide empty column'),
|
||||
'align' => 'center',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'data' => t('Responsive'),
|
||||
'align' => 'center',
|
||||
),
|
||||
);
|
||||
$rows = array();
|
||||
],
|
||||
];
|
||||
$rows = [];
|
||||
foreach (Element::children($form['columns']) as $id) {
|
||||
$row = array();
|
||||
$row = [];
|
||||
$row[]['data'] = $form['info'][$id]['name'];
|
||||
$row[]['data'] = $form['columns'][$id];
|
||||
$row[]['data'] = $form['info'][$id]['align'];
|
||||
$row[]['data'] = $form['info'][$id]['separator'];
|
||||
|
||||
if (!empty($form['info'][$id]['sortable'])) {
|
||||
$row[] = array(
|
||||
$row[] = [
|
||||
'data' => $form['info'][$id]['sortable'],
|
||||
'align' => 'center',
|
||||
);
|
||||
$row[] = array(
|
||||
];
|
||||
$row[] = [
|
||||
'data' => $form['info'][$id]['default_sort_order'],
|
||||
'align' => 'center',
|
||||
);
|
||||
$row[] = array(
|
||||
];
|
||||
$row[] = [
|
||||
'data' => $form['default'][$id],
|
||||
'align' => 'center',
|
||||
);
|
||||
];
|
||||
}
|
||||
else {
|
||||
$row[] = '';
|
||||
$row[] = '';
|
||||
$row[] = '';
|
||||
}
|
||||
$row[] = array(
|
||||
$row[] = [
|
||||
'data' => $form['info'][$id]['empty_column'],
|
||||
'align' => 'center',
|
||||
);
|
||||
$row[] = array(
|
||||
];
|
||||
$row[] = [
|
||||
'data' => $form['info'][$id]['responsive'],
|
||||
'align' => 'center',
|
||||
);
|
||||
];
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
// Add the special 'None' row.
|
||||
$rows[] = array(array('data' => t('None'), 'colspan' => 6), array('align' => 'center', 'data' => $form['default'][-1]), array('colspan' => 2));
|
||||
$rows[] = [['data' => t('None'), 'colspan' => 6], ['align' => 'center', 'data' => $form['default'][-1]], ['colspan' => 2]];
|
||||
|
||||
// Unset elements from the form array that are used to build the table so that
|
||||
// they are not rendered twice.
|
||||
@@ -444,12 +470,12 @@ function template_preprocess_views_ui_style_plugin_table(&$variables) {
|
||||
unset($form['info']);
|
||||
unset($form['columns']);
|
||||
|
||||
$variables['table'] = array(
|
||||
$variables['table'] = [
|
||||
'#type' => 'table',
|
||||
'#theme' => 'table__views_ui_style_plugin_table',
|
||||
'#header' => $header,
|
||||
'#rows' => $rows,
|
||||
);
|
||||
];
|
||||
$variables['form'] = $form;
|
||||
}
|
||||
|
||||
@@ -510,14 +536,14 @@ function template_preprocess_views_ui_view_preview_section(&$variables) {
|
||||
}
|
||||
|
||||
if (isset($links)) {
|
||||
$build = array(
|
||||
$build = [
|
||||
'#theme' => 'links__contextual',
|
||||
'#links' => $links,
|
||||
'#attributes' => array('class' => array('contextual-links')),
|
||||
'#attached' => array(
|
||||
'library' => array('contextual/drupal.contextual-links'),
|
||||
),
|
||||
);
|
||||
'#attributes' => ['class' => ['contextual-links']],
|
||||
'#attached' => [
|
||||
'library' => ['contextual/drupal.contextual-links'],
|
||||
],
|
||||
];
|
||||
$variables['links'] = $build;
|
||||
}
|
||||
}
|
||||
@@ -526,5 +552,5 @@ function template_preprocess_views_ui_view_preview_section(&$variables) {
|
||||
* Implements hook_theme_suggestions_HOOK().
|
||||
*/
|
||||
function views_ui_theme_suggestions_views_ui_view_preview_section(array $variables) {
|
||||
return array('views_ui_view_preview_section__' . $variables['section']);
|
||||
return ['views_ui_view_preview_section__' . $variables['section']];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user