You are here

function quickedit_library_info_alter in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/quickedit/quickedit.module \quickedit_library_info_alter()
  2. 10 core/modules/quickedit/quickedit.module \quickedit_library_info_alter()

Implements hook_library_info_alter().

Includes additional stylesheets defined by the admin theme to allow it to customize the Quick Edit toolbar appearance.

An admin theme can specify CSS files to make the front-end administration experience of in-place editing match the administration experience in the back-end.

The CSS files can be specified via the "edit_stylesheets" property in the .info.yml file:

quickedit_stylesheets:
-css / quickedit . css;

File

core/modules/quickedit/quickedit.module, line 76
Provides in-place content editing functionality for fields.

Code

function quickedit_library_info_alter(&$libraries, $extension) {
  if ($extension === 'quickedit' && isset($libraries['quickedit'])) {
    $theme = Drupal::config('system.theme')
      ->get('admin');

    // First let the base theme modify the library, then the actual theme.
    $alter_library = function (&$library, $theme) use (&$alter_library) {
      if (!empty($theme) && ($theme_path = drupal_get_path('theme', $theme))) {
        $info = \Drupal::service('extension.list.theme')
          ->getExtensionInfo($theme);

        // Recurse to process base theme(s) first.
        if (isset($info['base theme'])) {
          $alter_library($library, $info['base theme']);
        }
        if (isset($info['quickedit_stylesheets'])) {
          foreach ($info['quickedit_stylesheets'] as $path) {
            $library['css']['theme']['/' . $theme_path . '/' . $path] = [];
          }
        }
      }
    };
    $alter_library($libraries['quickedit'], $theme);
  }
}