Problem/Motivation

There's a problem reported in #2979440: EU Cookie Compliance expects specific text formats to exist. When you install the minimal profile from config export, an error is thrown due to filters not being available at install time.

Error: Call to a member function id() on bool in filter_default_format() (line 214 of /Users/svenbergryen/Sites/eu8/web/core/modules/filter/filter.module).

Steps to reproduce

1. Install drupal with minimal profile
2. Enable EU Cookie Compliance
3. Export config
4. Delete Database
5. drush si --existing-config
6. ERROR as above

Comments

svenryen created an issue. See original summary.

svenryen’s picture

I don't think this is a bug in our module. The problem is that no user is available when the default filter is looked up. I'm not sure what we can do about that.

I also tried the same procedure when starting from the Standard and Umami profiles, but the drush installer didn't support those.

Are you able to find a different profile that works when installing from Drush?
@jollysolutions - Is this something you typically do (Installing drupal with minimal profile through Drush)?

jollysolutions’s picture

I have found that adding

dependencies:
  module:
    - filter

to this modules exported config solves the issue

svenryen’s picture

I debugged it a bit further, and the problem is that \Drupal::entityTypeManager()->getStorage('filter_format')->loadByProperties(['status' => TRUE]) on line 114 in filter.module returns an empty array. I also tried to enforce that Drupal would use UID 1 when selecting the formats. The $format['all'] array was still empty.

I think the only recommendation I can use is to keep EU Cookie Compliance out of your config and enable it manually - either through UI or via Drush once Drupal is installed - this seems to be a weakness in either Drush si or Drupal core.

svenryen’s picture

Status: Active » Closed (works as designed)
jollysolutions’s picture

Status: Closed (works as designed) » Active

I agree that an empty array is returned but on an config install you are trying to get the default of something that hasn't got a default yet and the default can change depending on the permissions of the current user. Instead I think the module should use the fallback filter as this is always guaranteed to be available as per
https://api.drupal.org/api/drupal/core%21modules%21filter%21filter.modul...

Conversely, when existing content that does not have an assigned text format needs to be filtered for display, the default text format is the wrong choice, because it is not guaranteed to be consistent from user to user, and some trusted users may have an unsafe text format set by default, which should not be used on text of unknown origin. Instead, the fallback format returned by filter_fallback_format() should be used, since that is intended to be a safe, consistent format that is always available to all users.

And during module install the default configuration the module provides is "existing content" the module should use the fallback format.

jollysolutions’s picture

This is also not drush specific as it happens when installing from existing config using the web interface.

svenryen’s picture

Apologies that I stated it was a Drush specific problem. I take that back.

We added the part of the code that you're complaining about because a major issue was filed by several people that were having problems using the module at all when installing on the Lightning distribution (or on any site that doesn't have the Restricted HTML in config).

Your problem is different, and I haven't been able to find a way to fix it in code.

All I can conclude is at the time of installation, even user 1 doesn't have any text formats available when we're installing the module.

Have you tried with "fallback format" and does it work?

svenryen’s picture

I tried filter_fallback_format. It returns 'plain_text'. I still consider it a core bug that filter_default_format() doesn't work, and it would be more fruitful to figure out why that fails than having to force all users of the module to change the format from plain text to HTML after they have installed the module.

We can't set the format to 'plain text'.

svenryen’s picture

I also tried filter_fallback_format during a regular module install, and it seems to always return 'plain_text'.

I understand this is a problem for you, but I really can't fix the problem the way you suggest.

svenryen’s picture

Title: Error when installing minimal profile (config export) with Drush » Error when installing minimal profile (config export)
Status: Active » Needs review
StatusFileSize
new1.2 KB

Happy to say, here's a patch for you. It needs testing against the Lightning distribution before it can make it into the module.

svenryen’s picture

That being said, you do realize that with a config set from a minimal profile, your html will render as text for all banners in this module, so maybe a good solution for you would be to add at least one other text format to the config before you export?

Status: Needs review » Needs work
svenryen’s picture

Status: Needs work » Needs review
jollysolutions’s picture

Status: Needs review » Reviewed & tested by the community

Thank you very much for the patch. I can confirm that it does work for us. And in our case the config is only based on minimal has that is the only profile that does not have any install hooks and so can be installed as existing config. We have filters that do display the HTML correctly.

Tested with Lightning as per the original issue and works there. Marking as RTCB and thank you again.

  • svenryen committed cf16120 on 8.x-1.x
    Issue #3176439 by svenryen, jollysolutions: Error when installing...
svenryen’s picture

Status: Reviewed & tested by the community » Fixed
eiriksm’s picture

Hello, thanks for fixing this!

Could we get a new release with this fix? The current release is currently "unusable" for us.

Thanks again! :)

svenryen’s picture

You'll have a new release by Monday. I have a few more patches that I'd like to include.

dspachos’s picture

Hi! Any news about the upcoming new patch? We are interesting in the patch, since we have some failing tests in our case.

svenryen’s picture

As promised, there was a release by Monday. We included eu_cookie_compliance-error-when-installing-minimal-profile-config-export-3176439-11.patch in the release.

If you have problems, are they related to this issue? If not, could you please open a new issue. Thanks!

dspachos’s picture

Thanks very much! I'm going to try and I'll update here.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.