Skip to content

Commit

Permalink
Merge branch 'backdrop:1.x' into issue_5891
Browse files Browse the repository at this point in the history
  • Loading branch information
kiamlaluno committed Mar 22, 2024
2 parents 525a244 + 266a501 commit 7296f2c
Show file tree
Hide file tree
Showing 34 changed files with 723 additions and 257 deletions.
1 change: 0 additions & 1 deletion core/includes/common.inc
Expand Up @@ -4698,7 +4698,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
20 changes: 10 additions & 10 deletions core/includes/form.inc
Expand Up @@ -709,25 +709,25 @@ function form_load_include(&$form_state, $type, $module, $name = NULL) {
* build info array so that the reference can be preserved. For example, a
* form builder function with the following signature:
* @code
* function mymodule_form($form, &$form_state, &$object) {
* function my_module_form($form, &$form_state, &$object) {
* }
* @endcode
* would be called via backdrop_form_submit() as follows:
* @code
* $form_state['values'] = $my_form_values;
* $form_state['build_info']['args'] = array(&$object);
* backdrop_form_submit('mymodule_form', $form_state);
* backdrop_form_submit('my_module_form', $form_state);
* @endcode
* For example:
* @code
* // register a new user
* $form_state = array();
* $form_state['values']['name'] = 'new-user';
* $form_state['values']['mail'] = 'new.user@example.com';
* $form_state['values']['pass']['pass1'] = 'password';
* $form_state['values']['pass']['pass2'] = 'password';
* $form_state['values']['op'] = t('Create new account');
* backdrop_form_submit('user_register_form', $form_state);
* // Register a new user.
* $form_state = array();
* $form_state['values']['name'] = 'new-user';
* $form_state['values']['mail'] = 'new.user@example.com';
* $form_state['values']['pass']['pass1'] = 'password';
* $form_state['values']['pass']['pass2'] = 'password';
* $form_state['values']['op'] = t('Create new account');
* backdrop_form_submit('user_register_form', $form_state);
* @endcode
*/
function backdrop_form_submit($form_id, &$form_state) {
Expand Down
10 changes: 5 additions & 5 deletions core/includes/language.inc
Expand Up @@ -44,7 +44,7 @@ define('LANGUAGE_NEGOTIATION_DEFAULT', 'language-default');
* language (which by default inherits the interface language's values)
* configurable:
* @code
* function mymodule_language_types_info_alter(&$language_types) {
* function my_module_language_types_info_alter(&$language_types) {
* unset($language_types[LANGUAGE_TYPE_CONTENT]['fixed']);
* }
* @endcode
Expand Down Expand Up @@ -74,13 +74,13 @@ define('LANGUAGE_NEGOTIATION_DEFAULT', 'language-default');
* hook_language_negotiation_info_alter(). Here is an example snippet that lets
* path prefixes be ignored for administrative paths:
* @code
* function mymodule_language_negotiation_info_alter(&$negotiation_info) {
* function my_module_language_negotiation_info_alter(&$negotiation_info) {
* // Replace the core function with our own function.
* $negotiation_info[LANGUAGE_NEGOTIATION_URL]['callbacks']['language'] = 'mymodule_from_url';
* $negotiation_info[LANGUAGE_NEGOTIATION_URL]['file'] = backdrop_get_path('module', 'mymodule') . '/mymodule.module';
* $negotiation_info[LANGUAGE_NEGOTIATION_URL]['callbacks']['language'] = 'my_module_from_url';
* $negotiation_info[LANGUAGE_NEGOTIATION_URL]['file'] = backdrop_get_path('module', 'my_module') . '/my_module.module';
* }
*
* function mymodule_from_url($languages) {
* function my_module_from_url($languages) {
* // Use the core URL language negotiation provider to get a valid language
* // code.
* $langcode = locale_language_from_url($languages);
Expand Down
6 changes: 3 additions & 3 deletions core/includes/lock.inc
Expand Up @@ -26,11 +26,11 @@
* name of the function performing the operation. A very simple example use of
* this API:
* @code
* function mymodule_long_operation() {
* if (lock_acquire('mymodule_long_operation')) {
* function my_module_long_operation() {
* if (lock_acquire('my_module_long_operation')) {
* // Do the long operation here.
* // ...
* lock_release('mymodule_long_operation');
* lock_release('my_module_long_operation');
* }
* }
* @endcode
Expand Down
4 changes: 2 additions & 2 deletions core/includes/module.inc
Expand Up @@ -1049,7 +1049,7 @@ function backdrop_required_modules() {
* 'unalterable' => $unalterable,
* 'foo' => 'bar',
* );
* backdrop_alter('mymodule_data', $alterable1, $alterable2, $context);
* backdrop_alter('my_module_data', $alterable1, $alterable2, $context);
* @endcode
*
* Note that objects are always passed by reference in PHP5. If it is absolutely
Expand All @@ -1059,7 +1059,7 @@ function backdrop_required_modules() {
* $context = array(
* 'unalterable_object' => clone $object,
* );
* backdrop_alter('mymodule_data', $data, $context);
* backdrop_alter('my_module_data', $data, $context);
* @endcode
*
* @param $type
Expand Down
12 changes: 6 additions & 6 deletions core/includes/pager.inc
Expand Up @@ -55,14 +55,14 @@ function pager_find_page($element = 0) {
* @code
* // First find the total number of items and initialize the pager.
* $where = "status = 1";
* $total = mymodule_select("SELECT COUNT(*) FROM data " . $where)->result();
* $num_per_page = config_get('mymodule.settings', 'num_per_page');
* $total = my_module_select("SELECT COUNT(*) FROM data " . $where)->result();
* $num_per_page = config_get('my_module.settings', 'num_per_page');
* $page = pager_default_initialize($total, $num_per_page);
*
* // Next, retrieve and display the items for the current page.
* $offset = $num_per_page * $page;
* $result = mymodule_select("SELECT * FROM data " . $where . " LIMIT %d, %d", $offset, $num_per_page)->fetchAll();
* $output = theme('mymodule_results', array('result' => $result));
* $result = my_module_select("SELECT * FROM data " . $where . " LIMIT %d, %d", $offset, $num_per_page)->fetchAll();
* $output = theme('my_module_results', array('result' => $result));
*
* // Finally, display the pager controls, and return.
* $output .= theme('pager');
Expand All @@ -80,9 +80,9 @@ function pager_find_page($element = 0) {
* // parameter corresponds to an actual page of results that will exist
* // within the set.
* $page = pager_find_page();
* $num_per_page = config_get('mymodule.settings', 'num_per_page');
* $num_per_page = config_get('my_module.settings', 'num_per_page');
* $offset = $num_per_page * $page;
* $result = mymodule_remote_search($keywords, $offset, $num_per_page);
* $result = my_module_remote_search($keywords, $offset, $num_per_page);
*
* // Now that we have the total number of results, initialize the pager.
* pager_default_initialize($result->total, $num_per_page);
Expand Down
14 changes: 14 additions & 0 deletions core/misc/ajax.js
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
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
4 changes: 2 additions & 2 deletions core/modules/admin_bar/admin_bar.api.php
Expand Up @@ -75,8 +75,8 @@ function hook_admin_bar_output_build(&$content) {
$content['menu']['menu']['myitem'] = array(
'#title' => t('My item'),
// #attributes are used for list items (LI).
'#attributes' => array('class' => array('mymodule-myitem')),
'#href' => 'mymodule/path',
'#attributes' => array('class' => array('my_module-myitem')),
'#href' => 'my_module/path',
// #options are passed to l().
'#options' => array(
'query' => backdrop_get_destination(),
Expand Down
10 changes: 5 additions & 5 deletions core/modules/ckeditor/ckeditor.api.php
Expand Up @@ -80,10 +80,10 @@
*/
function hook_ckeditor_plugins() {
$plugins['myplugin'] = array(
'path' => backdrop_get_path('module', 'mymodule') . '/js/myplugin',
'path' => backdrop_get_path('module', 'my_module') . '/js/myplugin',
'file' => 'plugin.js',
'css' => array(backdrop_get_path('module', 'mymodule') . '/css/myplugin.css'),
'enabled callback' => 'mymodule_myplugin_plugin_check',
'css' => array(backdrop_get_path('module', 'my_module') . '/css/myplugin.css'),
'enabled callback' => 'my_module_myplugin_plugin_check',
'buttons' => array(
'MyPlugin' => array(
'label' => t('My custom button'),
Expand Down Expand Up @@ -113,7 +113,7 @@ function hook_ckeditor_plugins() {
* @see hook_ckeditor_plugins()
*/
function hook_ckeditor_plugins_alter(array &$plugins) {
$plugins['someplugin']['enabled callback'] = 'mymodule_someplugin_enabled_callback';
$plugins['someplugin']['enabled callback'] = 'my_module_someplugin_enabled_callback';
}

/**
Expand Down Expand Up @@ -143,7 +143,7 @@ function hook_ckeditor_plugins_alter(array &$plugins) {
* @see _ckeditor_theme_css()
*/
function hook_ckeditor_css_alter(array &$css, $format) {
$css[] = backdrop_get_path('module', 'mymodule') . '/css/mymodule-ckeditor.css';
$css[] = backdrop_get_path('module', 'my_module') . '/css/my_module-ckeditor.css';
}

/**
Expand Down
10 changes: 5 additions & 5 deletions core/modules/ckeditor5/ckeditor5.api.php
Expand Up @@ -72,9 +72,9 @@
*/
function hook_ckeditor5_plugins() {
$plugins['myPlugin.MyPlugin'] = array(
'library' => array('mymodule', 'mymodule.ckeditor5.myplugin'),
'css' => array(backdrop_get_path('module', 'mymodule') . '/css/myplugin.css'),
'enabled_callback' => 'mymodule_myplugin_plugin_check',
'library' => array('my_module', 'my_module.ckeditor5.myplugin'),
'css' => array(backdrop_get_path('module', 'my_module') . '/css/myplugin.css'),
'enabled_callback' => 'my_module_myplugin_plugin_check',
'buttons' => array(
'myButton' => array(
'library' => array('my_module', 'my-module-ckeditor5-plugin'),
Expand All @@ -101,7 +101,7 @@ function hook_ckeditor5_plugins() {
* @see hook_ckeditor5_plugins()
*/
function hook_ckeditor5_plugins_alter(array &$plugins) {
$plugins['someplugin']['enabled callback'] = 'mymodule_someplugin_enabled_callback';
$plugins['someplugin']['enabled callback'] = 'my_module_someplugin_enabled_callback';
}

/**
Expand Down Expand Up @@ -139,7 +139,7 @@ function hook_ckeditor5_plugins_alter(array &$plugins) {
* @see _ckeditor5_theme_css()
*/
function hook_ckeditor5_css_alter(array &$css) {
$css[] = backdrop_get_path('module', 'mymodule') . '/css/mymodule-ckeditor5.css';
$css[] = backdrop_get_path('module', 'my_module') . '/css/my_module-ckeditor5.css';
}

/**
Expand Down
24 changes: 14 additions & 10 deletions core/modules/config/config.api.php
Expand Up @@ -62,7 +62,7 @@ function hook_config_info() {
* @throws ConfigValidateException
*/
function hook_config_data_validate(Config $config, array $config_info) {
if ($config->getName() === 'mymodule.settings') {
if ($config->getName() === 'my_module.settings') {
if (!module_exists($config->get('module'))) {
throw new ConfigValidateException(t('The configuration "@file" could not be imported because the module "@module" is not enabled.', array('@file' => $config->getName(), '@module' => $config->get('module'))));
}
Expand All @@ -87,7 +87,7 @@ function hook_config_data_validate(Config $config, array $config_info) {
* @throws ConfigValidateException
*/
function hook_config_create_validate(Config $staging_config, $all_changes) {
if ($staging_config->getName() === 'mymodule.settings') {
if ($staging_config->getName() === 'my_module.settings') {
// Ensure that the name key is no longer than 64 characters.
if (strlen($staging_config->get('name')) > 64) {
throw new ConfigValidateException(t('The configuration "@file" must have a "name" attribute less than 64 characters.', array('@file' => $staging_config->getName())));
Expand Down Expand Up @@ -115,7 +115,7 @@ function hook_config_create_validate(Config $staging_config, $all_changes) {
* @throws ConfigValidateException
*/
function hook_config_update_validate(Config $staging_config, Config $active_config, $all_changes) {
if ($staging_config->getName() === 'mymodule.settings') {
if ($staging_config->getName() === 'my_module.settings') {
// Ensure that the name key is no longer than 64 characters.
if (strlen($staging_config->get('name')) > 64) {
throw new ConfigValidateException(t('The configuration "@file" must have a "name" attribute less than 64 characters.', array('@file' => $staging_config->getName())));
Expand Down Expand Up @@ -143,11 +143,15 @@ function hook_config_update_validate(Config $staging_config, Config $active_conf
function hook_config_delete_validate(Config $active_config, $all_changes) {
if (strpos($active_config->getName(), 'image.style') === 0) {
// Check if another configuration depends on this configuration.
if (!isset($all_changes['mymodule.settings']) || $all_changes['mymodule.settings'] !== 'delete') {
$my_config = config('mymodule.settings');
if (!isset($all_changes['my_module.settings']) || $all_changes['my_module.settings'] !== 'delete') {
$my_config = config('my_module.settings');
$image_style_name = $active_config->get('name');
if ($my_config->get('image_style') === $image_style_name) {
throw new ConfigValidateException(t('The configuration "@file" cannot be deleted because the image style "@style" is in use by "@mymodule".', array('@file' => $active_config->getName(), '@style' => $image_style_name, '@mymodule' => $my_config->getName())));
throw new ConfigValidateException(t('The configuration "@file" cannot be deleted because the image style "@style" is in use by "@my_module".', array(
'@file' => $active_config->getName(),
'@style' => $image_style_name,
'@my_module' => $my_config->getName(),
)));
}
}
}
Expand All @@ -172,9 +176,9 @@ function hook_config_create(Config $staging_config) {
* Respond to configuration updates.
*
* @param Config $staging_config
* The configuration object for the settings about to be saved. This object
* is always passed by reference and may be modified to adjust the settings
* that are saved.
* The configuration object for the settings about to be saved. This object is
* always passed by reference and may be modified to adjust the settings that
* are saved.
* @param Config $active_config
* The configuration object for the settings being replaced.
*/
Expand All @@ -199,7 +203,7 @@ function hook_config_update(Config $staging_config, Config $active_config) {
function hook_config_delete(Config $active_config) {
if (strpos($active_config->getName(), 'image.style') === 0) {
$image_style_name = $active_config->get('name');
config('mymodule.image_style_addons.' . $image_style_name)->delete();
config('my_module.image_style_addons.' . $image_style_name)->delete();
}
}

Expand Down
1 change: 1 addition & 0 deletions core/modules/dashboard/dashboard.info
Expand Up @@ -5,3 +5,4 @@ version = BACKDROP_VERSION
type = module
backdrop = 1.x
configure = admin/dashboard/settings
dependencies[] = layout
6 changes: 3 additions & 3 deletions core/modules/entity/entity.api.php
Expand Up @@ -219,7 +219,7 @@ function hook_entity_info_alter(&$entity_info) {
*/
function hook_entity_load($entities, $type) {
foreach ($entities as $entity) {
$entity->foo = mymodule_add_something($entity, $type);
$entity->foo = my_module_add_something($entity, $type);
}
}

Expand Down Expand Up @@ -379,7 +379,7 @@ function hook_entity_view($entity, $type, $view_mode, $langcode) {
$entity->content['my_additional_field'] = array(
'#markup' => $additional_field,
'#weight' => 10,
'#theme' => 'mymodule_my_additional_field',
'#theme' => 'my_module_my_additional_field',
);
}

Expand Down Expand Up @@ -431,7 +431,7 @@ function hook_entity_view_alter(&$build, $type) {
function hook_entity_prepare_view($entities, $type) {
// Load a specific node into the user object to theme later.
if ($type == 'user') {
$nodes = mymodule_get_user_nodes(array_keys($entities));
$nodes = my_module_get_user_nodes(array_keys($entities));
foreach ($entities as $uid => $entity) {
$entity->user_node = $nodes[$uid];
}
Expand Down

0 comments on commit 7296f2c

Please sign in to comment.