Skip to content

Commit

Permalink
Merge branch 'backdrop:1.x' into issue_6303
Browse files Browse the repository at this point in the history
  • Loading branch information
kiamlaluno committed Mar 22, 2024
2 parents e2adb25 + 266a501 commit 97618e7
Show file tree
Hide file tree
Showing 11 changed files with 490 additions and 32 deletions.
1 change: 0 additions & 1 deletion core/includes/common.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4702,7 +4702,6 @@ function backdrop_add_js($data = NULL, $options = NULL) {
// Register all required libraries.
backdrop_add_library('system', 'jquery', TRUE);
backdrop_add_library('system', 'jquery.once', TRUE);
backdrop_add_library('system', 'html5shiv', TRUE);
}

switch ($options['type']) {
Expand Down
14 changes: 14 additions & 0 deletions core/misc/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,20 @@ Backdrop.ajax.prototype.beforeSerialize = function (element, options) {
if (this.form) {
var settings = this.settings || Backdrop.settings;
Backdrop.detachBehaviors(this.form, settings, 'serialize');

// Ensure Backdrop isn't vulnerable to the bugs disclosed in the unmerged
// pull request: https://github.com/jquery-form/form/pull/586.
// - Under normal circumstances, the first if statement doesn't evaluate
// to true, because options.dataType is initialized in the Drupal.ajax()
// constructor.
// - Under normal circumstances, the second if statement doesn't evaluate
// to true, because $.parseJSON is initialized by jQuery.
if (!options.dataType && options.target) {
delete options.target;
}
if (!$.parseJSON) {
$.parseJSON = JSON.parse;
}
}

// Prevent duplicate HTML ids in the returned markup.
Expand Down
35 changes: 31 additions & 4 deletions core/misc/autosubmit.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,37 @@
Backdrop.behaviors.autosubmit = {
attach: function(context) {
// 'this' references the form element
function triggerSubmit (e) {
function triggerSubmit (element) {
var $this = $(this);

// Variable "element" will have a value only when text fields trigger
// this. If element is undefined, then remove the data to prevent
// potential focus on a previously processed element.
if (element === undefined) {
$('body').removeData('autosubmit-last-focus-id');
}
else {
$('body').data('autosubmit-last-focus-id', $(element).attr('id'));
}

// Submit the form.
$this.find('.autosubmit-click').trigger('click');
}

// the change event bubbles so we only need to bind it to the outer form
// Listener to ajaxStop will re-focus on the text field as needed.
$(document).off('ajaxStop.autosubmit').on('ajaxStop.autosubmit', function () {
let id = $('body').data('autosubmit-last-focus-id');
if (id === undefined) {
return;
}
let $textInput = $('#' + id);
let pos = $textInput.val().length;
$textInput.focus();
$textInput[0].setSelectionRange(pos, pos);
$('body').removeData('autosubmit-last-focus-id');
});

// The change event bubbles so we only need to bind it to the outer form.
$('form.autosubmit-full-form', context)
.add('.autosubmit', context)
.filter('form, select, input:not(:text, :submit)')
Expand Down Expand Up @@ -86,12 +111,14 @@ Backdrop.behaviors.autosubmit = {
})
.on('keyup', function(e) {
if ($.inArray(e.keyCode, discardKeyCode) === -1) {
timeoutID = setTimeout($.proxy(triggerSubmit, this.form), 500);
// Provide the target element to triggerSubmit.
timeoutID = setTimeout($.proxy(triggerSubmit, this.form, e.target), 500);
}
})
.on('change', function (e) {
if ($.inArray(e.keyCode, discardKeyCode) === -1) {
timeoutID = setTimeout($.proxy(triggerSubmit, this.form), 500);
// Provide the target element to triggerSubmit.
timeoutID = setTimeout($.proxy(triggerSubmit, this.form, e.target), 500);
}
});
});
Expand Down
1 change: 1 addition & 0 deletions core/modules/dashboard/dashboard.info
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ version = BACKDROP_VERSION
type = module
backdrop = 1.x
configure = admin/dashboard/settings
dependencies[] = layout
5 changes: 5 additions & 0 deletions core/modules/filter/filter.module
Original file line number Diff line number Diff line change
Expand Up @@ -2670,6 +2670,11 @@ function _filter_image_align($text) {
if ($parent && $parent->nodeName === 'figure') {
$target = $parent;
}
// Consider more deeply nested structures. A link wrapped around a
// captioned image.
elseif ($parent && $parent->nodeName === 'a' && $parent->parentNode && $parent->parentNode->nodeName === 'figure') {
$target = $parent->parentNode;
}
else {
$target = $node;
}
Expand Down
11 changes: 10 additions & 1 deletion core/modules/node/node.types.inc
Original file line number Diff line number Diff line change
Expand Up @@ -418,16 +418,25 @@ function node_type_form($form, &$form_state, $type = NULL) {
);
$form['revision']['revision']['revision_enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Show option to create new revisions'),
'#title' => t('Enable option to create revisions'),
'#default_value' => $type->settings['revision_enabled'],
'#parents' => array('revision_enabled'),
'#description' => t('Revisions allow content editors to view changes over time and revert changes if needed.'),
);
$form['revision']['revision']['revision_default'] = array(
'#type' => 'checkbox',
'#title' => t('Create new revision by default'),
'#description' => t('If enabled, revisions to content will be created by default. People with the "Administer content" permission will see an option to create a revision.'),
'#default_value' => $type->settings['revision_default'],
'#parents' => array('revision_default'),
'#states' => array(
'visible' => array(
'input[name="revision_enabled"]' => array('checked' => TRUE),
),
'enabled' => array(
'input[name="revision_enabled"]' => array('checked' => TRUE),
),
),
);

// Menu settings.
Expand Down
1 change: 1 addition & 0 deletions core/modules/translation/translation.module
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function translation_menu() {
'access callback' => '_translation_tab_access',
'access arguments' => array(1),
'type' => MENU_LOCAL_TASK,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'weight' => 2,
'file' => 'translation.pages.inc',
);
Expand Down
31 changes: 19 additions & 12 deletions core/modules/views/handlers/views_handler_field_math.inc
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,31 @@ class views_handler_field_math extends views_handler_field_numeric {

// The rest is directly from views_handler_field_numeric but because it
// does not allow the value to be passed in, it is copied.
if (!empty($this->options['set_precision'])) {
$value = number_format($value, $this->options['precision'], $this->options['decimal'], $this->options['separator']);
}
else {
$remainder = abs($value) - intval(abs($value));
$value = $value > 0 ? floor($value) : ceil($value);
$value = number_format($value, 0, '', $this->options['separator']);
if ($remainder) {
// The substr may not be locale safe.
$value .= $this->options['decimal'] . substr($remainder, 2);
}
}

// Check to see if hiding should happen before adding prefix and suffix.
if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) {
return '';
}

if (!empty($this->options['set_precision'])) {
$precision = $this->options['precision'];
}
elseif ($decimal_position = strpos($value, '.')) {
$precision = strlen(rtrim($value, '0')) - $decimal_position - 1;
}
else {
$precision = 0;
}

// Use round first to avoid negative zeros.
$value = round($value, $precision);
// Test against both integer zero and float zero.
if ($this->options['empty_zero'] && ($value === 0 || $value === 0.0)) {
return '';
}

$value = number_format($value, $precision, $this->options['decimal'], $this->options['separator']);

// Should we format as a plural.
if (!empty($this->options['format_plural']) && ($value != 0 || !$this->options['empty_zero'])) {
$value = format_plural($value, $this->options['format_plural_singular'], $this->options['format_plural_plural']);
Expand Down
30 changes: 18 additions & 12 deletions core/modules/views/handlers/views_handler_field_numeric.inc
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,29 @@ class views_handler_field_numeric extends views_handler_field {
return '';
}

// Check to see if hiding should happen before adding prefix and suffix.
if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) {
return '';
}

if (!empty($this->options['set_precision'])) {
$value = number_format($value, $this->options['precision'], $this->options['decimal'], $this->options['separator']);
$precision = $this->options['precision'];
}
elseif ($decimal_position = strpos($value, '.')) {
$precision = strlen(rtrim($value, '0')) - $decimal_position - 1;
}
else {
$remainder = abs($value) - intval(abs($value));
$value = $value > 0 ? floor($value) : ceil($value);
$value = number_format($value, 0, '', $this->options['separator']);
if ($remainder) {
// The substr may not be locale safe.
$value .= $this->options['decimal'] . substr($remainder, 2);
}
$precision = 0;
}

// Check to see if hiding should happen before adding prefix and suffix.
if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) {
return '';
}
// Use round first to avoid negative zeros.
$value = round($value, $precision);
// Test against both integer zero and float zero.
if ($this->options['empty_zero'] && ($value === 0 || $value === 0.0)) {
return '';
}

$value = number_format($value, $precision, $this->options['decimal'], $this->options['separator']);

// Should we format as a plural.
if (!empty($this->options['format_plural'])) {
Expand Down
45 changes: 43 additions & 2 deletions core/modules/views/tests/handlers/views_handler_field_math.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,24 @@ require_once BACKDROP_ROOT . '/core/modules/views/tests/views_query.test';
* Tests the core views_handler_field_math handler.
*/
class ViewsHandlerFieldMath extends ViewsSqlTest {
function viewsData() {

/**
* {@inheritdoc}
*/
protected $profile = 'testing';

/**
* {@inheritdoc}
*/
protected function viewsData() {
$data = parent::viewsData();
return $data;
}

public function testFieldCustom() {
/**
* Test basic field functionality.
*/
protected function testFieldCustom() {
$view = $this->getBasicView();

// Alter the text of the field to a random string.
Expand All @@ -35,4 +47,33 @@ class ViewsHandlerFieldMath extends ViewsSqlTest {

$this->assertEqual($rand1 + $rand2, $view->style_plugin->get_field(0, 'expression'));
}

/**
* Test rendering of float values in "Global: Math expression" fields.
*/
protected function testMathFloatRender() {
// We need one dummy node of any type for our node based views query.
$type = $this->backdropCreateContentType();
$this->backdropCreateNode(array(
'type' => $type->type,
));
$view = views_get_view('floatval_check');
$this->executeView($view);
$result = $view->result[0];

foreach ($view->field as $name => $view_field) {
if ($name == 'nid') {
continue;
}
// In the view we set the label value to the raw input value (floats), to
// compare rendered output here.
$label = $view->field[$name]->label();
$render = $view->field[$name]->advanced_render($result);
$this->assertIdentical($label, $render, format_string('Expected rendered output to be %label, got %render', array(
'%label' => $label,
'%render' => $render,
)));
}
}

}

0 comments on commit 97618e7

Please sign in to comment.