Problem/Motivation

On #2068063: Change "Save and keep un-/published" buttons to a "Published" checkbox and an included "Save" button a footer region was introduced to NodeForm. It has surfaced while working on #2863431: Change "Save and keep un-/published" buttons for media module that this should be a more generic thing for all entity forms that implement EntityPublishedInterface so as to have consistency in the UI and avoid code duplication.

The only current use case in core where this would not be applicable is CommentForm. So double checking would be necessary.

Proposed resolution

Move the form footer region into ContentEntityForm for all entities implementing EntityPublishedInterface, remove it from NodeForm, and refactor the relevant CSS so it applies to all relevant forms.

Identify whether the need for a generic contententity-edit-form template would be necessary.

Remaining tasks

Do it.

User interface changes

None

API changes

None

Data model changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Manuel Garcia created an issue. See original summary.

Manuel Garcia’s picture

Status: Active » Needs review
FileSize
1.82 KB

Here's a start.

Berdir’s picture

The only class that ContentEntityForm currently explicitly defines is 'class' => ['entity-content-form-revision-information'], should we be consistent with that and use entity-content-footer or so?

Gábor Hojtsy’s picture

This would be amazing to support workflow's additions on the form.

amateescu’s picture

+++ b/core/lib/Drupal/Core/Entity/ContentEntityForm.php
@@ -127,6 +127,17 @@ public function form(array $form, FormStateInterface $form_state) {
+    if ($this->entity instanceof EntityPublishedInterface) {

I don't think we should condition this region on EntityPublishedInterface, some workflows beside Content Moderation might not care about an entity being publishable or not.

timmillwood’s picture

I agree with #3 and #5.

Also I wonder if it's worth pulling in $form['status']['#group'] = 'footer'; in this issue.

Manuel Garcia’s picture

Thanks @all for the feedback & suggestions.
Addressing #3, #5 and #6

timmillwood’s picture

Sorry, #6 was more of a question than an action. I'm on the fence about putting the status field in the footer generally, or do it on a per entity form basis. I guess even if we put status in the footer in ContentEntityForm, the entity still needs to update the base field definition to display the field in the form.

Manuel Garcia’s picture

@timmillwood yeah I suppose leaving it on the node form makes sense because of that...

Could we perhaps update the base field definition on ContentEntityBase? Or perhaps EditorialContentEntityBase or EntityPublishedTrait?

Manuel Garcia’s picture

Actualy ContentEntityBase is used by all kinds of unrelated entities so thats a no go.
EditorialContentEntityBase however is only used by Node and Media at the moment...

Manuel Garcia’s picture

How about updating the base status field definition in EditorialContentEntityBase?

This should help cutting down #2863431: Change "Save and keep un-/published" buttons for media module and any other entity that follows this pattern...

Manuel Garcia’s picture

Or perhaps do this on ContentEntityBase::baseFieldDefinitions()?

Manuel Garcia’s picture

Actually i already answered #12 on #10... so i think #11 is the way to go.

timmillwood’s picture

We could update the base field settings on the original base field in \Drupal\Core\Entity\EntityPublishedTrait::publishedBaseFieldDefinitions?Comment entity also uses this trait, so we might have to override things there.

+++ b/core/lib/Drupal/Core/Entity/EditorialContentEntityBase.php
@@ -25,6 +25,19 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
+    if ($entity_type->hasKey('status')) {

The entity key should be 'published'.

Manuel Garcia’s picture

Re #14:
I believe the key should be status. Both Node and MediaType define this key, but not Comment, so that serves as a way of signaling that the entity actually wants this field, so comments would not be affected by this change.

Moving the change into EntityPublishedTrait::publishedBaseFieldDefinitions

Node edit form looks exactly as before with this =)

Manuel Garcia’s picture

FileSize
2.11 KB
3.77 KB

Argh forgot to save the change on EditorialContentEntityBase before generating the patch... ignore the last one.

timmillwood’s picture

+++ b/core/lib/Drupal/Core/Entity/EntityPublishedTrait.php
@@ -32,11 +32,26 @@ public static function publishedBaseFieldDefinitions(EntityTypeInterface $entity
-    return [$entity_type->getKey('published') => BaseFieldDefinition::create('boolean')
+    $fields = [];
+    $fields[$entity_type->getKey('published')] = BaseFieldDefinition::create('boolean')
       ->setLabel(new TranslatableMarkup('Published'))
       ->setRevisionable(TRUE)
       ->setTranslatable(TRUE)
-      ->setDefaultValue(TRUE)];
+      ->setDefaultValue(TRUE);
+
+    // Add the status form field.
+    if ($entity_type->hasKey('status')) {
+      $fields['status']->setDisplayOptions('form', [
+          'type' => 'boolean_checkbox',
+          'settings' => [
+            'display_label' => TRUE,
+          ],
+          'weight' => 120,
+        ])
+        ->setDisplayConfigurable('form', TRUE);
+    }
+
+    return $fields;

We don't need to add this on, with the if hasKey, we can just update the original BaseFieldDefinition.

(and the key is published, not status. See Node, Media, and Comment.

amateescu’s picture

I don't think we should change EntityPublishedTrait to show the field by default, that's for individual entity types to decide when and how they want it displayed.

The patch in #7 was perfect IMO.

Berdir’s picture

Status: Needs review » Needs work

Agreed. This forces it on all entity types that implement this, it is up to them how to display it.

I'm still very confused about how exactly 9.x and deprecations and so on will work, but in theory, we could do what we did before.. introduce a setting to opt-in to this, and switch the default or remove it in 9.x, but I don't think this is worth it.

Also the CSS parts are tricky, because seven has quite a bit of node-form specific CSS, also e.g. the #edit-body thing above which is not limited to node form and is actually a configurable field, so different fields will look different. But if we suddenly apply all of that to all entity forms like comments and so on. And it's also partially tied to the node specific form alter that seven does (that we simplify but not completely remove in another issue) Maybe we could do a separte issue to introduce a something-form class that entity forms can add (or similar to above, we add by default in 9.x) to get the same styling for their forms.

Manuel Garcia’s picture

I've done a bit of exploring, and providing a template for all editorial content entities I don't think is a good idea. The node form and the media form are very different in purpose and requirements so this would just get in the way, even with proper theme suggestions I think it could get very messy.

Re #17 Node and Media define both status and published keys, while Comment only defines published, that's why I went with status, but I could be missing something...

Re #18 I can totally see the reasoning there. Hiding the other patches.

timmillwood’s picture

Media doesn't have a status and published entity key, it just has published, but it looks like that's irrelevant if we go with the patch in #7. I would like to see an easier way to opt in or out, other than the changing the base field definition, but I guess @Berdir is right, it's not worth it.

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
1.64 KB

Re #21 er... you're right, not sure what I was thinking, sorry for the nuisance!

Re-uploading #7 here so as to make it clear which way it's forward for this.

Berdir’s picture

Details elements have a useful #optional attribute, that does not show the wrapper if it is empty. That would be quite nice here as well because then we can guaranteee that the markup/output is not going to be altered unless you actually use that footer region.

Container unfortunately doesn't, and it is less likely to cause a visual change, but it could possibly still result in some additional spacing in theory.

Not sure if it's worth to add support for that for container or do a custom #pre_render for this element only here?

Manuel Garcia’s picture

I think it would be great having #optional on Container, opened #2893586: Add #optional support to the Container render element =)

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

tim.plunkett’s picture

Issue tags: +Blocks-Layouts

Tracking this, since it's something we'll need to undo once we bring layouts to entity forms.

amateescu’s picture

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 27: 2892304-27.patch, failed testing. View results

amateescu’s picture

Status: Needs work » Reviewed & tested by the community
larowlan’s picture

Did some manual testing of this, looks good

Manuel Garcia’s picture

#2893586: Add #optional support to the Container render element got in so let's use it here :)

w00t! great to see this all coming together :D

Re #26:

Tracking this, since it's something we'll need to undo once we bring layouts to entity forms.

We could just add the layouts configuration to this region no? - otherwise, what's the plan? (I'm curious)

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs change notice

Can we get a change notice here selling this feature - thanks

timmillwood’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs change notice

  • larowlan committed 2e3db91 on 8.5.x
    Issue #2892304 by Manuel Garcia, amateescu: Introduce footer region to...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed as 2e3db91 and pushed to 8.5.x.

Published change record.

Thanks.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

tim.plunkett’s picture

Issue tags: -Blocks-Layouts

Retroactively removing tag as it didn't factor into the initiative after all