Commit 596978a7 authored by catch's avatar catch

Issue #2378095 by Wim Leers, Devin Carlson: Convert all remaining attached...

Issue #2378095 by Wim Leers, Devin Carlson: Convert all remaining attached individual CSS/JS assets to attached asset libraries
parent d61f6195
......@@ -58,11 +58,11 @@ function _batch_page(Request $request) {
$build = array();
// Add batch-specific CSS.
// Add batch-specific libraries.
foreach ($batch['sets'] as $batch_set) {
if (isset($batch_set['css'])) {
foreach ($batch_set['css'] as $css) {
$build['#attached']['css'][$css] = array();
if (isset($batch_set['library'])) {
foreach ($batch_set['library'] as $library) {
$build['#attached']['library'][] = $library;
}
}
}
......
......@@ -162,9 +162,7 @@ public function form(array $form, FormStateInterface $form_state) {
'#prefix' => '<div id="edit-block-region-wrapper">',
'#suffix' => '</div>',
);
$form['#attached']['css'] = array(
drupal_get_path('module', 'block') . '/css/block.admin.css',
);
$form['#attached']['library'][] = 'block/drupal.block.admin';
return $form;
}
......
......@@ -6,3 +6,15 @@ drupal.book:
- core/jquery
- core/drupal
- core/drupal.form
navigation:
version: VERSION
css:
theme:
css/book.theme.css: {}
admin:
version: VERSION
css:
theme:
css/book.admin.css: {}
......@@ -163,9 +163,11 @@ function book_form_node_form_alter(&$form, FormStateInterface $form_state, $form
'#value' => t('Change book (update list of parents)'),
'#submit' => array('book_pick_book_nojs_submit'),
'#weight' => 20,
'#attached' => array(
'css' => array(drupal_get_path('module', 'book') . '/css/book.admin.css'),
),
'#attached' => [
'library' => [
'book/admin',
],
],
);
$form['#entity_builders'][] = 'book_node_builder';
}
......@@ -240,11 +242,11 @@ function book_node_view(array &$build, EntityInterface $node, EntityViewDisplayI
$build['book_navigation'] = array(
'#markup' => drupal_render($book_navigation),
'#weight' => 100,
'#attached' => array(
'css' => array(
drupal_get_path('module', 'book') . '/css/book.theme.css',
),
),
'#attached' => [
'library' => [
'book/navigation',
],
],
// The book navigation is a listing of Node entities, so associate its
// list cache tag for correct invalidation.
'#cache' => [
......
......@@ -18,3 +18,10 @@ drupal.color.preview:
- core/drupal
- core/drupalSettings
- core/jquery.once
admin:
version: VERSION
css:
theme:
css/color.admin.css: {}
......@@ -64,36 +64,6 @@ function color_form_system_theme_settings_alter(&$form, FormStateInterface $form
}
}
/**
* Implements hook_css_alter().
*
* Replaces style sheets with color-altered style sheets.
*/
function color_css_alter(&$css) {
$theme_key = \Drupal::theme()->getActiveTheme()->getName();
$themes = list_themes();
// Override stylesheets.
$color_paths = \Drupal::config('color.theme.' . $theme_key)->get('stylesheets');
if (!empty($color_paths) && !empty($themes[$theme_key]->stylesheets['all'])) {
foreach ($themes[$theme_key]->stylesheets['all'] as $old_path) {
// Loop over the path array with recolored CSS files to find matching
// paths which could replace the non-recolored paths.
foreach ($color_paths as $color_path) {
// Color module currently requires unique file names to be used,
// which allows us to compare different file paths.
if (drupal_basename($old_path) == drupal_basename($color_path)) {
// Replace the path to the new css file.
// This keeps the order of the stylesheets intact.
$css[drupal_basename($old_path)]['data'] = $color_path;
}
}
}
}
}
/**
* Implements hook_library_alter().
*
......@@ -240,10 +210,7 @@ function color_scheme_form($complete_form, FormStateInterface $form_state, $them
'#attached' => array(
'library' => array(
'color/drupal.color',
),
// Add custom CSS.
'css' => array(
$base . '/css/color.admin.css' => array(),
'color/admin',
),
// Add custom JavaScript.
'js' => array(
......@@ -297,15 +264,10 @@ function template_preprocess_color_scheme_form(&$variables) {
$theme = $form['theme']['#value'];
$info = $form['info']['#value'];
$path = drupal_get_path('theme', $theme) . '/';
if (isset($info['preview_css'])) {
$preview_css_path = $path . $info['preview_css'];
$form['scheme']['#attached']['css'][$preview_css_path] = array();
if (isset($info['preview_library'])) {
$form['scheme']['#attached']['library'][] = $info['preview_library'];
}
$preview_js_path = isset($info['preview_js']) ? $path . $info['preview_js'] : drupal_get_path('module', 'color') . '/' . 'preview.js';
// Add the JS at a weight below color.js.
$form['scheme']['#attached']['js'][$preview_js_path] = array('weight' => -1);
// Attempt to load preview HTML if the theme provides it.
$preview_html_path = \Drupal::root() . '/' . (isset($info['preview_html']) ? drupal_get_path('theme', $theme) . '/' . $info['preview_html'] : drupal_get_path('module', 'color') . '/preview.html');
......
......@@ -7,6 +7,12 @@ drupal.comment:
- core/drupal
- core/drupal.form
drupal.comment.threaded:
version: VERSION
css:
theme:
css/comment.theme.css: {}
drupal.comment-by-viewer:
version: VERSION
js:
......
......@@ -315,7 +315,7 @@ protected function alterBuild(array &$build, EntityInterface $comment, EntityVie
// Add indentation div or close open divs as needed.
if ($is_threaded) {
$build['#attached']['css'][] = drupal_get_path('module', 'comment') . '/css/comment.theme.css';
$build['#attached']['library'][] = 'comment/drupal.comment.threaded';
$prefix .= $comment->divs <= 0 ? str_repeat('</div>', abs($comment->divs)) : "\n" . '<div class="indented">';
}
......
......@@ -138,7 +138,7 @@ public function diff($source_name, $target_name = NULL, $collection = NULL) {
$build['#title'] = t('View changes of @config_file', array('@config_file' => $source_name));
// Add the CSS for the inline diff.
$build['#attached']['css'][] = drupal_get_path('module', 'system') . '/css/system.diff.css';
$build['#attached']['library'][] = 'system/diff';
$build['diff'] = array(
'#type' => 'table',
......
......@@ -79,7 +79,6 @@ function _content_translation_form_language_content_settings_form_alter(array &$
$form['entity_types']['#default_value'] = $default;
$form['#attached']['library'][] = 'content_translation/drupal.content_translation.admin';
$form['#attached']['js'][] = array('data' => drupal_get_path('module', 'content_translation') . '/content_translation.admin.js', 'type' => 'file');
$dependent_options_settings = array();
$entity_manager = Drupal::entityManager();
......
......@@ -88,7 +88,7 @@ public function testManager() {
$this->assertIdentical(array(), $this->editorManager->getAttachments(array()), 'No attachments when one text editor is enabled and retrieving attachments for zero text formats.');
$expected = array(
'library' => array(
0 => 'edit_test/unicorn',
0 => 'editor_test/unicorn',
),
'js' => array(
0 => array(
......
unicorn:
version: VERSION
js:
unicorn.js: {}
......@@ -60,7 +60,7 @@ function getJSSettings(EditorEntity $editor) {
*/
public function getLibraries(EditorEntity $editor) {
return array(
'edit_test/unicorn',
'editor_test/unicorn',
);
}
......
help:
version: VERSION
css:
component:
css/help.module.css: {}
......@@ -54,7 +54,7 @@ public static function create(ContainerInterface $container) {
public function helpMain() {
$output = array(
'#attached' => array(
'css' => array(drupal_get_path('module', 'help') . '/css/help.module.css'),
'library' => ['help/help'],
),
'#markup' => '<h2>' . $this->t('Help topics') . '</h2><p>' . $this->t('Help is available on the following items:') . '</p>' . $this->helpLinksAsList(),
);
......
form:
version: VERSION
css:
theme:
css/image.theme.css: {}
admin:
version: VERSION
css:
theme:
css/image.admin.css: {}
......@@ -69,7 +69,7 @@ public function buildForm(array $form, FormStateInterface $form_state, ImageStyl
throw new NotFoundHttpException();
}
$form['#attached']['css'][drupal_get_path('module', 'image') . '/css/image.admin.css'] = array();
$form['#attached']['library'][] = 'image/admin';
$form['uuid'] = array(
'#type' => 'value',
'#value' => $this->imageEffect->getUuid(),
......
......@@ -57,7 +57,7 @@ public function form(array $form, FormStateInterface $form_state) {
$user_input = $form_state->getUserInput();
$form['#title'] = $this->t('Edit style %name', array('%name' => $this->entity->label()));
$form['#tree'] = TRUE;
$form['#attached']['css'][drupal_get_path('module', 'image') . '/css/image.admin.css'] = array();
$form['#attached']['library'][] = 'image/admin';
// Show the thumbnail preview.
$preview_arguments = array('#theme' => 'image_style_preview', '#style' => $this->entity);
......
......@@ -158,7 +158,7 @@ public static function process($element, FormStateInterface $form_state, $form)
$item['fids'] = $element['fids']['#value'];
$element['#theme'] = 'image_widget';
$element['#attached']['css'][] = drupal_get_path('module', 'image') . '/css/image.theme.css';
$element['#attached']['library'][] = 'image/form';
// Add the image preview.
if (!empty($element['#files']) && $element['#preview_image_style']) {
......
......@@ -167,7 +167,6 @@ public function buildForm(array $form, FormStateInterface $form_state) {
);
$form['#attached']['library'][] = 'locale/drupal.locale.admin';
$form['#attached']['css'] = array(drupal_get_path('module', 'locale') . '/css/locale.admin.css');
$form['actions'] = array('#type' => 'actions');
if ($languages_update) {
......
drupal.node:
version: VERSION
css:
layout:
css/node.module.css: {}
js:
node.js: {}
dependencies:
......
......@@ -3,3 +3,8 @@ drupal.search.results:
css:
theme:
css/search.theme.css: {}
admin:
css:
theme:
css/search.admin.css: {}
......@@ -253,11 +253,11 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#attributes' => array(
'class' => array('container-inline'),
),
'#attached' => array(
'css' => array(
drupal_get_path('module', 'search') . '/css/search.admin.css',
),
),
'#attached' => [
'library' => [
'search/admin',
],
],
);
// In order to prevent validation errors for the parent form, this cannot be
// required, see self::validateAddSearchPage().
......
......@@ -152,7 +152,7 @@ function simpletest_run_tests($test_list) {
),
'finished' => '_simpletest_batch_finished',
'progress_message' => '',
'css' => array(drupal_get_path('module', 'simpletest') . '/css/simpletest.module.css'),
'library' => array('simpletest/drupal.simpletest'),
'init_message' => t('Processing test @num of @max - %test.', array('%test' => $info['name'], '@num' => '1', '@max' => count($test_list))),
);
batch_set($batch);
......
......@@ -118,7 +118,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $test_id
}
// Load all classes and include CSS.
$form['#attached']['css'][] = drupal_get_path('module', 'simpletest') . '/css/simpletest.module.css';
$form['#attached']['library'][] = 'simpletest/drupal.simpletest';
// Keep track of which test cases passed or failed.
$filter = array(
......
......@@ -134,7 +134,7 @@ public function testLazyLoad() {
'data' => $expected['css'],
'browsers' => array('IE' => TRUE, '!IE' => TRUE),
)), TRUE);
$expected_js_html = drupal_get_js('header', array($expected['js'] => drupal_js_defaults($expected['js'])), TRUE);
$expected_js_html = drupal_get_js('header', array($expected['js'] => ['version' => \Drupal::VERSION] + drupal_js_defaults($expected['js'])), TRUE);
// Get the base page.
$this->drupalGet('ajax_forms_test_lazy_load_form');
......
......@@ -44,3 +44,9 @@ drupal.system.modules:
- core/jquery
- core/drupal
- core/jquery.once
diff:
version: VERSION
css:
component:
css/system.diff.css: {}
......@@ -57,21 +57,20 @@ public function buildForm(array $form, FormStateInterface $form_state) {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
if ($form_state->getValue('add_files')) {
$path = drupal_get_path('module', 'system');
$attached = array(
'#attached' => array(
'css' => array(
$path . '/css/system.admin.css' => array(),
),
'js' => array(
0 => array(
$attached = [
'#attached' => [
'library' => [
'system/admin',
'system/drupal.system',
],
'js' => [
0 => [
'type' => 'setting',
'data' => array('ajax_forms_test_lazy_load_form_submit' => 'executed'),
),
$path . '/system.js' => array(),
),
),
);
'data' => ['ajax_forms_test_lazy_load_form_submit' => 'executed'],
],
],
],
];
drupal_render($attached);
drupal_process_attached($attached);
}
......
......@@ -34,9 +34,6 @@ function views_ajax_form_wrapper($form_class, FormStateInterface &$form_state) {
// These forms have the title built in, so set the title here:
$title = $form_state->get('title') ?: '';
if (!$ajax && $title) {
$form['#attached']['css'][] = drupal_get_path('module', 'views_ui') . '/css/views_ui.admin.css';
}
if ($ajax && (!$form_state->isExecuted() || $form_state->get('rerender'))) {
// If the form didn't execute and we're using ajax, build up a
......
......@@ -55,8 +55,7 @@ protected function prepareEntity() {
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state) {
$form['#attached']['css'] = static::getAdminCSS();
$form['#attached']['js'][] = drupal_get_path('module', 'views_ui') . '/js/views-admin.js';
$form['#attached']['library'][] = 'views_ui/admin.styling';
$form['#attributes']['class'] = array('views-admin');
$form['name'] = array(
......
......@@ -107,8 +107,7 @@ public function form(array $form, FormStateInterface $form_state) {
$form['#attached']['library'][] = 'core/drupal.states';
$form['#attached']['library'][] = 'core/drupal.tabledrag';
$form['#attached']['library'][] = 'views_ui/views_ui.admin';
$form['#attached']['css'] = static::getAdminCSS();
$form['#attached']['library'][] = 'views_ui/admin.styling';
$form['#attached']['js'][] = array(
'data' => array('views' => array('ajax' => array(
......
......@@ -78,27 +78,6 @@ protected function prepareEntity() {
}
}
/**
* Creates an array of Views admin CSS for adding or attaching.
*
* This returns an array of arrays. Each array represents a single
* file. The array format is:
* - file: The fully qualified name of the file to send to _drupal_add_css
* - options: An array of options to pass to _drupal_add_css.
*/
public static function getAdminCSS() {
$module_path = drupal_get_path('module', 'views_ui');
$list = array();
$list[$module_path . '/css/views_ui.admin.css'] = array();
$list[$module_path . '/css/views_ui.admin.theme.css'] = array();
if (\Drupal::moduleHandler()->moduleExists('contextual')) {
$list[$module_path . '/css/views_ui.contextual.css'] = array();
}
return $list;
}
/**
* Adds tabs for navigating across Displays when editing a View.
*
......
......@@ -174,7 +174,6 @@ public function render() {
$list['#type'] = 'container';
$list['#attributes']['id'] = 'views-entity-list';
$list['#attached']['css'] = ViewFormBase::getAdminCSS();
$list['#attached']['library'][] = 'core/drupal.ajax';
$list['#attached']['library'][] = 'views_ui/views_ui.listing';
......
......@@ -13,6 +13,7 @@ views_ui.admin:
- core/drupal.ajax
- core/drupal.dropbutton
- views/views.ajax
- views_ui/admin.styling
views_ui.listing:
version: VERSION
......@@ -22,3 +23,13 @@ views_ui.listing:
- core/jquery
- core/drupal
- core/jquery.once
- views_ui/admin.styling
admin.styling:
version: VERSION
css:
component:
css/views_ui.admin.css: {}
theme:
css/views_ui.admin.theme.css: {}
css/views_ui.contextual.css: {}
......@@ -7,6 +7,16 @@ global-styling:
css/colors.css: {}
css/print.css: { media: print }
color.preview:
version: VERSION
css:
theme:
color/preview.css: {}
js:
color/preview.js: {}
dependencies:
- color/drupal.color
maintenance_page:
version: VERSION
css:
......
......@@ -120,7 +120,6 @@
),
// Preview files.
'preview_css' => 'color/preview.css',
'preview_js' => 'color/preview.js',
'preview_library' => 'bartik/color.preview',
'preview_html' => 'color/preview.html',
);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment