Problem/Motivation

As discussed in #2753673-10: Add status and workflow state to page title block. the very useful meta information typically presented at the top of the sidebar:

node form meta information

... in node edit forms presently comes from seven_form_node_form_alter. This means that it's not available when a different admin theme is used, and it's complicated / impossible for other modules to alter.

Proposed resolution

Move the provision of this meta information out of the theme layer; probably into the node.module itself.

Remaining tasks

Write a patch, review the patch etc..

User interface changes

Probably none if Seven is selected as the admin theme, if not then extra information may appear in the node edit form.

API changes

None.

Data model changes

None.

CommentFileSizeAuthor
#53 interdiff.txt554 bytesamateescu
#53 2803875-53.patch7.84 KBamateescu
#49 interdiff.txt2.12 KBamateescu
#49 2803875-49.patch7.82 KBamateescu
#47 interdiff.txt3 KBamateescu
#47 2803875-47.patch7.33 KBamateescu
#44 interdiff.txt556 bytesamateescu
#44 2803875-44.patch6.79 KBamateescu
#42 interdiff.txt2.61 KBamateescu
#42 2803875-42.patch6.43 KBamateescu
#39 Selection_160.png30.13 KBberdir
#38 interdiff.txt1.41 KBamateescu
#38 2803875-38.patch4.79 KBamateescu
#36 entity-meta.png30.45 KBmanuel garcia
#35 interdiff.txt3.2 KBamateescu
#35 2803875-35.patch4.22 KBamateescu
#31 interdiff.txt1.57 KBmanuel garcia
#31 Screenshot from 2017-05-12 16-01-08.png34.23 KBmanuel garcia
#28 2803875-28.patch5.32 KBtimmillwood
#28 interdiff-2803875-28.txt1.51 KBtimmillwood
#26 2803875-36.patch5.28 KBtimmillwood
#26 interdiff-2803875-26.txt3.66 KBtimmillwood
#24 Screenshot from 2017-04-11 13-46-44.png23.39 KBtimmillwood
#24 Screenshot from 2017-04-11 13-46-18.png22.38 KBtimmillwood
#24 2803875-24.patch5.34 KBtimmillwood
#16 2803875-16.patch5.93 KBtimmillwood
#16 2803875-16-test-only.patch1.28 KBtimmillwood
#15 interdiff.txt1.28 KBtimmillwood
#15 2803875-14.patch5.93 KBtimmillwood
#13 2803875-13.patch4.65 KBtimmillwood
#11 node_form_meta-2803875-11.patch5.18 KBsidharthap
#7 node_form_meta-2803875-7.patch4.07 KBmcdruid
#6 node_form_meta-2803875-6.patch3.53 KBmcdruid
#6 Selection_014.png14.66 KBmcdruid
#6 Selection_013.png27.03 KBmcdruid
#4 interdiff-2803875-2-4.txt502 bytesshashikant_chauhan
#4 2803875-4.patch4.02 KBshashikant_chauhan
#2 2803875-2.patch4.02 KBshashikant_chauhan
Selection_003.png14.75 KBmcdruid

Comments

mcdruid created an issue. See original summary.

shashikant_chauhan’s picture

Status: Active » Needs review
StatusFileSize
new4.02 KB

Adding initial patch.

timmillwood’s picture

