Unverified Commit c1d24b91 authored by sean_e_dietrich's avatar sean_e_dietrich Committed by e0ipso

Issue #3047728 by e0ipso, sean_e_dietrich, cindytwilliams: Allow for enhancers...

Issue #3047728 by e0ipso, sean_e_dietrich, cindytwilliams: Allow for enhancers to require dependencies in order to be usable
parent 635ddd0b
......@@ -47,4 +47,11 @@ class ResourceFieldEnhancer extends Plugin {
*/
public $class;
/**
* The name of modules that are required for this Field Enhancer to be usable.
*
* @var array
*/
public $dependencies;
}
......@@ -35,4 +35,27 @@ class ResourceFieldEnhancerManager extends DefaultPluginManager {
$this->setCacheBackend($cache_backend, 'resource_field_enhancer_plugins');
}
/**
* {@inheritdoc}
*/
protected function alterDefinitions(&$definitions) {
// Loop through all definitions.
foreach ($definitions as $definition_key => $definition_info) {
// Check to see if dependencies key is set.
if (!empty($definition_info['dependencies'])) {
$definition_dependencies = $definition_info['dependencies'];
// Loop through dependencies to confirm if enabled.
foreach ($definition_dependencies as $dependency) {
// If dependency is not enabled removed from list of definitions.
if (!$this->moduleHandler->moduleExists($dependency)) {
unset($definitions[$definition_key]);
continue;
}
}
}
}
parent::alterDefinitions($definitions);
}
}
......@@ -12,7 +12,8 @@ use Shaper\Util\Context;
* @ResourceFieldEnhancer(
* id = "date_time",
* label = @Translation("Date Time (Timestamp field)"),
* description = @Translation("Formats a date based the configured date format for timestamp fields.")
* description = @Translation("Formats a date based the configured date format for timestamp fields."),
* dependencies = {"datetime"}
* )
*/
class DateTimeEnhancer extends DateTimeEnhancerBase {
......
......@@ -12,7 +12,8 @@ use Shaper\Util\Context;
* @ResourceFieldEnhancer(
* id = "date_time_from_string",
* label = @Translation("Date Time (Date Time field)"),
* description = @Translation("Formats a date based the configured date format for date fields.")
* description = @Translation("Formats a date based the configured date format for date fields."),
* dependencies = {"datetime"}
* )
*/
class DateTimeFromStringEnhancer extends DateTimeEnhancerBase {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment