How to integrate scheduler with custom / contrib entity types?

Created on 20 May 2025, 2 months ago

Problem/Motivation

Currently, we are working on a submodule of the Advertisement module β†’ that should implement a scheduler plugin so that the advertisement entities (ad_content bundled via ad_content_type) may have their publication scheduled. Here is our current module code.

Unfortunately, the documentation of this module is a bit unclear regarding certain steps that have to be taken for the plugin implementation. It also appears to mostly document creating support for a third-party module within Scheduler instead of using a scheduler plugin within another module.

Is there a best-practice, gapless approach for implementing a scheduler plugin as of the current state of the project? If so, could anyone please provide it or the link for it here? If it has not yet been documented properly, it definitely should be done, and we could take this issue to add it to the docs.

A pretty sound-looking explanation was made in this issue β†’ , but that on its own did not provide any apparent and usable functionality, as far as I have seen.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ’¬ Support request
Status

Active

Version

2.0

Component

Plugin

Created by

πŸ‡©πŸ‡ͺGermany lrwebks Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @lrwebks
  • πŸ‡©πŸ‡ͺGermany lrwebks Porta Westfalica
  • πŸ‡©πŸ‡ͺGermany lrwebks Porta Westfalica
  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    Hi lrwebks,

    Did you see the Scheduler documentation site https://project.pages.drupalcode.org/scheduler/plugin_create/ ?
    I can't tell from your comments above, but you may have seen this, as it was the result of the first part of #3249560: Write documentation for the entity plugin β†’ which you have linked to.

    I'd be happy to help with questions and to update the documentation if there are specific things that are missing. If you could use those steps and note down any places where you get stuck, or it is not clear, then we can improve those pages.

    Other issues on creating a plugin which may (or may not!) be helpful:
    ✨ Support for Block (display) entities Active
    ✨ Paragraph scheduler plugin Needs work
    ✨ Scheduler plugin for Commerce Product Variation Active

  • πŸ‡©πŸ‡ͺGermany lrwebks Porta Westfalica

    Thanks for your quick response, @jonathan1055,

    indeed I was aware about the docs page that you linked, but within the list of steps there appear to be a few instructions, that seem to me like this is meant to be implemented within the Scheduler Module (like support for a module from your module's side, the way that you have done it with Commerce Product already).

    Examples of what I mean:

    Add extra two lines in config/schema/scheduler.schema.yml to use the saved alias for the new third party settings.

    In scheduler.install add a hook_update function to load the new view.

    This was the case for Media and Commerce Products (note from lrwebks: Two of the modules that scheduler supports internally, which is not what we want to achieve with our module)

    Update README.md to include the new entity in the list of implementations.

    Is it enough to avoid the steps which require modification of the scheduler module, for our custom plugin implementation? Or do we have to handle that differently? If so, what are the required steps?

  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    Thanks for pointing out those bits. Yes the doc page could do with some re-work, as you are correct - those lines are specific to internal plugins provided by scheduler. I wrote it up from my notes when making the first plugin, media, and then refined it as we added commerce_product and taxonomy_term.

    Is it enough to avoid the steps which require modification of the scheduler module, for our custom plugin implementation?

    In general, yes. But there may be some things that you need to do in your module instead. An example is the first on your list - you will want to have all scheduler settings available in your content type. Whether you simply copy those from the schuduler schema or somehow get them defined dynamically to avoid duplication, you can decide on how you want to tackle it.

    I think we can use this issue to make some changes to the documentation, to explain when some steps are not required and when the change needs to be done in the 3rd-party module.

  • πŸ‡©πŸ‡ͺGermany lrwebks Porta Westfalica

    Since there were no changes to the docs yet, could you at least provide a comprehensive walkthrough or required code snippets as a comment here, so that we could continue with our plugin implementation?

  • πŸ‡©πŸ‡ͺGermany Grevil

    @lrwebks I think the comments @jonathan1055 gave here are more than enough, but I can understand that working with the schema can be confusing:

    Add extra two lines in config/schema/scheduler.schema.yml to use the saved alias for the new third party settings.

    In the scheduler.schema this:

    node.type.*.third_party.scheduler: &third_party_settings_alias
      type: mapping
      label: 'Scheduler entity type settings'
      mapping:
        [...]
    

    Simply aliases the mapping to "&third_party_settings_alias", which is then used to define the entity type third party scheduler schema objects:
    media.type.*.third_party.scheduler: *third_party_settings_alias

    Since we don't have access to the alias in our custom module we simply need to copy paste the node.type schema object and use our entity type name instead of node (we don't need the alias there of course).

    In scheduler.install add a hook_update function to load the new view.

    We simply add the update hook in our myModule.install file (only needed if the module already existed before this implementation)

    This was the case for Media and Commerce Products (note from lrwebks: Two of the modules that scheduler supports internally, which is not what we want to achieve with our module)

    Unsure what you are trying to say here?

    Update README.md to include the new entity in the list of implementations.

    This should be self-explanatory.

    I think the Plugin implementation page could definitely need some work, but it's awesome that there even is one to begin with! Thanks for that @jonathan1055!
    A few notes on the plugin documentation:

    The plugin definition properties should be documented

    Based on the names alone, it wasn't easy to see what exactly each definition property does. And correct me if I am wrong but aren't publishAction / unpublishAction and schedulerEventClass mandatory for third party modules (not living inside the scheduler module)? That would be a very important note!

    Add extra two lines in config/schema/scheduler.schema.yml [...]

    Add a comment, that we need to copy the original "node.type" schema definitions for third party modules

    Create a new view definition and save it as

    Add a comment, that the existing views inside scheduler.module can be an excellent template!

    In scheduler.install add a hook_update function to load the new view.

    Add a comment, that this is only mandatory if the third party module already existed before.

    Scheduler Rules Integration

    This should be inside an extra header, as it is not mandatory

    General

    I think it would be good to avoid explicit "scheduler" file names in the documentation. This might lead to confusion (e.g. scheduler.install => myModule.install, etc.)

    And once again, thanks for this wonderful module @jonathan1055! I appreciate the work you are doing and the great support you are giving! If you are interested in the scheduler integration @lrwebks and I implemented, for the Drupal "Advertisement" module, take a look at https://git.drupalcode.org/project/ad/-/tree/11.x/modules/ad_content_sch...! ☺️

Production build 0.71.5 2024