Problem/Motivation
This issue is a follow up of #2096585: Support for non-node entities, e.g. Media, Commerce Products, Custom 3rd-party entities.
While implementing a custom Scheduler Plugin for Taxonomy Terms I noticed a couple of issues, that might appear for other entity types as well and can be easily addressed.
1. Currently only entity types are supported whose entity bundle type name ends with _type
This is a little too biased towards the currently implemented entity types. The entity bundle type name is flexible and can vary between the entity types, so there is no common pattern. Luckily it's rather easy to fetch this information from an entity by replacing
$entity_type = $this->entityTypeManager->getStorage($entityTypeId . '_type')->load($entity->bundle());
with
$bundle_type = $entity->getEntityType()->getBundleEntityType();
$entity_type = $this->entityTypeManager->getStorage($bundle_type)->load($entity->bundle());
2. Currently no entity types are supported who miss the created property and implement getCreatedTime() and setCreatedTime()
There might be some entity types like taxonomy terms, that don't have a created property by default. Conceptually it's only needed for the configuration option
Change *** creation time to match the scheduled publish time
I implemented a logic, that checks, if the method exists for the currently processed entity. On the form I'm disabling those options for entity types, that don't support it by creating an empty entity object and check if the method exists.
Issue fork scheduler-3225695
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
Comment #3
szeidlerI added a merge request that is addressing the issue.
Comment #4
jonathan1055 commentedHi szeidler,
It's great to hear that you have used the new work to implement a plugin for taxonomy terms. Thanks for the detailed feedback. Yes I am not surprised that as we get more plugins, we find more assumptions that need to have options/flexibility now. I found a large number obviously when I first expanded from Node to Media, but because Media was also a core content type there were many things that were the same. Then when we added commerce_product support we found some more that needed fixing. I'm pleased that you have only found these two things (so far)
At first glance your suggestions seem good.
Comment #5
jonathan1055 commentedI already had this following change in the pipeline, but it makes sense to add it now, in preparation for testing of other entity types.
Comment #6
szeidlerI also added support for scheduling taxonomy terms now, as you requested in Slack. That one could be used for testing and verifying that the two problems in this issue got resolved.
Credits for implementing the taxonomy term support go to @kiss.jozsef
Comment #7
jonathan1055 commentedThanks szeidler for adding you plugin files, as that immediately allows me to test the changes.
The check for
method_exists($entity, 'getCreatedTime')can be removed, but it also requires the re-ordering of the conditional elements. The option must be checked first, so that if it is negative the rest of the conditional elements will not be checked. As it stood (before my last commit) we still get the errorError: Call to undefined method Drupal\taxonomy\Entity\Term::getCreatedTime() in scheduler_entity_presave(). Testing the option first avoids this.edit: I made these changes in the commit above.
Comment #8
berdirstumbled over this issue, made a few comments on the MR
Comment #9
szeidlerThanks for the feedback @berdir. I'm wondering if we should tackle the feedback here, the original #2096585: Support for non-node entities, e.g. Media, Commerce Products, Custom 3rd-party entities or create a follow up issue.
Comment #10
jonathan1055 commentedThanks @berdir, those comments are really helpful. Just for background, the 2.x branch is very new and was created specifically so that the huge changes in #2096585: Support for non-node entities, e.g. Media, Commerce Products, Custom 3rd-party entities are started on a new branch, and 8.x-1.x will not have entity plugin support. The only commits to 2.x so far are related to this plugin work.
I would prefer not to add more changes into the above issue, as that MR has been merged with all the main work done. I will close that one soon. Clearly there are improvments that can be made, so I think they could be added to this issue (with the subject made more generic) as that is where @berdir has made the suggestions.
Comment #11
rockaholiciam commentedAdding to this thread. Currently also no entities are supported that don't support or need bundles. While going through the code, it seems to be architecturally close to the original node based implementation and relies on the bundles to function. Would it be possible to make it support non bundled entities? If not, at least it needs to be made clear that only bundled entities are supported. An alternative I have discovered is the scheduler field module. Although not too mature, but the approach is more flexible and it incorporates a similar plugin based model to practically have scheduling for tasks beyond publishing/un-publishing.
Comment #12
rockaholiciam commentedAny insights on why entity types with no bundles are not supported? Is it actually the case or am I missing something?
Comment #13
jonathan1055 commentedHi rockaholiciam,
Thanks for the prompt. It will take some major investigation but is definitely worth looking at. Can you open a new issue for this please? We will then have the discussion there, and leave this issue for the tasks already in progress.
Jonathan
Comment #14
jonathan1055 commentedThere is a problem here when Taxonomy module is enabled then Scheduler is installed, because currently the .install process is expecting a view.yml definition. Adding
taxonomyinto the functional BrowserTestBase (even if not actually testing the new taxonomy plugin) demonstrates the exception.Comment #15
jonathan1055 commentedWe have an assumption that a view showing the scheduled items will exist. Without it, the admin does not have any quick and simple way to see which terms are scheduled. They have to view the vocabulary tree and edit each term to see the status and dates. Is this acceptable? The options to solve this are:
If we decide on option 1 then we should wait for #3224340: Hardcoded local task dependency on view scheduler_scheduled_content because that has the new functionality for dynamic local tasks.
Comment #16
jonathan1055 commentedThat's better. Now that we have a scheduled taxonomy view the tests can actually run with the taxonomy module enabled, and we get 8 fails instead of 52. These will be generic failures - we are still not explicitly testing a taxonomy_term entity type yet.
Comment #17
jonathan1055 commentedThe final test failure is due to a missed occurrence of
$entityTypeId . '_type'in SchedulerAdminForm::buildForm(). This can be easily changed to use->getBundleEntityType()just as has been done in the earlier changes.NOTE: The tests are not explicitly testing the taxonomy entity type yet, this is just making sure that the existing tests run and pass when the Taxonomy module is enabled.
Comment #18
jonathan1055 commentedThere is getting to be too much going on in this single issue, so to help clarity (and be more useful as reference for future issues) I have created
#3260067: Implement Taxonomy Term scheduler plugin and
#3260070: Streamline the test coverage process when a new plugin is added
I will revert the changes in this issue back to just covering what is described in the issue title.
Comment #19
jonathan1055 commentedForce-pushed the relevent changes to this same branch and MR10.
Comment #21
jonathan1055 commentedMerged and fixed. Thanks @szeidler for the original patch and followup fixes.
Thanks also to @berdir for your review. I have not forgotten your comments and will pick them up on a different issue, as they are not directly relating to the changes here.
The followup issues #3260067: Implement Taxonomy Term scheduler plugin and #3260070: Streamline the test coverage process when a new plugin is added will have the remainder of the work I did here.