When adding scheduler options for publishing and unpublishing nodes the options never get saved.

I looked at trying to fix this but need some guidance. I saw that the path module in core uses a widget, is this the right route to go down?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pfrenssen’s picture

Title: Sceduler options not saving » Scheduler options not saving

You can find the code that was originally handling this is in scheduler_node_validate(). In Drupal 8 hook_node_validate() was removed. This is the change record: hook_node_validate() and hook_node_submit() have been removed.

Seems like we need to implement some validation constraints!

joekers’s picture

Assigned: Unassigned » joekers
FileSize
1.87 KB

Thanks for the pointer in your comment :) I haven't added any validation constraints as I think it's covered in other issues.

joekers’s picture

Status: Active » Needs review
pfrenssen’s picture

Status: Needs review » Needs work

Looking very good. When testing it out I get a fatal error when viewing the node, but that's a different issue, I'll make a follow-up about it.

  1. +++ b/scheduler.edit.inc
    @@ -148,6 +149,15 @@ function _scheduler_form_alter(array &$form, FormStateInterface $form_state) {
    +/**
    + * Entity builder for nodes with scheduler options.
    + */
    +function scheduler_node_builder($entity_type, NodeInterface $node, &$form, FormStateInterface $form_state) {
    +  $node->publish_on = $form_state->getValue('publish_on');
    +  $node->unpublish_on = $form_state->getValue('unpublish_on');
     }
    

    I would move this out of scheduler.edit.inc and into scheduler.module. The edit page is only included when an actual form alter takes place and might not be included when a cached form is reused. I can imagine that this would break in special cases such as multistep forms, inline entity forms etc.

  2. +++ b/scheduler.module
    @@ -449,10 +449,12 @@ function scheduler_node_presave(EntityInterface $node) {
    -    $publish_immediately = variable_get('scheduler_publish_past_date_' . $node->getType(), 'error') == 'publish';
    

    Ah so there were some calls left to variable_get()? Nice catch!

  3. +++ b/scheduler.module
    @@ -449,10 +449,12 @@ function scheduler_node_presave(EntityInterface $node) {
    +    $type = $node->type->entity;
    

    This looks strange to me but it works and I could not find a better way to do it.

    $node->getEntityType() returns the definition instead of the entity, so that's not the right solution.

    I guess it's fine for now.

So the only thing that needs to be done is moving the entity builder function to scheduler.module.

pfrenssen’s picture

Created followup issue for the fatal error: #2495011: Fatal error when viewing a scheduled node.

pfrenssen’s picture

joekers’s picture

Status: Needs work » Needs review
FileSize
2.46 KB

1. I've moved the scheduler_node_builder() to scheduler.module :)

2. Yeah I think there's still some more though but they don't seem to be causing any errors with anything I've been updating.

3. I thought so too but I couldn't find another way.

pfrenssen’s picture

Assigned: joekers » Unassigned
Status: Needs review » Fixed

Thanks a lot! Merged into 8.x-1.x.

  • pfrenssen committed 5d47fba on 8.x-1.x authored by joekers
    Issue #2487303 by joekers: Scheduler options not saving.
    

Status: Fixed » Closed (fixed)

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