Hi,

I have 2 entities : page and file.

In Page entity there is a entity reference field references file entity only and configured as follow:
- reference method: default
- Create referenced entities if they don't already exist: enabled
- Unlimited number of values

Entity reference form field display is : "Inline entity form - complex" with "Allow users to add new nodes." option only.

Scheduler module is enabled but not active for those 2 content types. Drupal core is 8.3.7.

Problem is that "Publish on" and "Unpublish on" fields are both displayed when I edit a file from within the page edit form.

Any idea ?

Thanks !

CommentFileSizeAuthor
#6 Screenshot 2022-02-22 at 14.53.22.png364.79 KBg_miric

Issue fork scheduler-2916730

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

wanjee created an issue. See original summary.

jonathan1055’s picture

Hi wanjee,
Do you get the Publish and Unpublish field when you edit the page? or is it just when editting the file attached to the page?
In content type admin, do you have contol over the display for "file". If so, does it have the Scheduler fields?
Jonathan

wanjee’s picture

Hi,

Both fields are displayed when I'm on a page edit form and I click on "edit" button for any of the related files so they appear on the file embedded form only. If I edit the file directly I don't see those fields.

Fields are indeed visible in file "manage form display" whatever the status of scheduler for this entity (disabled for both publish and unpublish).

Ok so removing them from there fixes my issue. Problem solved for me. Thanks ! I didn't had to manage form display for them to appear on any other entities so I didn't think it could be the reason :)

However this should maybe be checked anyway. Behavior of those fields is inconsistent depending on context (#1 being full node edit form or #2 embedded edit for in another node edit form).

#1 displays the fields in right column
#2 displays the fields inline

Regards

Rob230’s picture

Version: 8.x-1.0-rc2 » 2.x-dev

I think there is a bug here. I've upgraded from 1.x to 2.x and the image media type has "Publish on" and "Unpublish on" fields suddenly appearing in the form display of every entity type. If I edit the content type or media type then scheduling is not enabled. Is this a new thing? The fields don't actually display because scheduling is disabled. Do I need to go through and re-save every entity bundle on the site?

jonathan1055’s picture

Hi Rob230,
Media entities are supported from version 2.x of Scheduler and yes you will see those fields listed in the Form Display tab. But unless you actually enable scheduled publishing or unpublishing for a media type then the input fields will not be displayed in the actual edit form. So there is no need to re-save all your entity bundles, as I don't think you actually have a problem.

Or if I have mis-understood then apologies, and please explain, stating what is wrong for the end user.

g_miric’s picture

Hi jonathan1055

That is true, but the issue occurs in "Media Library".

Steps to reproduce:
1. Create a media type, e.g. Image
2. Don't enable Scheduler
3. If you go to "/media/add/image" you will not see Publish/Unpublish fields - Works as designed
4. Add Image field to e.g. Basic page content type: Entity reference → Media → Image
5. In Form Display settings set the "Media library" widget for the image field
6. If you go to /node/add/page and try to upload the image (create a media) you will see Publish/Unpublish fields (screenshot attached)

jonathan1055’s picture

Thanks for giving the steps to reproduce, and I confirm that this is a bug. It's a very strange one, though, as most often things are missing when they should be present, but here we get the scheduler fields on the form when neither the base entity (page) nor the referenced entity (image) have scheduling enabled.

Also, as the initial bug was reported at 8.x-1.0 it is unlikely that the new work for entity plugins (introduced in 2.x) is the cause. I will find out what is going on.

jonathan1055’s picture

I have found the cause of the problem, the Media Library form for uploading a new image (or any media item) is not an entity form, so the standard hook_entity_form_alter is not invoked, which is how Scheduler disables one or both of those fields if scheduling is not enabled, etc. This is not necessarily a fault in Media Library, it's just that it does things a little differently. I will make a temporary fix for you to test, to see how it goes.

jonathan1055’s picture

Title: "(Un)Publish on" fields displayed in entity reference form » 2916730-fields-on-referenced-entity-form
Status: Active » Needs review

I have made a quick fix, to see if this works for you, but it is not the full final solution. If you want a patch from the MR, you can get it via the 'plain diff' link in the box at the top - https://git.drupalcode.org/project/scheduler/-/merge_requests/33.diff

jonathan1055’s picture

Title: 2916730-fields-on-referenced-entity-form » Scheduler fields displayed in entity reference form when entity is not enabled

Restoring the title that automatically got changed to the branch name when I created the MR.

Rob230’s picture

So there is no need to re-save all your entity bundles, as I don't think you actually have a problem

It's just because if you do re-save it and export the config then those fields will be added (even though they aren't shown). But it shouldn't make a difference to the end user, it's just that the config has now changed.

jonathan1055’s picture

To cater for this properly, that is, to show the Scheduler field(s) on the upload form when the entity does have scheduling enabeld, it requires a slight re-factoring of _scheduler_entity_form_alter(), to add a new parameter for the $entity. Then for the normal entity forms this is called as before, but now with the $entity parameter set in scheduler_form_alter(). For media uploads, the function is called for each media entity in the form.

This is currently only work-in-progress, because it needs the following

  • Patch from #3269103: Add getFormDisplay() method to media_library AddFormBase to allow the display to be loaded
  • The media_upload view needs to be modified to show unpublished items, otherwise when you enter a publish_on date the new media is excluded from the view and cannot be selected
  • Problems with the scheduler fields being repeated when multiple new media entities are uploaded in one operation

However, the refactoring of _scheduler_entity_form_alter() does not add any overhead, so will be a useful start to this.

jonathan1055’s picture

I have now raised #3269471: Expose 'published' status filter in media library views and added a patch there (for core 8.9 and 9.4) to allow unpublished media to be displayed. I have also fixed the problem with Scheduler fields being duplicated, see next commit.

jonathan1055’s picture

@wanjee, @Rob230, @g_miric
Just wondering if anyone has tested this fix yet? I'd like to commit it soon, so would be good to get any feedback. Thanks very much.
Jonathan

jonathan1055’s picture

Title: Scheduler fields displayed in entity reference form when entity is not enabled » Scheduler fields displayed in Media Library upload form when media is not enabled

Changing title as this problem (and the fix) is specific to Media Library

  • jonathan1055 committed 5f1de1c on 2.x
    Issue #2916730 by jonathan1055, g_miric, wanjee, Rob230: Scheduler...
jonathan1055’s picture

Title: Scheduler fields displayed in Media Library upload form when media is not enabled » Scheduler fields displayed in Media Library upload form when media is not enabled for scheduling
Category: Bug report » Task
Status: Needs review » Fixed

Committed. If the two Media core issues are (ever) addressed then we can re-visit this and make an accurate decision on which scheduler fields should be shown.

Status: Fixed » Closed (fixed)

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