dx_toolkit
6 sites
No security coverage
DX Toolkit provides reusable developer primitives—standardized patterns and plugin systems that improve code quality and reduce boilerplate in Drupal custom module development. Now available as a beta release for community testing.
- EntityGenerator plugin system for programmatically creating companion configuration entities. Solves use cases like:
- Generating a View Mode for every bundle of a custom entity type.
- Generating a REST Resource configuration for every Content Type
- Generating a Feed Type for every Taxonomy Vocabulary.
- FeedTypeGenerator base plugin provides specialized support for the Feeds ecosystem, handling both Feed Type and Feed entity creation and import.
- ServiceInstance pattern for self-identifying services with inline instantiation support.
- ServiceInstanceInterface requires implementing classes to declare their service name, enabling
MyService::getService()syntax. - ServiceInstanceTrait provides the implementation, allowing IDE autocompletion like
MyService::getService()->someMethod()in static contexts. - Simplifies testing by making mock container injection straightforward.
- ServiceInstanceInterface requires implementing classes to declare their service name, enabling
- Plugin enhancements via extended base classes for annotation plugin definitions and plugin manager definition.
- PluginManager includes additional methods:
- createInstances: Returns all plugin instances, optionally filtered by base plugin ID.
- getPluginDerivatives: Returns all definitions for a base plugin ID.
- createDerivativeInstances: Returns all plugin instances for a base plugin ID
- optionLabels: Returns id/label arrays for use in FAPI
#optionsproperties.
- PluginManagerPropertyQueryInterface / PluginManagerPropertyQueryTrait pair for returning definitions by property values from plugin manager. Gives plugin managers capability similar to entity storage handler's
loadByPropertiesmethod.
- PluginManager includes additional methods:
- Core utility extensions that add production-tested functionality to Drupal's component layer.
- Environment utility class extends
\Drupal\Component\Utility\Environmentwith enhanced CLI detection. - Color utility class extends
Drupal\Component\Utility\Colorwith hex normalization, luminance calculations, and contrast checking (YIQ, luminance, 50% algorithms). - Json utility class extends
Drupal\Component\Serialization\Jsonwith control character removal and BOM stripping for malformed JSON handling.
- Environment utility class extends
-
General purpose utilities:
- ArrayUtilities class
- arrayKeysCombined: Combines keys from two arrays into key/value pairs.
- arrayMapMerged: Provides one-level flattening of the results returned from the provided array_map callback.
- arrayFlattenRecursive: Provides recursive flattening of the results returned from the provided array_map callback.
- arrayKeyColumn: Derivative of
array_column()function that maintains parent key associations. - arraySortByKeys: Sorts one array by the keys of another.
- AsArrayTrait provides a simple trait for ensuring a value is always an array.
- OptionsGenerator that generates key/label arrays from an array of entities or a storage handler.
- StateBase provides an OO wrapper for the State key/value store.
- ExtensionBase provides extension-specific metadata.
Demo Module: The included dx_toolkit_demo submodule provides working implementations of all plugin systems and patterns. Enable it to see concrete examples of ServiceInjector plugins with derivers, EntityGenerator implementations, and ServiceInstance pattern usage. Use these as templates for your own projects.
Note: This is a Beta release intended for community testing. The plugin systems and utilities have been used in production environments. Please report any bugs or feature requests to the issue queue.