Drupal is a registered trademark of Dries Buytaert
Release: Drupal 10.3.6 Update released for Drupal core (10.3.6)! Release: Drupal 11.0.5 Update released for Drupal core (11.0.5)! Release: Drupal 10.2.9 Update released for Drupal core (10.2.9)! Release: Drupal 10.2.10 Update released for Drupal core (10.2.10)! Release: Drupal 10.3.7 Update released for Drupal core (10.3.7)! Release: Drupal 11.0.6 Update released for Drupal core (11.0.6)! Release: Drupal 10.3.8 Update released for Drupal core (10.3.8)! Release: Drupal 11.0.7 Update released for Drupal core (11.0.7)! Module Revived: Translation Management Tool 8.x-1.19 Module tmgmt updated after 7 months of inactivity (8.x-1.19). Usage Milestone: Account field split Module account_field_split crossed 10,000 active installs.

Utility module for use when developing custom or contributed modules with in-code saving of entities where you want to create a new revision.

Use it like this:

\Drupal::service('revision_helper.entity')->setRevision($node, TRUE, "Sync from data API.");

The motivation for this module was being frustrated that revisions were not automatic when a content type was set to make revisions by default, and then much further frustration that translateable entities needed a different set of steps. Ironically we are not yet accounting for that, this is what our custom code needed.

The line above is basically simply doing this:

      // Make this change a new revision
      $node->setNewRevision(TRUE);
      $node->revision_log = 'Sync from data API';
      $node->setRevisionCreationTime(REQUEST_TIME);
      $node->setRevisionUserId(11142);

with extra checks that revisions are available etc.

What we expect to have to add, when the use case comes up again and after a lot of testing, is a fallback/addition for translation-having content lke this:

      // This node type has translations, although it should not,
      // so for now we need this silliness to save a revision.
      $storage =\Drupal::entityTypeManager()->getStorage('node');
      $revision = $node->getTranslation(LanguageInterface::LANGCODE_DEFAULT);
      $revision->setRevisionCreationTime(\Drupal::time()->getCurrentTime());
      $revision = $storage->createRevision($revision);
      $revision->save();

Again, that is not implemented yet, and not 100% sure it will be needed.

You can support Agaric's overall contributions to Drupal and a bit beyond by supporting Drutopia at opencollective.com/drutopia. Thanks!

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
1
Tracked since
Oct 2024
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 1
Maintenance
Dormant

Releases

Version Type Core Release date
1.0.x-dev Dev Oct 9, 2024