Problem/Motivation

The Layout Paragraphs project is a really huge step for Drupal Paragraphs

In #3254892: Improve UI / UX for (Un)published (see 3.) we discussed if a scheduled (un)publishing wouldn't be a cool feature, as layout_paragraphs 2.x uses the native published status of paragraphs and should allow doing this if scheduler is enabled for a paragraph type.

What do you think about an integration?

Steps to set up and test

  1. Install the module: composer require drupal/paragraphs && drush en paragraphs -y
  2. Create a paragraph type through Structure > Paragraph types, add at least one field and enable Scheduler as you would with node types.
  3. Create a node type and add a field of type Reference revisions / Paragraph. Tick 'include the selected below' and tick the paragraph content type.
  4. Create a node with a paragraph and schedule the paragraph for 5 minutes later.
  5. Wait 10 minutes and run cron. The paragraph should be published.

Issue fork scheduler-3259200

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:

Comments

Anybody created an issue. See original summary.

pub497 made their first commit to this issue’s fork.

jonathan1055’s picture

Hi,
Are you planning or writing a scheduler plugin for the Paragraphs entity type? I am about to post the documentation on this, which should help you.

anybody’s picture

@jonathan, no I just documented the issue. Anyone may implement it. :)

dieterholvoet’s picture

Title: Support Layout Paragraphs (2.x) » Support Paragraphs (2.x)
dieterholvoet’s picture

Status: Active » Needs review

I pushed a working plugin implementation to the MR. I had to do some extra changes since this module didn't account yet for entities without canonical/edit-form link templates.

jonathan1055’s picture

Thanks DieterHolvoet for providing the plugin and the fix for edit link.
As I've not used Parapgraphs or Layout Paragraphs before, could you give a few quick steps to follow so that I can test you work. I know I could do my own research and work it out for myself, but as you (or anyone else following here) are already experienced with Paragraphs it would be quicker for you.

This looks like a good addition for committing before I release 2.0, but I need to be able to test it in the way you are doing. Thanks

dieterholvoet’s picture

Here are the steps for testing with the Paragraphs module. I have no experience with the Layout Paragraphs module.

  1. Install the module: composer require drupal/paragraphs && drush en paragraphs -y
  2. Create a paragraph type through Structure > Paragraph types and enable Scheduler as you would with node types
  3. Create a node type and add a field of type Reference revisions / Paragraph
  4. Create a node with a paragraph and schedule the paragraph for 5 minutes later
  5. Wait 10 minutes and run cron. The paragraph should be published.
jonathan1055’s picture

Priority: Minor » Normal
Issue summary: View changes

Thanks DieterHolvoet, that's helpful. I followed through, and have sucessfully created paragraphs and scheduled them. All works fine in general, so that's a good start.

Some points I noticed:

Step 1. When installing (via drush and via site UI) we get the exception Failed to read source file for views.view.scheduler_scheduled_paragraph from either modules/scheduler/config/install or modules/scheduler/config/optional folders. This is because Scheduler does not (yet) provide any view for listing the scheduled paragraphs. SoI have changed this to a dblog notice, as there is no real need for it to be an exception. We need to work out if and how Scheduler can provide a view for a user to find their own scheduled paragraphs. Or maybe this is not possible, or not needed. Any ideas?

Step 2. When creating the Paragraph content type, it needs at least one field to be added (this was missing from above)

Step 3. When adding the paragraph to the node type, I used the default reference method. Also need to tick 'include the selected below' and tick the paragraph content type

Step 4. On saving the node we get message the Scheduler message is {node title} > {my paragraphs label} (previous revision) is scheduled to be unpublished ..... This message basically applies to the whole paragraphs section. If there are several paragraphs added but only one is scheduled I don't know if there is a better way to indicate which specific paragraph is scheduled? Maybe we can't do that, and the general message is good enough?

dieterholvoet’s picture

Issue summary: View changes
dieterholvoet’s picture

Step 1

We could add a view. Don't really have the time to do that right now though.

Step 2 / Step 3

I updated the testing instructions and added them to the issue description.

Step 4

That logic comes from Drupal\paragraphs\Entity\Paragraph::label(), it's how the paragraphs module decided to label its entities. If we wanted to override that logic on a per-entity type basis we would have to move most logic from scheduler_entity_presave to the Scheduler plugins, or we could add an entityLabel(EntityInterface $entity) method to SchedulerPluginInterface. Not sure if all that is worth the effort.

jonathan1055’s picture

Thanks for updating the issue summary.

Regarding a view, I will take a quick look, but even if we had a view I'm note sure where it would be displayed. Maybe on /admin/structure/paragraphs_type like we do for Commerce Products. There could be a user view on the profile tab too. But it may all be too much trouble.

For the warning I have created #3311425: Replace warning for no entity type with an explanation in the menu to avoid that being wrapped up in this issue.

For the scheduler message let's leave this as is. It is fine.

The first release of Scheduler 2.0 is almost here. Are you happy with this work so far, it would be nice for this to be in the first major release.