Status: Needs review » Needs work
+++ b/core/modules/node/node.module
@@ -1367,3 +1367,46 @@ function node_comment_delete($comment) {
+function seven_form_node_form_alter(&$form, FormStateInterface $form_state) {

This needs to be node_form_node_form_alter.

shashikant_chauhan’s picture

StatusFileSize
new4.02 KB
new502 bytes

Sorry my bad, adding updated patch. Thanks timmillwood.

shashikant_chauhan’s picture

Status: Needs work » Needs review
mcdruid’s picture

StatusFileSize
new27.03 KB
new14.66 KB
new3.53 KB

Thanks for starting off the work on the patch shashikant_chauhan!

Rather than moving the form_alter from seven.theme into node.module, I was thinking more of putting the meta information directly into the NodeForm. It seems a bit strange for a module to alter its own form :)

So I think the idea would be to introduce the "missing" meta info into the basic NodeForm such that - for example - it's visible when using an admin theme like 'stark'.

Then seven.theme can still make tweaks to the presentation using form_alter.

Here's a patch which does that. It's not perfect, but it's a start.

The new info when using the stark theme:

stark admin theme

...and the meta info when using the seven admin theme:

seven admin theme

There are a few problems to address e.g.:

* the presentation is not identical in seven before and after - for example "Last saved" has two colons :after it because of the way the HTML and CSS work at present.
* not sure about "status" as a title for the new meta element in the form; I think it's probably better than "meta" but I expect there will be a few different opinions.

I haven't included an interdiff, as I'm not sure that line-by-line comparison of the patches is particularly useful.

mcdruid’s picture

StatusFileSize
new4.07 KB

New patch (which applies against 8.3.x and) which adds CSS tweaks to avoid the double colon being added after the "Last saved" label.

timmillwood’s picture

Should we have a test for this?

timmillwood’s picture

Status: Needs review » Needs work

Moving to needs work for the tests.

naveenvalecha’s picture

Issue tags: +Novice, +Needs reroll

This needs a reroll which is a novice task. See how to reroll a patch https://www.drupal.org/contributor-tasks/reroll

sidharthap’s picture

Status: Needs work » Needs review
StatusFileSize
new5.18 KB

Reroll patch as per #10

Status: Needs review » Needs work

The last submitted patch, 11: node_form_meta-2803875-11.patch, failed testing.

timmillwood’s picture

Status: Needs work » Needs review
Issue tags: -Novice, -Needs reroll
StatusFileSize
new4.65 KB

Re-rolling again.

timmillwood’s picture

timmillwood’s picture

Issue tags: -Needs tests
StatusFileSize
new5.93 KB
new1.28 KB

Added a simple test for these changes.

timmillwood’s picture

StatusFileSize
new1.28 KB
new5.93 KB

Adding a test only patch to show this actually fixes stuff.
Also re-uploading the patch from #15 just for clarity.

The last submitted patch, 16: 2803875-16-test-only.patch, failed testing.

jeqq’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

catch’s picture

Assigned: Unassigned » star-szr

Moving this over to Cottser in case he wants to have a look first. Looks like a very minor addition to the node form to me, I'd definitely not have expected to find it in seven.

berdir’s picture

Yeah, this is certainly strange to be in Seven, but moving it now might have some tricky side effects?

When you use node forms without the admin theme, then it is quite common to have it be public for anon/authenticated users and this change could result in "things" being suddenly displayed, which affects user-visible parts of a website?

I see there's a screenshot above for stark, how does this look in bartik?

Also a ton of markup is apparently still seven specific and we're still changing all kinds of things there.

And also wondering about this combined with #2068063: Change "Save and keep un-/published" buttons to a "Published" checkbox and an included "Save" button.

catch’s picture

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

CNR for at least the bartik screenshots.

star-szr’s picture

Assigned: star-szr » Unassigned
Status: Needs review » Needs work

From @Berdir in #20:

When you use node forms without the admin theme, then it is quite common to have it be public for anon/authenticated users and this change could result in "things" being suddenly displayed, which affects user-visible parts of a website?

Indeed that seems to be the most concerning potential side effect, in that it would be general user-facing.

We can potentially consider including this in 8.3.x but I'd like to run that by a release manager. We are short on time to squeeze it in for the first 8.3.x alpha.

Unassigning for now so we can get screenshots and discuss further.

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

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

timmillwood’s picture

Status: Needs work » Needs review
Issue tags: -Needs screenshots
StatusFileSize
new5.34 KB
new22.38 KB
new23.39 KB

Here's a re-roll of the patch and some screenshots in Bartik.

manuel garcia’s picture

Status: Needs review » Needs work

Drive by nit picks...

+++ b/core/modules/node/src/NodeForm.php
@@ -99,6 +99,42 @@ public function form(array $form, FormStateInterface $form_state) {
+    $form['meta'] = array(
+      '#type' => 'details',
+      '#group' => 'advanced',
+      '#weight' => -10,
+      '#title' => t('Status'),
+    );
+    $form['meta']['published'] = array(
+      '#type' => 'item',
+      '#markup' => $node->isPublished() ? t('Published') : t('Not published'),
+      '#access' => !$node->isNew(),
+    );
+    $changed = !$node->isNew() ? format_date($node->getChangedTime(), 'short') : t('Not saved yet');
+    $form['meta']['changed'] = array(
+      '#type' => 'item',
+      '#title' => t('Last saved'),
+      '#markup' => $changed,
+    );
+
+    // Add a revision_log field if the "Create new revision" option is checked,
+    // or if the current user has the ability to check that option.
+    $form['revision_information'] = array(
+      '#type' => 'details',
+      '#group' => 'advanced',
+      '#title' => t('Revision information'),
+      // Open by default when "Create new revision" is checked.
+      '#open' => $node->isNewRevision(),
+      '#attributes' => array(
+        'class' => array('node-form-revision-information'),
+      ),
+      '#attached' => array(
+        'library' => array('node/drupal.node'),
+      ),
+      '#weight' => 20,
+      '#optional' => TRUE,
+    );

Can we do short array syntax here please?

+++ b/core/themes/seven/seven.theme
@@ -157,32 +157,24 @@ function seven_form_node_form_alter(&$form, FormStateInterface $form_state) {
+
+  $form['meta']['#attributes'] = array('class' => array('entity-meta__header'));
+  $form['meta']['#type'] = 'container';
+  $form['meta']['published']['#type'] = 'html_tag';
+  $form['meta']['published']['#tag'] = 'h3';
+  $form['meta']['published']['#value'] = $form['meta']['published']['#markup'];
+  unset($form['meta']['published']['#markup']);
+  $form['meta']['published']['#attributes'] = array(
+    'class' => 'entity-meta__title',
+  );
+  $form['meta']['changed']['#title'] = '<h4 class="label inline">' . t('Last saved') . '</h4>';
+  $form['meta']['changed']['#wrapper_attributes'] = array('class' => array('entity-meta__last-saved', 'container-inline'));
+  $form['meta']['author'] = array(
+    '#type' => 'item',
+    '#wrapper_attributes' => array('class' => array('author', 'container-inline')),
+    '#markup' => '<h4 class="label inline">' . t('Author') . '</h4> ' . $node->getOwner()->getUsername(),
+  );

And here as well :)

timmillwood’s picture

Status: Needs work » Needs review
StatusFileSize
new3.66 KB
new5.28 KB

Thanks for the review @Manuel Garcia, here's the short syntax version of the patch.

manuel garcia’s picture

Status: Needs review » Needs work

Sorry more nitpicks...

+++ b/core/modules/node/src/NodeForm.php
@@ -99,6 +99,42 @@ public function form(array $form, FormStateInterface $form_state) {
+      '#title' => t('Status'),
...
+      '#markup' => $node->isPublished() ? t('Published') : t('Not published'),
...
+    $changed = !$node->isNew() ? format_date($node->getChangedTime(), 'short') : t('Not saved yet');
...
+      '#title' => t('Last saved'),
...
+      '#title' => t('Revision information'),

Let's do $this->t() instead.

timmillwood’s picture

Status: Needs work » Needs review
StatusFileSize
new1.51 KB
new5.32 KB

Done.

Was tempted to update all, but out of scope, so just updated the ones added / edited by this patch.

manuel garcia’s picture

Thanks, looks good to me now
@Cottser we've now got screenshots (see #24) ;-)

berdir’s picture

This doesn't really make it worse than it was before, but I'm still wondering if couldn't be a lot cleaner if we could move at least some of markup things in seven.theme into the node template. That code just feels "dirty" to me :)

manuel garcia’s picture

StatusFileSize
new34.23 KB
new1.57 KB

While having a look at this, I thought that we could transition this to just being another details element, it looks good to me, although obviously not the same as we had before. I attach just an interdiff to illustrate what the change would need to be against the other patch and not derail the "patch conversation", assuming we want to keep the look we've got so far on Seven.

Apologies if this was already discussed back in the day =)

In any case, I agree we should clean up seven_form_node_form_alter to get rid of the markup there, but I think that we could do that as a follow up. We would be introducing a new template file that is not yet in Seven (node-edit-form.html.twig), and if we are going to do that we should aim to give other admin themes a good example on how to theme the node form - which deserves an issue to itself.

timmillwood’s picture

Issue tags: +Needs themer review

I quite like the suggestion in #31.

timmillwood’s picture

This issue is blocking us from altering the meta information in the sidebar in #2753717: Add select field to choose moderation state on entity forms.

The meta information is currently added in seven theme, therefore no modules can form_alter it, this issue would resolve that.

In content moderation we could have a state such as "archived" which sees the Node still being unpublished, just was a state labeled "archived". The issue here is the meta information still states "unpublished" which is confusing when the Content Moderation state is "archived".

I strongly feel the patch in #28 is a good solution, or at least a good first step in the right direction. Can we continue on with that, then open a follow up to discuss any further modifications such as #3?

wim leers’s picture

And since #2882801: Review and improve the media creation form is also talking about having a sidebar for Media like Node already has … it looks like this is also blocking the Media Initiative now.

amateescu’s picture

StatusFileSize
new4.22 KB
new3.2 KB

This needed a re-roll after #2068063: Change "Save and keep un-/published" buttons to a "Published" checkbox and an included "Save" button.

Also, the "dirty" code mentioned by @Berdir in #30 could be improved with the attached interdiff :) The screenshots from #24 (for Bartik) and the issue summary (for Seven) still apply.

manuel garcia’s picture

StatusFileSize
new30.45 KB

Ah great, thanks @amateescu
Did a bit of manual checking, looks great to me, +1 to RTBC

jonathan1055’s picture

In the re-roll in #24 we lost one of the additional tests that was in #16

--- a/core/modules/node/src/Tests/NodeCreationTest.php
+++ b/core/modules/node/src/Tests/NodeCreationTest.php
@@ -40,6 +40,7 @@ function testNodeCreation() {
     $node_type_storage->load('article')->delete();
     $this->drupalGet('node/add');
     $this->assertResponse(200);
+    $this->assertText('Not saved yet');
     $this->assertUrl('node/add/page');
     // Create a node.
     $edit = array();

It was not in the interdiff, so was it accidentally dropped, and should it go back in?

amateescu’s picture

StatusFileSize
new4.79 KB
new1.41 KB

@jonathan1055, that's a very good observation! Yes, let's bring back that assertion :)

berdir’s picture

StatusFileSize
new30.13 KB

This does look a bit weird now in bartik though, because the status is duplicated fairly close together if you have administer nodes permission:

It also overlaps a bit with #2886569: Users with just create content permission don't know publishing status, especially on existing entities as you'd then get both the disabled checkbox and this new information?

I really don't want to be this annoying person who dislikes everything new (I feel very old right now ;)) but my comments on #2886569: Users with just create content permission don't know publishing status also apply here. If you have workflows where you use node forms to let users post stuff, without them even knowing that they are creating nodes/content, then this adds stuff to the page that wasn't there before. Maybe that's just me, but that's a pattern that we have used quite often in the past.

The same is true about the existing revision log field, but that was there before and you had to take care of it but this will then suddenly pop up on existing sites. If we're OK with that fine, but then we definitely need a change record that explains that.

jonathan1055’s picture

If this issue lands and we do have a tab for 'status' which is viewable by all users, then am I right in thinking that #2886569: Users with just create content permission don't know publishing status will be redundant?

Also, to address your concern that the 'published' information is repeated, when this issue is done we could look at moving the new checkbox which was added in #2068063: Change "Save and keep un-/published" buttons to a "Published" checkbox and an included "Save" button to be inside this status tab, then all the status information would be in the one place, and the form for admins would be tidier with only the buttons showing at the bottom and no isolated checkbox.

berdir’s picture

Not reduntant, because this, just like seven in HEAD does *not* show the status for new content, just existing.

Also, about moving it, I'm not sure because we tried various things there, including having it in the vertical tabs but it is important that it is close to the submit button for UX. Also keep in mind that this looks completely different in seven, so the the checkbox would be in the sidebar. Which was actually something that I suggested in that other issue but others didn't like it (and I agree, was just an idea I had)

amateescu’s picture

Title: node form meta information should not come from a theme » Node form meta information should not come from a theme
StatusFileSize
new6.43 KB
new2.61 KB

If you have workflows where you use node forms to let users post stuff, without them even knowing that they are creating nodes/content, then this adds stuff to the page that wasn't there before. Maybe that's just me, but that's a pattern that we have used quite often in the past.

I also did this a number of times, so I can totally relate to your comment :) How about restricting access to the 'meta' details element by default to uses that have the 'administer nodes' permission, and only show it by default for everyone in the Seven theme?

Status: Needs review » Needs work

The last submitted patch, 42: 2803875-42.patch, failed testing. View results

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new6.79 KB
new556 bytes

Briefly discussed the approach in #42 with @Berdir and he liked it, so here's a green patch, hopefully :)

timmillwood’s picture

+1 looks like a nice approach.

Status: Needs review » Needs work

The last submitted patch, 44: 2803875-44.patch, failed testing. View results

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new7.33 KB
new3 KB

Of course, the test expectations have to be updated as well.

amateescu’s picture

Priority: Normal » Major
Issue tags: +WI critical
amateescu’s picture

StatusFileSize
new7.82 KB
new2.12 KB

I was talking to @Berdir in IRC about this issue and we couldn't find any reason to keep the 'author' meta info in the theme, so here's a new patch that finally moves all the meta elements to the node form itself.

berdir’s picture

The interaction between node form and seven is very complicated, especially as we start to try and expand/apply it to other entity forms as well. My comments in #2892304: Introduce footer region to ContentEntityForm have more examples of that.

I think this is a step in the right direction and unblocks a bunch of issues.

I opened two follow-ups for some ideas that @amateescu and I just discussed in IRC: #2893737: Move meta details element from NodeForm to ContentEntityForm and #2893740: Allow the sidebar for the node form to be used on other entity forms as well

This issue is also referenced by the media creation UX issue but it actually doesn't have any effect on that. #2893740: Allow the sidebar for the node form to be used on other entity forms as well on the other hand would.

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Meant to do this.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 49: 2803875-49.patch, failed testing. View results

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new7.84 KB
new554 bytes

The problem with moving the 'meta' form element from the theme form alter to the actual form is that they collide with the actual form elements with the same name ('author', 'changed', etc.), so we need to define the new 'meta' form element with '#tree' => TRUE in order stop that from happening.

timmillwood’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC then.

swentel’s picture

+++ b/core/modules/node/src/NodeForm.php
@@ -102,6 +114,34 @@ public function form(array $form, FormStateInterface $form_state) {
+      '#access' => $this->currentUser->hasPermission('administer nodes'),

Wouldn't it make more sense here to use the 'view the administration theme' permission ? Then we should be 100% sure that the 'Status' fieldset will never appear in case

- seven is not enabled,
- or that user doesn't have permission to see admin themes
- a different admin theme is used

berdir’s picture

My concerns aren't really about showing it only in seven/the admin theme, keep in mind that the node forms also have a setting to use admin theme or not.

I think it is OK if we introduce new visual elements to adminstrative users or also editors, what I was worried about is showing weird fieldsets and so on in custom themes for anon/normal authenticated users.

  • catch committed e0ea6c6 on 8.4.x
    Issue #2803875 by amateescu, timmillwood, mcdruid, shashikant_chauhan,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed e0ea6c6 and pushed to 8.4.x. Thanks!

tim.plunkett’s picture

Status: Fixed » Closed (fixed)

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