I have found a bug.
If snippet_manager configuration is imported on clean site, it will crash with error:
[error] Error: Call to a member function id() on boolean in filter_default_format() (line 212 of /var/www/html/web/core/modules/filter/filter.module) #0 /var/www/html/web/modules/contrib/snippet_manager/src/Entity/Snippet.php(276): filter_default_format()
The problem is that module is use text filters from core filter module. But module itself has no dependency to it. So if config imported before filter is installed via config, or even will be disabled on site, this will throw error.
I see two ways to fix it:
1. Add to module dependency to filter module. But it's seems not working, I don't know why but I tried and this not solve the problem.
2. This way is works and tested. We need to add filter module as dependency for configuration
dependencies: { }
replace by
dependencies:
module:
- filter
I interested, what way do you prefer and if second one, how to implement it. I found that dependencies can be set by variable plugins, but not for snippet itself which uses filter for template.
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | 2952920-18-snippet_manager_variable_collection.patch | 21.37 KB | chi |
| #8 | 2952920-3.patch | 2.48 KB | niklan |
| #7 | 2952920-2.patch | 1.13 KB | niklan |
| #4 | 2952920-1.patch | 325 bytes | niklan |
Comments
Comment #2
niklanComment #3
chi commentedWe should add a dependency on core filter module.
Comment #4
niklanI have added dependency for filter module, but it not working. Still need to add filter module depencency to config. I don't know why. I looked at
\Core\Config\Entity\ConfigEntityInterface::calculateDependencies()and\Drupal\Core\Config\Entity\ConfigEntityBase::addDependency()there is a comment:So we don't need to add module itself to config dependency. But there is the problem. I don't exactly understand how, but during the import, seems like snippet_manager is not enabled at this moment, and so, filter is no enabled too, which cause this error.
Comment #5
chi commentedShould be drupal:filter.
Comment #6
chi commentedPer the backtrace the error happens when Drupal\snippet_manager\Entity\Snippet object is being instantiated.
Comment #7
niklanThis patch is temporary fix for problem to get it working, before better solution will be found.
Comment #8
niklanThis patch adds dependency to configurations of filters used in formattable areas. Also it adds dependencies to modules which defines plugin variables used in snippet.
Comment #9
chi commentedSeems like Drupal core does not follow this approach. Note that in example below there is no dependency on basic_html format though it is used to format default value.
Another example is a View that has Text area plugin configured.
Comment #10
chi commented[error] Error: Call to a member function id() on boolean in filter_default_format() (line 212 of /var/www/html/web/core/modules/filter/filter.module) #0 /var/www/html/web/modules/contrib/snippet_manager/src/Entity/Snippet.php(276): filter_default_format()Per the error message you provided the error happened in filter_default_format() function which belongs to the filter module. This means that the filter module was enabled at that moment.
I guess it fails because the system has not available filter formats at all.
Comment #12
niklanSeems like this is the core problem of this issue, I didn't think about that.
I will test later patch from commit above. Looks like this is also fix it.
But what's about dependencies for modules which define custom SnippetManagerVariablePlugin in patch 3 from #8?
And last commit missing dependency drupal:filter for module itself.
Comment #13
chi commentedComment #17
niklanRTBC for 0608b96. This is fix main error for issue.
Comment #18
chi commentedIn attached patch snippet variables are bundled into lazy plugin collection. For such collections core configuration system magically applies some operation when the configuration entity is being processed. For instance it supports "bubbling" dependencies from the collected plugins. While the patch works well (at least tests passed) I am inclined not to commit it. We don't really need a lazy loader for snippet variable plugins and the level of complexity does not match the benefits we gain by using this plugin collection.
And besides, the patch changes the structure of snippet configuration entity. So that upgrade path is needed.
Comment #20
chi commentedI've just added a calculation of dependencies including filter formats. Thanks.