Problem/Motivation
When updating a FarmOs entity using JSON API, it never creates a revision. We need those revisions to match the rest of the application.
See this JSON API issue: https://github.com/json-api/json-api/pull/824
Steps to reproduce
PATCH an entity or POST a relationship change through JSON API, it should create a new revision but it doesn't.
Proposed resolution
Force new revisions if the entity type supports it and the bundle have them enabled.
Preliminary code for the assets:
function farm_ui_location_asset_presave(EntityInterface $entity) {
// Force create new revision as json api doesn't do that by default.
// @see https://www.drupal.org/project/drupal/issues/2993557
// @see https://www.drupal.org/project/drupal/issues/2795279
// @see https://github.com/json-api/json-api/pull/824
$bundle = AssetType::load($entity->bundle());
if ($bundle->shouldCreateNewRevision() && $entity->getEntityType()->isRevisionable()) {
/** @var \Drupal\Core\Entity\RevisionLogInterface $entity */
$entity->setNewRevision(TRUE);
$entity->setRevisionCreationTime(\Drupal::time()->getRequestTime());
}
}
Remaining tasks
Hide the "new revision" checkbox from the farm entity forms.
Issue fork farm-3216766
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
m.stentaThanks for opening this @pcambra!
(To summarize for future reference:) We discussed this in the farmOS dev call today and made the decision to just force revisions 100% of the time. This means we will be losing the ability for users to "uncheck" the "Create a new revision" checkbox in entity edit forms. This is a minor loss, but seems to be the easiest way to ensure revisions in all other contexts, including API requests, which is far more important.
We can open a new issue to explore re-enabling that checkbox in the future if there is demand for it.
Comment #4
pcambraComment #6
m.stentaMerged - thanks @pcambra!