Created
August 14, 2013 22:39
-
-
Save neclimdul/6236392 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Contains Drupal\Core\Plugin\Discovery\YamlDiscovery. | |
*/ | |
namespace Drupal\Core\Plugin\Discovery; | |
use Drupal\Component\Plugin\Discovery\DiscoveryInterface; | |
use Drupal\Component\Discovery\YamlDiscovery as DrupalYamlDiscovery; | |
use Drupal\Core\Extension\ModuleHandlerInterface; | |
/** | |
* Allows Yaml files to discover plugin definitions. | |
* | |
* @todo there should be a base class provided so every YAML file doesn't have to specify the implementation. | |
*/ | |
class YamlDiscovery implements DiscoveryInterface { | |
/** | |
* Internal YAML parsing handler. | |
* | |
* @var \Drupal\Component\Discovery\YamlDiscovery | |
*/ | |
protected $discovery; | |
/** | |
* The extension handler for retrieving the list of enabled modules. | |
* | |
* @var \Drupal\Core\Extension\ModuleHandlerInterface | |
*/ | |
protected $moduleHandler; | |
/** | |
* Construct a YamlDiscovery object. | |
* | |
* @param string $name | |
* The | |
* @param ModuleHandlerInterface $module_handler | |
* The module handler service. | |
*/ | |
function __construct($name, ModuleHandlerInterface $module_handler) { | |
$this->moduleHandler = $module_handler; | |
$this->discovery = new DrupalYamlDiscovery($name, $this->moduleHandler->getModuleDirectories()); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getDefinition($plugin_id) { | |
$plugins = $this->getDefinitions(); | |
return isset($plugins[$plugin_id]) ? $plugins[$plugin_id] : NULL; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getDefinitions() { | |
return $this->discovery->findAll(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment