Skip to content

Conversation

@lozcalver
Copy link
Member

Description

Issues

Pull request checklist

  • The target branch is correct
  • All commits are relevant to the purpose of the PR (e.g. no TODO comments, unrelated rewording/restructuring, or arbitrary changes)
    • Small amounts of additional changes are usually okay, but if it makes it hard to concentrate on the relevant changes, ask for the unrelated changes to be reverted, and submitted as a separate PR.
  • The commit messages follow our commit message guidelines
  • The PR follows our contribution guidelines
  • The changes follow our writing style guide
  • Code examples follow our coding conventions
  • CI is green

Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this to the top of SingleRecordAdmin::getEditForm() will mean people don't have to add this extra field.

if (!$fields) {
    if (!$id) {
        $id = $this->currentRecordID();
    }
    $record = $this->getRecord($id);
    if ($record) {
        $fields = $record->getCMSFields();
    }
}
if ($fields && !$fields->dataFieldByName('ID')) {
    $fields->add(HiddenField::create('ID'));
}

Given a record could be edited in different contexts, we shouldn't require adding a field to the model itself just so it can be edited correctly in this one specific context. We should just make SingleRecordAdmin work out of the box instead.

From what I can tell, the above snippet works for new admins and doesn't break existing ones since it checks for the existence of the ID field initially.

@lozcalver
Copy link
Member Author

Good idea!

@lozcalver lozcalver closed this Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants