不完整的库定义 drupal 8
Incomplete library definition drupal 8
您好,我收到以下错误。这段代码有什么问题?我正在尝试添加 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',
),
),
);
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'
*.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: {}
如果您的图书馆在 module/extension 中定义,则每个图书馆条目都应包含以下所有必填字段:
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
我不知道为什么需要 drupalSettings
条目,但似乎是这样。
您好,我收到以下错误。这段代码有什么问题?我正在尝试添加 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',
),
),
);
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'
*.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: {}
如果您的图书馆在 module/extension 中定义,则每个图书馆条目都应包含以下所有必填字段:
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
我不知道为什么需要 drupalSettings
条目,但似乎是这样。