Commit 9d3a2280 authored by webchick's avatar webchick

Issue #2171071 by jessebeach, dawehner, chakrapani, longwave, Gábor Hojtsy,...

Issue #2171071 by jessebeach, dawehner, chakrapani, longwave, Gábor Hojtsy, xjm, Wim Leers: Rename drupal_add_library() to _drupal_add_library() and remove its uses.
parent 9a2cb6ad
......@@ -280,7 +280,7 @@ html5shiv:
remote: https://github.com/aFarkas/html5shiv
version: 3.6.2
js:
assets/vendor/html5shiv/html5.js: { weight: -22, browsers: { IE: 'lte IE 8', '!IE': false } }
assets/vendor/html5shiv/html5.js: { every_page: true, weight: -22, browsers: { IE: 'lte IE 8', '!IE': false } }
jquery:
remote: https://github.com/jquery/jquery
......
......@@ -2457,7 +2457,7 @@ function drupal_pre_render_scripts($elements) {
* FALSE if there were any missing library dependencies; TRUE if all library
* dependencies were met.
*
* @see drupal_add_library()
* @see _drupal_add_library()
* @see _drupal_add_js()
* @see _drupal_add_css()
* @see drupal_render()
......@@ -2473,7 +2473,7 @@ function drupal_process_attached($elements, $dependency_check = FALSE) {
// Add the libraries first.
$success = TRUE;
foreach ($elements['#attached']['library'] as $library) {
if (drupal_add_library($library) === FALSE) {
if (_drupal_add_library($library) === FALSE) {
$success = FALSE;
// Exit if the dependency is missing.
if ($dependency_check) {
......@@ -2672,7 +2672,7 @@ function drupal_process_states(&$elements) {
* @see drupal_get_library()
* @see hook_library_info_alter()
*/
function drupal_add_library($library_name, $every_page = NULL) {
function _drupal_add_library($library_name, $every_page = NULL) {
$added = &drupal_static(__FUNCTION__, array());
list($extension, $name) = explode('/', $library_name, 2);
......@@ -2731,7 +2731,7 @@ function drupal_add_library($library_name, $every_page = NULL) {
* or FALSE if it does not exist. If no $name was passed, an associative array
* of libraries registered by the module is returned (which may be empty).
*
* @see drupal_add_library()
* @see _drupal_add_library()
* @see hook_library_info_alter()
*
* @todo The purpose of drupal_get_*() is completely different to other page
......@@ -3894,6 +3894,12 @@ function drupal_render(&$elements, $is_recursive_call = FALSE) {
drupal_process_states($elements);
}
// Add additional libraries, CSS, JavaScript and other custom
// attached data associated with this element.
if (!empty($elements['#attached'])) {
drupal_process_attached($elements);
}
// Get the children of the element, sorted by weight.
$children = Element::children($elements, TRUE);
......@@ -3939,12 +3945,6 @@ function drupal_render(&$elements, $is_recursive_call = FALSE) {
$elements['#children'] = $elements['#markup'] . $elements['#children'];
}
// Add additional libraries, CSS, JavaScript an other custom
// attached data associated with this element.
if (!empty($elements['#attached'])) {
drupal_process_attached($elements);
}
// Let the theme functions in #theme_wrappers add markup around the rendered
// children.
// #states and #attached have to be processed before #theme_wrappers, because
......
......@@ -1600,7 +1600,7 @@ function form_process_container($element, &$form_state) {
function theme_tableselect($variables) {
$element = $variables['element'];
$table = array(
'#theme' => 'table',
'#type' => 'table',
);
$rows = array();
$header = $element['#header'];
......
......@@ -9,7 +9,7 @@
* @file
* Functions to aid in the creation of sortable tables.
*
* All tables created when rendering a '#theme' => 'table' have the option of
* All tables created when rendering a '#type' => 'table' have the option of
* having column headers that the user can click on to sort the table by that
* column.
*/
......@@ -33,7 +33,7 @@ function tablesort_init($header) {
* @param $cell
* The cell to format.
* @param $header
* An array of column headers in the format described in '#theme' => 'table'.
* An array of column headers in the format described in '#type' => 'table'.
* @param $ts
* The current table sort context as returned from tablesort_init().
*
......@@ -77,7 +77,7 @@ function tablesort_header($cell, $header, $ts) {
* @param $cell
* The cell to format.
* @param $header
* An array of column headers in the format described in '#theme' => 'table'.
* An array of column headers in the format described in '#type' => 'table'.
* @param $ts
* The current table sort context as returned from tablesort_init().
* @param $i
......@@ -113,7 +113,7 @@ function tablesort_get_query_parameters() {
* Determines the current sort criterion.
*
* @param $headers
* An array of column headers in the format described in '#theme' => 'table'.
* An array of column headers in the format described in '#type' => 'table'.
*
* @return
* An associative array describing the criterion, containing the keys:
......@@ -150,7 +150,7 @@ function tablesort_get_order($headers) {
* Determines the current sort direction.
*
* @param $headers
* An array of column headers in the format described in '#theme' => 'table'.
* An array of column headers in the format described in '#type' => 'table'.
*
* @return
* The current sort direction ("asc" or "desc").
......
......@@ -1416,6 +1416,24 @@ function drupal_pre_render_table(array $element) {
// Take over $element['#id'] as HTML ID attribute, if not already set.
element_set_attributes($element, array('id'));
// Add sticky headers, if applicable.
if (count($element['#header']) && $element['#sticky']) {
$element['#attached']['library'][] = 'core/drupal.tableheader';
// Add 'sticky-enabled' class to the table to identify it for JS.
// This is needed to target tables constructed by this function.
$element['#attributes']['class'][] = 'sticky-enabled';
}
// If the table has headers and it should react responsively to columns hidden
// with the classes represented by the constants RESPONSIVE_PRIORITY_MEDIUM
// and RESPONSIVE_PRIORITY_LOW, add the tableresponsive behaviors.
if (count($element['#header']) && $element['#responsive']) {
$element['#attached']['library'][] = 'core/drupal.tableresponsive';
// Add 'responsive-enabled' class to the table to identify it for JS.
// This is needed to target tables constructed by this function.
$element['#attributes']['class'][] = 'responsive-enabled';
}
// If the custom #tabledrag is set and there is a HTML ID, add the table's
// HTML ID to the options and attach the behavior.
if (!empty($element['#tabledrag']) && isset($element['#attributes']['id'])) {
......@@ -1523,23 +1541,6 @@ function theme_table($variables) {
$responsive = $variables['responsive'];
$empty = $variables['empty'];
// Add sticky headers, if applicable.
if (count($header) && $sticky) {
drupal_add_library('core/drupal.tableheader');
// Add 'sticky-enabled' class to the table to identify it for JS.
// This is needed to target tables constructed by this function.
$attributes['class'][] = 'sticky-enabled';
}
// If the table has headers and it should react responsively to columns hidden
// with the classes represented by the constants RESPONSIVE_PRIORITY_MEDIUM
// and RESPONSIVE_PRIORITY_LOW, add the tableresponsive behaviors.
if (count($header) && $responsive) {
drupal_add_library('core/drupal.tableresponsive');
// Add 'responsive-enabled' class to the table to identify it for JS.
// This is needed to target tables constructed by this function.
$attributes['class'][] = 'responsive-enabled';
}
$output = '<table' . new Attribute($attributes) . ">\n";
if (isset($caption)) {
......@@ -1967,6 +1968,28 @@ function _template_preprocess_default_variables() {
return $variables;
}
/**
* #pre_render callback for the html element type.
*
* @param array $element
* A structured array containing the html element type build properties.
*
* @see system_element_info()
*/
function drupal_pre_render_html(array $element) {
// Add favicon.
if (theme_get_setting('features.favicon')) {
$favicon = theme_get_setting('favicon.url');
$type = theme_get_setting('favicon.mimetype');
$element['#attached']['drupal_add_html_head_link'][][] = array(
'rel' => 'shortcut icon',
'href' => UrlHelper::stripDangerousProtocols($favicon),
'type' => $type,
);
}
return $element;
}
/**
* Prepares variables for HTML document templates.
*
......@@ -2016,18 +2039,6 @@ function template_preprocess_html(&$variables) {
$variables['html_attributes']['lang'] = $language_interface->id;
$variables['html_attributes']['dir'] = $language_interface->direction ? 'rtl' : 'ltr';
// Add favicon.
if (theme_get_setting('features.favicon')) {
$favicon = theme_get_setting('favicon.url');
$type = theme_get_setting('favicon.mimetype');
$build['#attached']['drupal_add_html_head_link'][][] = array(
'rel' => 'shortcut icon',
'href' => UrlHelper::stripDangerousProtocols($favicon),
'type' => $type,
);
drupal_render($build);
}
$site_config = \Drupal::config('system.site');
// Construct page title.
if ($page->hasTitle()) {
......@@ -2088,8 +2099,6 @@ function template_preprocess_html(&$variables) {
drupal_add_html_head($element, $name);
}
drupal_add_library('core/html5shiv', TRUE);
$variables['page_top'][] = array('#markup' => $page->getBodyTop());
$variables['page_bottom'][] = array('#markup' => $page->getBodyBottom());
......
......@@ -124,7 +124,7 @@ public function setDialogTitle($title) {
*/
public function render() {
// Add the library for handling the dialog in the response.
drupal_add_library('core/drupal.dialog.ajax');
$this->drupalAttachLibrary('core/drupal.dialog.ajax');
// For consistency ensure the modal option is set to TRUE or FALSE.
$this->dialogOptions['modal'] = isset($this->dialogOptions['modal']) && $this->dialogOptions['modal'];
......@@ -136,4 +136,19 @@ public function render() {
'dialogOptions' => $this->dialogOptions,
);
}
/**
* Wraps drupal_render.
*
* @param string $name
* The name of the library.
*
* @todo Remove once drupal_render is converted to autoloadable code.
* @see https://drupal.org/node/2171071
*/
protected function drupalAttachLibrary($name) {
$attached['#attached']['library'][] = $name;
drupal_render($attached);
}
}
......@@ -171,7 +171,7 @@ public function buildOperations(EntityInterface $entity) {
*/
public function render() {
$build = array(
'#theme' => 'table',
'#type' => 'table',
'#header' => $this->buildHeader(),
'#title' => $this->getTitle(),
'#rows' => array(),
......
......@@ -17,7 +17,7 @@ class DefaultHtmlPageRenderer implements HtmlPageRendererInterface {
*/
public function render(HtmlPage $page) {
$render = array(
'#theme' => 'html',
'#type' => 'html',
'#page_object' => $page,
);
return drupal_render($render);
......
......@@ -174,7 +174,7 @@ public function adminOverview() {
}
$build['feeds'] = array(
'#prefix' => '<h3>' . $this->t('Feed overview') . '</h3>',
'#theme' => 'table',
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => $this->t('No feeds available. <a href="@link">Add feed</a>.', array('@link' => $this->urlGenerator()->generateFromPath('admin/config/services/aggregator/add/feed'))),
......
......@@ -90,7 +90,7 @@ public function buildForm(array $form, array &$form_state, $default_ip = '') {
);
$form['ban_ip_banning_table'] = array(
'#theme' => 'table',
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => $this->t('No blocked IP addresses available.'),
......
......@@ -89,7 +89,7 @@ public function adminOverview() {
$rows[] = $row;
}
return array(
'#theme' => 'table',
'#type' => 'table',
'#header' => $headers,
'#rows' => $rows,
'#empty' => t('No books available.'),
......
......@@ -174,7 +174,7 @@ public function overviewBundles() {
}
$build['overview'] = array(
'#theme' => 'table',
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => $this->t('No comment forms available.'),
......
......@@ -115,7 +115,7 @@ public function diff($config_file) {
$build['#attached']['css'][] = drupal_get_path('module', 'system') . '/css/system.diff.css';
$build['diff'] = array(
'#theme' => 'table',
'#type' => 'table',
'#header' => array(
array('data' => t('Old'), 'colspan' => '2'),
array('data' => t('New'), 'colspan' => '2'),
......
......@@ -136,7 +136,7 @@ public function buildForm(array $form, array &$form_state) {
$storage_comparer = new StorageComparer($this->sourceStorage, $this->targetStorage);
if (empty($source_list) || !$storage_comparer->createChangelist()->hasChanges()) {
$form['no_changes'] = array(
'#theme' => 'table',
'#type' => 'table',
'#header' => array('Name', 'Operations'),
'#rows' => array(),
'#empty' => $this->t('There are no configuration changes.'),
......@@ -182,7 +182,7 @@ public function buildForm(array $form, array &$form_state) {
break;
}
$form[$config_change_type]['list'] = array(
'#theme' => 'table',
'#type' => 'table',
'#header' => array('Name', 'Operations'),
);
......
......@@ -53,7 +53,7 @@ public static function create(ContainerInterface $container) {
*/
public function render() {
$build = array(
'#theme' => 'table',
'#type' => 'table',
'#header' => $this->buildHeader(),
'#rows' => array(),
);
......
......@@ -136,7 +136,7 @@ function content_translation_overview(EntityInterface $entity) {
$build['#entity'] = $entity;
$build['content_translation_overview'] = array(
'#theme' => 'table',
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
);
......
......@@ -205,7 +205,7 @@ public function overview() {
}
$build['dblog_table'] = array(
'#theme' => 'table',
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#attributes' => array('id' => 'admin-dblog', 'class' => array('admin-dblog')),
......@@ -280,7 +280,7 @@ public function eventDetails($event_id) {
),
);
$build['dblog_table'] = array(
'#theme' => 'table',
'#type' => 'table',
'#rows' => $rows,
'#attributes' => array('class' => array('dblog-event')),
);
......@@ -379,7 +379,7 @@ public function topLogMessages($type) {
}
$build['dblog_top_table'] = array(
'#theme' => 'table',
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => $this->t('No log messages available.'),
......
......@@ -237,7 +237,7 @@ function field_ui_view_mode_delete(EntityViewModeInterface $view_mode) {
*/
function theme_field_ui_table($variables) {
$elements = $variables['elements'];
$table = array('#theme' => 'table');
$table = array('#type' => 'table');
// Add table headers and attributes.
foreach (array('#header', '#attributes') as $key) {
......
......@@ -271,7 +271,7 @@ function theme_file_formatter_table($variables) {
}
$build = array(
'#theme' => 'table',
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
);
......
......@@ -152,7 +152,7 @@ public function tips($long = FALSE) {
}
}
$table = array(
'#theme' => 'table',
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
);
......@@ -177,7 +177,7 @@ public function tips($long = FALSE) {
);
}
$table = array(
'#theme' => 'table',
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
);
......
......@@ -192,7 +192,7 @@ function theme_image_anchor($variables) {
}
$table = array(
'#theme' => 'table',
'#type' => 'table',
'#header' => array(),
'#rows' => $rows,
'#attributes' => array('class' => array('image-anchor')),
......
......@@ -140,7 +140,7 @@ function theme_language_negotiation_configure_browser_form_table($variables) {
);
$table = array(
'#theme' => 'table',
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#attributes' => array('id' => 'lang-neg-browser'),
......@@ -292,7 +292,7 @@ function template_preprocess_language_content_settings_table(&$variables) {
'#title' => $element['#title'],
'#header' => $header,
'#rows' => $rows,
'#theme' => 'table',
'#type' => 'table',
);
}
......
......@@ -121,9 +121,9 @@ function testExportTranslation() {
* Test exportation of translation template file.
*/
function testExportTranslationTemplateFile() {
// Load an admin page with JavaScript so drupal_add_library() fires at least
// once and _locale_parse_js_file() gets to run at least once so that the
// locales_source table gets populated with something.
// Load an admin page with JavaScript so _drupal_add_library() fires at
// least once and _locale_parse_js_file() gets to run at least once so that
// the locales_source table gets populated with something.
$this->drupalGet('admin/config/regional/language');
// Get the translation template file.
$this->drupalPostForm('admin/config/regional/translate/export', array(), t('Export'));
......
......@@ -36,7 +36,8 @@ public static function getInfo() {
* @see locale_library_info_alter()
*/
public function testLibraryInfoAlter() {
drupal_add_library('core/jquery.ui.datepicker');
$attached['#attached']['library'][] = 'core/jquery.ui.datepicker';
drupal_render($attached);
$scripts = drupal_get_js();
$this->assertTrue(strpos($scripts, 'locale.datepicker.js'), 'locale.datepicker.js added to scripts.');
}
......
......@@ -298,7 +298,7 @@ function theme_locale_translate_edit_form_strings($variables) {
);
}
$table = array(
'#theme' => 'table',
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('No strings available.'),
......
......@@ -898,7 +898,7 @@ function theme_node_search_admin($variables) {
$rows[] = $row;
}
$table = array(
'#theme' => 'table',
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
);
......
......@@ -175,7 +175,7 @@ function node_revision_overview($node) {
}
$build['node_revisions_table'] = array(
'#theme' => 'table',
'#type' => 'table',
'#rows' => $rows,
'#header' => $header,
'#attached' => array (
......
......@@ -89,7 +89,7 @@ function path_admin_overview($keys = NULL) {
}
$build['path_table'] = array(
'#theme' => 'table',
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('No URL aliases available. <a href="@link">Add URL alias</a>.', array('@link' => url('admin/config/search/path/add'))),
......
......@@ -172,7 +172,7 @@ public function buildForm(array $form, array &$form_state, $test_id = NULL) {
$form['result']['summary']['#' . $assertion->status]++;
}
$form['result']['results'][$group]['table'] = array(
'#theme' => 'table',
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
);
......
......@@ -395,7 +395,7 @@ function theme_system_modules_details($variables) {
}
$table = array(
'#theme' => 'table',
'#type' => 'table',
'#header' => $form['#header'],
'#rows' => $rows,
);
......@@ -459,7 +459,7 @@ function theme_system_modules_uninstall($variables) {
}
$table = array(
'#theme' => 'table',
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('No modules are available to uninstall.'),
......
......@@ -360,7 +360,7 @@ function hook_library_info_alter(&$libraries, $module) {
* @param string $name
* The name of the library.
*
* @see drupal_add_library()
* @see _drupal_add_library()
*/
function hook_library_alter(array &$library, $name) {
if ($name == 'core/jquery.ui.datepicker') {
......
......@@ -276,6 +276,14 @@ function system_hook_info() {
*/
function system_element_info() {
// Top level elements.
$types['html'] = array(
'#theme' => 'html',
'#pre_render' => array('drupal_pre_render_html'),
// HTML5 Shiv
'#attached' => array(
'library' => array('core/html5shiv'),
),
);
$types['form'] = array(
'#method' => 'post',
'#action' => request_uri(),
......@@ -611,6 +619,8 @@ function system_element_info() {
'#input' => TRUE,
'#tree' => TRUE,
'#tableselect' => FALSE,
'#sticky' => FALSE,
'#responsive' => TRUE,
'#multiple' => TRUE,
'#js_select' => TRUE,
'#value_callback' => 'form_type_table_value',
......@@ -1218,8 +1228,8 @@ function system_user_timezone(&$form, &$form_state) {
);
if (!$account->getTimezone() && $account->id() == $user->id() && empty($form_state['input']['timezone'])) {
$form['timezone']['#description'] = t('Your time zone setting will be automatically detected if possible. Confirm the selection and click save.');
$form['timezone']['#attached']['library'][] = 'core/drupal.timezone';
$form['timezone']['timezone']['#attributes'] = array('class' => array('timezone-detect'));
drupal_add_library('core/drupal.timezone');
}
}
......
......@@ -139,7 +139,7 @@ function tracker_page($account = NULL) {
$page['tracker'] = array(
'#rows' => $rows,
'#header' => array(t('Type'), t('Title'), t('Author'), t('Replies'), t('Last updated')),
'#theme' => 'table',
'#type' => 'table',
'#empty' => t('No content available.'),
);
$page['pager'] = array(
......
......@@ -267,7 +267,7 @@ function update_manager_update_form($form, $form_state = array(), $context) {
$prefix = '<h2>' . t('Manual updates required') . '</h2>';
$prefix .= '<p>' . t('Updates of Drupal core are not supported at this time.') . '</p>';
$form['manual_updates'] = array(
'#theme' => 'table',
'#type' => 'table',
'#header' => $headers,
'#rows' => $projects['manual'],
'#prefix' => $prefix,
......
......@@ -283,7 +283,7 @@ function theme_update_report($variables) {
ksort($rows[$type_name]);
$output .= "\n<h3>" . $type_label . "</h3>\n";
$table = array(
'#theme' => 'table',
'#type' => 'table',
'#header' => $header,
'#rows' => $rows[$type_name],
'#attributes' => array(
......
......@@ -131,7 +131,7 @@ public function ajaxView(Request $request) {
$view->dom_id = $dom_id;
$preview = $view->preview($display_id, $args);
$response->addCommand(new ReplaceCommand(".view-dom-id-$dom_id", drupal_render($preview)));
$response->addCommand(new ReplaceCommand(".view-dom-id-$dom_id", $this->drupalRender($preview)));
return $response;
}
else {
......@@ -143,4 +143,20 @@ public function ajaxView(Request $request) {
}
}
/**
* Wraps drupal_render.
*
* @param array $elements
* The structured array describing the data to be rendered.
*
* @return string
* The rendered HTML.
*
* @todo Remove once drupal_render is converted to autoloadable code.
* @see https://drupal.org/node/2171071
*/
protected function drupalRender(array $elements) {
return drupal_render($elements);
}
}
......@@ -58,7 +58,7 @@ protected function setUp() {
->disableOriginalConstructor()
->getMock();
$this->viewAjaxController = new ViewAjaxController($this->viewStorage, $this->executableFactory);
$this->viewAjaxController = new TestViewAjaxController($this->viewStorage, $this->executableFactory);
}
/**
......@@ -280,6 +280,18 @@ protected function assertViewResultCommand(ViewAjaxResponse $response, $position
}
/**
* Overrides ViewAjaxController::drupalRender to protect the parent method.
*/
class TestViewAjaxController extends ViewAjaxController {
// @todo Remove once drupal_render is converted to autoloadable code.
protected function drupalRender(array $elements) {
return isset($elements['#markup']) ? $elements['#markup'] : '';
}
}
}
namespace {
......@@ -290,11 +302,4 @@ function &drupal_static($key) {
}
}
// @todo Remove once drupal_render is converted to autoloadable code.
if (!function_exists('drupal_render')) {
function drupal_render($array) {
return isset($array['#markup']) ? $array['#markup'] : '';
}
}
}
......@@ -576,9 +576,9 @@ function hook_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
*
* @param array $rows
* An associative array with two keys:
* - query: An array of rows suitable for '#theme' => 'table', containing
* - query: An array of rows suitable for '#type' => 'table', containing
* information about the query and the display title and path.
* - statistics: An array of rows suitable for '#theme' => 'table',
* - statistics: An array of rows suitable for '#type' => 'table',
* containing performance statistics.
* @param \Drupal\views\ViewExecutable $view
* The view object.
......