- Issue created by @sakiland
- Merge request !5Add extra check for item format in preprocess field fucntion. → (Open) created by sakiland
In the function ckeditor5_highlight_preprocess_field
for each item, editor is loaded
function ckeditor5_highlight_preprocess_field(array &$variables): void {
$items = $variables['element']['#items'];
if (!$items instanceof FieldItemListInterface) {
return;
}
foreach ($items as $item) {
if (!$item instanceof TextItemBase) {
continue;
}
$editor = \Drupal::entityTypeManager()
->getStorage('editor')
->load($item->format);
but, TextItemBase
doesn't ensure $item
has format
property defined (it's not required):
abstract class TextItemBase extends FieldItemBase {
/**
* {@inheritdoc}
*/
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['value'] = DataDefinition::create('string')
->setLabel(t('Text'))
->setRequired(TRUE);
$properties['format'] = DataDefinition::create('filter_format')
->setLabel(t('Text format'));
}
}
This can produce following error:
The website encountered an unexpected error. Please try again later.
AssertionError: Cannot load the "editor" entity with NULL ID. in assert() (line 295 of core/lib/Drupal/Core/Entity/EntityStorageBase.php).
assert(, 'Cannot load the "editor" entity with NULL ID.') (Line: 295)
Drupal\Core\Entity\EntityStorageBase->load(NULL) (Line: 29)
ckeditor5_highlight_preprocess_field(Array, 'field', Array)
call_user_func_array('ckeditor5_highlight_preprocess_field', Array) (Line: 287)
We just need to add extra check before entity storage load,
if (empty($item->format)) {
continue;
}
Active
1.1
Code