dieterholvoet’s picture

Let's leave the paragraphs view, paragraphs are only really relevant in context of their parent anyway.

Yeah, I'm happy with the work so far. I think this is ready to merge.

jonathan1055’s picture

Title: Support Paragraphs (2.x) » Plugin to support Paragraph entity type
Issue summary: View changes
Status: Needs review » Fixed

Yes we can leave the view out for now. It can always be added as a follow-up issue.

Merged and fixed. Thanks DieterHolvoet for doing most of this work.

jonathan1055’s picture

Follow-up issue #3312200: Paragraph scheduler plugin is needed because hook_form_alter is not called for referenced entities. It can be solved using hook_field_widget_complete_WIDGET_form_alter() for paragraph widgets.

This error would have been discovered if Paragraphs could be easily added into Scheduler's generic testing. However, the method for adding and editing a paragraph is not the same as other supported entities due to paragraphs being added to nodes and not being standalone entities. It would be very good to expand the tests to cover Paragraphs.

I have also found that the third-party settings for paragraph are missing from config/schema/scheduler.schema.yml so that has been added too.

jonathan1055’s picture

Status: Fixed » Needs work

I have decided to revert and remove the paragraphs plugin, as it is clear that it is not fully working with all the scheduler features. I have solved some of the problems on #3312200: Paragraph scheduler plugin but there is still the major problem that hook_form_alter is not being called for the paragraph entities when adding a new node which has paragraphs. That's a big problem because all users that have Paragraphs and Scheduler installed will always see the scheduer fields when adding the node, even if Scheduler is not enabled for the paragraphs.

I am sure it can be solved, but right now we are working towards the first 2.0 release and the paragraphs plugin was a last-minute addition. It can be worked on as soon as 2.0 is released.

Do you know if a new hook_update has to be written to remove the publish_on and unpublish_on fields that were added in your scheduler_update_8205() ? For those users who installed 2.0-rc5 and have Paragraphs installed there could be a problem if the plugin is removed?

dieterholvoet’s picture

Do you know if a new hook_update has to be written to remove the publish_on and unpublish_on fields that were added in your scheduler_update_8205() ? For those users who installed 2.0-rc5 and have Paragraphs installed there could be a problem if the plugin is removed?

Not immediately and I don't think I'll have time to work on this during the coming week. We'd probably have to update SchedulerManager::entityUpdate or add a new method for handling removing fields.

jonathan1055’s picture

Thanks, and sorry to have to revert this out. Most of your work here will remain committed, its just the plugin and events files which will be removed. I will add them back into #3312200: Paragraph scheduler plugin and re-purpose that issue to add all the paragraph work to-date, so that you can have a working MR and patch if you need it.

I've tested going from rc5 to a branch without the two files mentioned, and the existing paragraphs can be editted without any problem. There are schema errors with missing third-party settings, which I can fix in a hook_update. Yes, like you mentioned it might be worth making it a general function much like SchedulerManager::entityUpdate which could also be called from a drush function. That could be useful in other circumstances too.

jonathan1055’s picture

Status: Needs work » Needs review
StatusFileSize
new10.77 KB

For some unexplained reason I cannot create a new branch on this issue (can on others but not here). Therefore going back to old-school patch file for checking here.

There is no test coverage for the new hook_update, but I have tested it locally, both with the UI and via the new drush command drush scheduler:entity-revert, starting with a site at Scheduler 2.0.0.rc5, enabling Parahraphs for Scheduler, entering dates, then switching to the new Scheduler branch. All works fine.

  • jonathan1055 committed 451d016 on 2.x
    Issue #3259200 by jonathan1055: Remove Paragraph plugin
    
jonathan1055’s picture

Title: Plugin to support Paragraph entity type » [REVERTED] Plugin to support Paragraph entity type
Status: Needs review » Fixed

Now that the plugin and event files have been removed from 2.x this issue can be closed. The secondary issue #3312200: Paragraph scheduler plugin will become the main one to add the plugin files and solve the remaining bugs.

anfor’s picture

Hi @jonathan1055,

In the hook scheduler_update_8206 the module name isn't correct.

It must be

\Drupal::moduleHandler()->moduleExists('paragraphs')

instead of

\Drupal::moduleHandler()->moduleExists('paragraph')

I needed to execute the drush command manually to actually delete the fields.
> drush scheduler:entity-revert

Regards,

anybody’s picture

@anfor please create a separate follow-up issue for that important bug!

anfor’s picture

@Anybody, you are right, I should have created an issue from the get go.

Here we go : https://www.drupal.org/project/scheduler/issues/3317944

jonathan1055’s picture

Thanks @anfor for reporting that bug. I thoight I had tested it, but I must have got confused between my dev environments and tested on a site which actually did not have Paragraphs enabled anyway.

@Anybody I would have fixed it on this issue, but will now do it on #3317944: Paragraph module machine name in hook_update_N

Status: Fixed » Closed (fixed)

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