usort() deprecation on admin overview and PHP notice when creating a new snippet

Created on 4 December 2023, 12 months ago

In the current 2.0.2. release of content_snippets i am currently running into 2 warnings in the admin interface when using the module with PHP 8.1 on Drupal 10.1.5.

After creating a new snippet the following warning appears:

Warning: Trying to access array offset on value of type null in content_snippets_retrieve() (line 40 of modules/contrib/content_snippets/content_snippets.module).

This happens when in 'content_snippets_retrieve' a snippet is retrieved the following code is executed:

\Drupal::config('content_snippets.content')->get('snippets')[$snippetname]

In my installation \Drupal::config('content_snippets.content') is always empty. A examination of the further code seems to show the snippets are actually saved in '\Drupal::config('content_snippets.items')'.

The second error appears when visiting '/admin/config/content_snippets/admin'

Deprecated function: usort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in Drupal\content_snippets\Form\ContentSnippets->buildForm() (line 66 of modules/contrib/content_snippets/src/Form/ContentSnippets.php).

The patch attached to this issue solved both errors on my installation.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡³πŸ‡±Netherlands strakkie

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @strakkie
  • πŸ‡³πŸ‡±Netherlands strakkie
  • πŸ‡ΊπŸ‡ΈUnited States gcb

    @Strakkie Thanks for the patch!

    The warning fix is definitely needed. However, the other part breaks the module. The way this module works is that you create items, and then you add content to them. That's the content. Note the function "content_snippets_config()".

    Items include a name, a machine name, a type, and a description for your snippet. Those appear under the "Content -> Snippets" for site editors with the proper permissions to set values for those. So, you need to create the item and THEN set the value for it as separate tasks. The idea is that the sitebuilder or developer creates the items, and leaves it to the content editor to be able to change the text. This help make site content editable rather than hard-coded for custom usages.

  • Status changed to Fixed 12 months ago
  • πŸ‡ΊπŸ‡ΈUnited States gcb
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024