- Issue created by @nicodh
- Assigned to apatel0325
- Issue was unassigned.
- 🇮🇳India apatel0325
@rkcreation Can you please try below?
// Define your entity class.
class MyEntity extends ContentEntityBase {
// Define your entity properties and fields.
}// Define your entity type using the ContentEntityType class.
$contentEntityType = ContentEntityType::create([
'id' => 'my_entity',
'label' => 'My Entity',
'entity_class' => MyEntity::class,
'base_table' => 'my_entity',
// Define your entity's fields and storage settings here.
]);// Implement hook_entity_type_build() to register your entity type with Drupal.
function mymodule_entity_type_build(&$entityTypes) {
$entityTypes['my_entity'] = $contentEntityType;
}// Define a custom entity form for your entity.
function mymodule_entity_form_display(\Drupal\Core\Entity\EntityInterface $entity, $mode, $form, &$form_state) {
if ($entity->getEntityTypeId() == 'my_entity') {
// Define your custom form display here.
}
}// Define any additional functionality for your entity.
function mymodule_my_entity_validate(MyEntity $entity) {
// Define your custom validation logic here.
} - 🇫🇷France pacproduct
I am facing the same issue, but I'm not trying to create a custom entity myself: I wanted to use the 'ad' module which defines an 'ad_content' entity with no bundle.
I tried declaring a Scheduler plugin (with the idea to eventually suggest it as an addition to the 'ad' module), but after several tries and some xdebug sessions, I realized that the scheduler module explicitly excludes entity types that do not have any bundle (in
\Drupal\scheduler\SchedulerPluginManager::findDefinitions
):foreach ($definitions as $plugin_id => $plugin_definition) { [...] $entityType = $this->entityTypeManager->getDefinition($plugin_definition['entityType'], FALSE); if (!$entityType || !$entityType->getBundleEntityType()) { unset($definitions[$plugin_id]); } }
My Plugin definition gets unset right there.
Is there a workaround for enabling scheduling on contrib entities with no bundles?
- 🇬🇧United Kingdom jonathan1055
Hi rkcreation and pacproduct,
Thanks for giving your feedback here, it is useful. Currently, as you discovered, Scheduler does expect a bundle on the entity type. Scheduler 8.x-1.x only supported nodes and everything was hardcoded. This was expanded in 2.x with the entity plugin, but we did not build in from the start the possibility of using the plugin on entities without a bundle type, because it was built as a logical follow-on from nodes. Everything, all options and processing, is currently structured around entity bundle types, and there is no quick work-around.
I would be very interested to see how much work is involved in getting Scheduler to work on non-bundle entity types. It could be quite complex, or maybe it could be straight-forward if we expanded the plugin manager with new functions. My feeling is that it will be a lot of work, but that is not a reason to discard the idea.
apatel0325 - regarding your post in #2-3 above, I don't understand what you were trying to show. I think you must have mis-understood what this issue is about.