Skip to content
Snippets Groups Projects
Commit ddb69acd authored by Adam Nagy's avatar Adam Nagy Committed by Adam Nagy
Browse files

Issue #3375880: Fix CKEditor5 library dependency.

parent a0f4c549
No related branches found
No related tags found
1 merge request!47Issue #3375880: Fix CKEditor5 library dependency.
Pipeline #185089 passed with warnings
......@@ -8,4 +8,3 @@ maxlength:
- core/drupal
- core/once
- core/jquery
- ckeditor5/internal.drupal.ckeditor5
......@@ -239,3 +239,16 @@ function _maxlength_field_widget_form_alter_link_field(array &$element, FormStat
}
}
}
/**
* Implements hook_library_info_alter().
*/
function maxlength_library_info_alter(&$libraries, $extension) {
if ($extension === 'maxlength') {
// We only care about MaxLength.
$ckeditor5_enabled = \Drupal::moduleHandler()->moduleExists('ckeditor5');
if ($ckeditor5_enabled) {
$libraries['maxlength']['dependencies'][] = 'ckeditor5/internal.drupal.ckeditor5';
}
}
}
\ No newline at end of file
<?php
declare(strict_types=1);
namespace Drupal\Tests\maxlength\Kernel;
use Drupal\KernelTests\KernelTestBase;
/**
* Provides kernel tests MaxLength with CKEditor5.
*
* @group maxlength
*/
class MaxLengthCkeditorTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'maxlength',
'field',
'user',
'system',
];
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->installConfig(['maxlength']);
}
/**
* Tests the CKEditor5 library dependency.
*
* @covers maxlength_library_info_alter()
*/
public function testCkeditor5LibraryDependency() {
// Get the library discovery service.
/** @var \Drupal\Core\Asset\LibraryDiscovery $libraryDiscovery */
$library_discovery = $this->container->get('library.discovery');
$maxlength_library = $library_discovery->getLibraryByName('maxlength', 'maxlength');
$this->assertNotContains('ckeditor5/internal.drupal.ckeditor5', $maxlength_library['dependencies']);
// Now enable CKEditor5 module.
$this->container->get('module_installer')->install(['ckeditor5']);
$library_discovery->clearCachedDefinitions();
$maxlength_library = $library_discovery->getLibraryByName('maxlength', 'maxlength');
$this->assertContains('ckeditor5/internal.drupal.ckeditor5', $maxlength_library['dependencies']);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment