【问题标题】:Incomplete library definition drupal 8不完整的库定义drupal 8
【发布时间】:2015-12-23 12:11:32
【问题描述】:

您好,我收到以下错误。这段代码有什么问题?我正在尝试添加CSS。还在学习drupal 8。我想知道是什么问题。

这是我添加 css 的 sn-p。我的css文件夹和库中的css与路由yml文件处于同一级别。

The website encountered an unexpected error. Please try again later.

Drupal\Core\Asset\Exception\IncompleteLibraryDefinitionException: Incomplete library definition for definition 'test-module' in extension 'test_module' in Drupal\Core\Asset\LibraryDiscoveryParser->buildByExtension() (line 96 of core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php).

Drupal\Core\Asset\LibraryDiscoveryCollector->getLibraryDefinitions('test_module')
Drupal\Core\Asset\LibraryDiscoveryCollector->resolveCacheMiss('test_module')
Drupal\Core\Cache\CacheCollector->get('test_module')
Drupal\Core\Asset\LibraryDiscovery->getLibrariesByExtension('test_module')
Drupal\Core\Asset\LibraryDiscovery->getLibraryByName('test_module', 'test-module')
Drupal\Core\Asset\LibraryDependencyResolver->doGetDependencies(Array)
Drupal\Core\Asset\LibraryDependencyResolver->getLibrariesWithDependencies(Array)
Drupal\Core\Asset\AssetResolver->getLibrariesToLoad(Object)
Drupal\Core\Asset\AssetResolver->getCssAssets(Object, 1)
Drupal\Core\Render\HtmlResponseAttachmentsProcessor->processAssetLibraries(Object, Array)
Drupal\Core\Render\HtmlResponseAttachmentsProcessor->processAttachments(Object)
Drupal\Core\EventSubscriber\HtmlResponseSubscriber->onRespond(Object, 'kernel.response', Object)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.response', Object)
Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object, Object, 1)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1)
Stack\StackedHttpKernel->handle(Object, 1, 1)
Drupal\Core\DrupalKernel->handle(Object)

这是我添加 css 的 sn-p。我的css文件夹和库中的css与路由yml文件处于同一级别。

        $element = array(
      '#markup' => '<p><b>Saying Hello World in Drupal 8 is cool!</b></p>' . $content,
      '#attached' => array(
        'library' => array(
          'test_module/test-module',
        ),
      ),
    );

test_module.libraries.yml

test_module_settings:
      path: '/hello/test'
      defaults:
        _controller: '\Drupal\test_module\Controller\TestModuleController::myCallbackMethod'
        _title: 'Hello World'
      requirements:
        _permission: 'view hello world'

【问题讨论】:

  • 请提供您将 css 添加到模块的文件
  • @greg606 添加了 sn-p
  • 和 *.libraries.yml 文件的内容?
  • @greg606 添加了libraries.yml

标签: drupal drupal-8


【解决方案1】:

如果您的库是在您的模块/扩展中定义的,则每个库条目都应包含以下所有必填字段:

my-library-entry:
  js: {}
  css: {}
  drupalSettings: {}

您可以像这样用jscssdrupalSettings 替换花括号:

my-library-entry:
  js:
    misc/ajax.js: {}
  css:
    theme:
      css/cuddly-slider.css: {}
  drupalSettings:
    myDrupalSetting: null

我不知道为什么需要 drupalSettings 条目,但似乎是这样。

【讨论】:

    【解决方案2】:

    *.libraries.yml 的内容似乎不正确。这是应该进入 routing.yml 的内容。

    libraries.yml 应该看起来不同: https://www.drupal.org/developing/api/8/assets

    cuddly-slider:
      version: 1.x
      css:
        theme:
          css/cuddly-slider.css: {}
      js:
        js/cuddly-slider.js: {}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-30
      • 2013-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      相关资源
      最近更新 更多