localgovdrupal / localgov_news

Provides news articles and news listing pages for LocalGov Drupal
GNU General Public License v2.0
0 stars 2 forks source link

WSOD when trying to create a news article without a newsroom when localgov_microsites_group is < 4.0.0-alpha3 #127

Open chriswales95 opened 1 month ago

chriswales95 commented 1 month ago

Issue

We have discovered that a WSOD occurs if you try to create a news article, without creating a newsroom, when using localgov_microsites_group:4.0.0-alpha2 or less.

We have came across this issue on 2 of our client's microsite instances and I was able to replicate with a fresh microsite install locally.

The problematic code is:

// If there are no newsrooms display a warning.
    if (count($options) == 1 && isset($options['_none'])) {
      $create_newsroom_path = 'localgov_newsroom';
      if (\Drupal::moduleHandler()->moduleExists('localgov_microsites_group')) {
        // @phpstan-ignore-next-line Ignore the next line as this is only present on microsites.
        $group = localgov_microsites_group_get_by_context();
        // @phpstan-ignore-next-line Ignore the next line as this is only present on microsites.
        if ($group instanceof GroupInterface) {
          $create_newsroom_path = 'group_node:' . $create_newsroom_path;
        }
      }

      \Drupal::messenger()->addWarning(t('There are no Newsrooms. Please <a href="./@link">create a Newsroom</a> first, before creating this news article.', ['@link' => $create_newsroom_path]));
    }

I think the issue is that somewhere the dependencies are not correctly implemented.

I've had to pin our clients to version 2.3.5 until we're ready to go to version 4 of Microsites.

Reproduction Steps

I replicated this on Mac OS using Lando.

Follow these commands:

composer create-project --stability dev localgovdrupal/localgov_microsites_project microsites_d10 3.x-dev
cd microsites_d10
lando start
lando composer install
lando drush si localgov_microsites -y

Then

Workaround / Solution

Pin LocalGov News to version 2.3.5 for those on Version 3 of LocalGov Microsites.

millnut commented 2 weeks ago

So that error which causes the WSOD is due to localgov_microsites_group_get_by_context() only existing in localgov_microsites_group 4.x.

This PR introduced the change for localgov_news, and localgov_blogs is likely affected as well as it has similar code.

@finnlewis for microsites 3.x should we lock news and blogs to versions before that change?

stephen-cox commented 1 week ago

All development on Microsites < 4.x has stopped. Although I don't think we have officially stopped supporting them, we should deprecate them. Pinning dependencies at older versions to ensure the sites continue to work until they get updated sounds like a reasonable solution to me.

millnut commented 1 week ago

PR added https://github.com/localgovdrupal/localgov_microsites/pull/494 to lock both news and blogs to working versions