amcgowanca / discoverable_entity_bundle_classes Goto Github PK
View Code? Open in Web Editor NEWEnables entity type provider entity base class overrides on a per-bundle basis.
License: GNU General Public License v2.0
Enables entity type provider entity base class overrides on a per-bundle basis.
License: GNU General Public License v2.0
This package could really benefit from some examples. discoverable_entity_bundle_classes
is a fine name but at first read its so generic that its hard to grasp. Examples might be lifted from https://www.drupal.org/project/drupal/issues/2570593
With the release of 9.3 and this https://www.drupal.org/node/3191609, does it make sense to deprecate this module for core?
Current implementation
protected function postLoad(array &$entities) {
$entity_class = $this->getEntityClass();
$entity_class::postLoad($this, $entities);
// Call hook_entity_load().
foreach ($this->moduleHandler()
->getImplementations('entity_load') as $module) {
$function = $module . '_entity_load';
$function($entities, $this->entityTypeId);
}
// Call hook_TYPE_load().
foreach ($this->moduleHandler()
->getImplementations($this->entityTypeId . '_load') as $module) {
$function = $module . '_' . $this->entityTypeId . '_load';
$function($entities);
}
}
does not determine entity_class
of used entity bundle, but rather of the given parent entity, as there is no parameter given to getEntityClass()
.
I suggest to invoke the postLoad
hook by bundle. Maybe like following.
protected function postLoad(array &$entities) {
// We have to determine the bundle first.
$bundle = FALSE;
if (!empty($entities) && isset($this->bundleKey)) {
$entity = reset($entities);
$bundle = $entity->get($this->bundleKey)->getString();
}
$entity_class = $this->getEntityClass($bundle);
$entity_class::postLoad($this, $entities);
// Call hook_entity_load().
foreach ($this->moduleHandler()
->getImplementations('entity_load') as $module) {
$function = $module . '_entity_load';
$function($entities, $this->entityTypeId);
}
// Call hook_TYPE_load().
foreach ($this->moduleHandler()
->getImplementations($this->entityTypeId . '_load') as $module) {
$function = $module . '_' . $this->entityTypeId . '_load';
$function($entities);
}
}
Is the module compatible with D9? Is maintenance still happenning?
Plugin managers should call alterInfo() in the contructor. This exists in an older version of the module that we have, but doesn't exist in the version here.
https://www.drupal.org/docs/drupal-apis/plugin-api/creating-your-own-plugin-manager
The SqlContentEntityStorageBase.php
should also have:
+use Drupal\Core\Entity\EntityStorageException
As of Drupal 8.6.x
the mapFromStorageRecords()
method in the SqlContentEntityStorage
class was changed. These changes should also be represented in the SqlContentEntityStorageTrait
of the discoverable_entity_bundle_classes
module.
I will send a pull request when I am done testing.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.