Description
Problem/Motivation
Drupal 8.3 introduced a new key in the Content Entity Annotation show_revision_ui
(see https://www.drupal.org/node/2835025) eliminating the need for Drupal Console to add some custom code and logic to the Entity Form.
Solution
When Drupal Console generates Content Entities this key should be added and set to TRUE
if the user specifies that they would like revision.
The result is that the whole buildForm
method in the generated ContentEntityForm
class can be removed, or if not all of it just the field which adds the Create new revision
checkbox, assuming the later this would leave:
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
// Add custom form elements here
$entity = $this->entity;
return $form;
}
In the save
method of the generated ContentEntityForm
class will need to be modified slightly, the checkbox which allows the user to choose if they want to create a new revision is now named simply revision
, not new_revision
:
if (!$form_state->isValueEmpty('new_revision') && $form_state->getValue('new_revision') != FALSE) {
Should be changed to:
if (!$form_state->isValueEmpty('revision') && $form_state->getValue('revision') != FALSE) {
There may be additional code which can also be removed, or some code which may need to change, but I haven't found anything else yet..
Activity
AaronMcHale commentedon Feb 7, 2019
While I'm on the subject of improving revisioning, currently with Drupal Console generated Content Entities, if you edit a Entity and choose not to create a new revision, but the Entity already has a revision with a log message, the log message will be erased.
To solve this we should add this override method to the generated Entity class (taken directly from the Node module with slight modification):
AaronMcHale commentedon Feb 7, 2019
Regarding my previous comment, came across this core issue which will probably address that at a higher level https://www.drupal.org/project/drupal/issues/1863258
I suppose it comes down to, add the override of preSaveRevision now and remove later, or just don't bother and assume it'll be fixed eventually in that core issue.
enzolutions commentedon May 9, 2019
@AaronMcHale Could you tell us if this issue was resolved in the latest release of Drupal 8.7.x?