Cms: [FR] Ability to see dirty attributes programmatically before element save

Created on 16 Apr 2019  路  4Comments  路  Source: craftcms/cms

Description

Currently, it doesn't look like there's a way to see what attributes are updated on elements without doing an additional query before an element is saved. Ideally, there would be a layer of abstraction on elements to help keep track of dirty fields and basic attributes, such as slugs and content fields. This functionality could mirror Yii's ActiveRecord:

public array getDirtyAttributes ( $names = null )
public聽mixed聽getOldAttribute聽(聽$name聽)

Due to the complexity of elements and their usage of sister tables, I imagine this may need to be an "opt-in" based functionality in certain cases; particularly because certain elements query their sister tables directly, bypassing ActiveRecord.

The benefits of this would be pretty substantial:

  • Rebuild sitemaps/create 301 redirects only if slug or title changed
  • Programmatically clear coldcaches or cacheflags on heavy templates only when a specific attribute is updated
  • Paves the way for keeping track of element histories efficiently

Additional info

  • Craft version: 3.1.22
enhancement extensibility

Most helpful comment

Added for Craft 3.4 :)

All 4 comments

Added for Craft 3.4 :)

@brandonkelly Not exactly related to this issue, but I noticed the delta updates don't currently work on the draft editor for live preview. Is that something that's more trouble than it's worth or is it still on your radar? I imagine it could mean a pretty big bump in live-preview speed, especially for larger entries.

Definitely part of the plan :) It will be a prerequisite for #4642 which is next up.

@Mosnar Drafts support delta updates now (2e1c70a6d16b38c7f1ae0b84548a7c866646e4c3).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mattstein picture mattstein  路  3Comments

rynpsc picture rynpsc  路  3Comments

darylknight picture darylknight  路  3Comments

angrybrad picture angrybrad  路  3Comments

lukebailey picture lukebailey  路  3Comments