Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291123

Allow for optional dependencies

$
0
0

If your module depends on the service of another module , we do not have a very good way to get injection currently. You can't just add it as an argument. You would need to write something ContainerAware and that's ouch. Here's a patch.

Here's how it works:

  arguments: ['@plugin.manager.entity']
  tags:
    - {name: optional_dependency, block_manager: '@plugin.manager.block' }

And then

<?php
function __construct(EntityManager $entity_manager, array $optional_dependencies = array()) {
 
$this->entityManager = $entity_manager;
  if (isset(
$optional_dependencies['block_manager'])) {
   
$this->blockManager = $optional_dependencies['block_manager'];
  }
}
function
postSave() {
  if (
$this->blockManager) {
   
$this->blockManager->clearCachedDefinitions();
  }
}
?>
AttachmentSizeStatusTest resultOperations
OptionalDependencyPass.patch2.9 KBIdleFAILED: [[SimpleTest]]: [MySQL] Setup environment: Test cancelled by admin prior to completion.View details | Re-test

Viewing all articles
Browse latest Browse all 291123

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>