Radioactivity not set when creating nodes in code

Created on 4 December 2022, almost 2 years ago
Updated 7 March 2024, 8 months ago

Problem/Motivation

When creating nodes programmatically (with Node::create()) no entry is added to the radioactivity table in the database. This happens because the Radioactivity entities are only managed by the RadioactivityReferenceWidget (radioactivity_reference) widget.

Steps to reproduce

  1. Set a Radioactivity Reference field on a content type.
  2. Give the reference field a non-zero default value.
  3. In a custom module, create a node programmatically.
  4. Check the radioactivity table in the database.
  5. Open the created page in the Drupal UI. Save the page.
  6. Note that the radioactivity table now has the correct entry in the database.

Proposed resolution

Radioactivity entities should be created / managed by the RadioactivityReferenceItem field type, not in the field widget.

Remaining tasks

  1. Done! βœ…
  2. Done! βœ…

User interface changes

Nothing at all.

API changes

  1. Existence of Radioactivity entities is guaranteed by the field type (unless entities are created by a sync operation).
  2. Radioactivity creation can be skipped by setting NULL as field value:

    EntityInterface::create(['field_name' => NULL])->save();

Data model changes

Nothing.

πŸ› Bug report
Status

Needs work

Version

4.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States oo0shiny

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024