代码之家  ›  专栏  ›  技术社区  ›  U.N

库定义drupal 8不完整

  •  2
  • U.N  · 技术社区  · 9 年前

    你好,我收到以下错误。这个代码有什么问题?我正在尝试添加css。还在学习drupal 8。我想知道问题出在哪里。

    这是我添加css的片段。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的片段。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',
            ),
          ),
        );
    

    测试模块库.yml

    test_module_settings:
          path: '/hello/test'
          defaults:
            _controller: '\Drupal\test_module\Controller\TestModuleController::myCallbackMethod'
            _title: 'Hello World'
          requirements:
            _permission: 'view hello world'
    
    2 回复  |  直到 9 年前
        1
  •  4
  •   Je Suis Alrick    8 年前

    如果在模块/扩展中定义了库,则每个库条目应具有以下所有必填字段:

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

    你可以用你的 js , css drupalSettings 这样地:

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

    我不知道为什么 drupal设置 需要输入,但情况似乎如此。

        2
  •  2
  •   greg606    9 年前

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

    图书馆。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: {}