本文整理汇总了PHP中Drupal\Core\DependencyInjection\ContainerBuilder::getDefinition方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::getDefinition方法的具体用法?PHP ContainerBuilder::getDefinition怎么用?PHP ContainerBuilder::getDefinition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\DependencyInjection\ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder::getDefinition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: alter
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container)
{
$definition = $container->getDefinition('asset.resolver');
$argument = new Reference('cache.null');
$definition->replaceArgument(5, $argument);
$definition = $container->getDefinition('library.discovery.collector');
$argument = new Reference('cache.null');
$definition->replaceArgument(0, $argument);
}
示例2: alter
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container)
{
$definition = $container->getDefinition('language_manager');
$definition->setClass('Drupal\\language\\ConfigurableLanguageManager')->addArgument(new Reference('config.factory'))->addArgument(new Reference('module_handler'))->addArgument(new Reference('language.config_factory_override'))->addArgument(new Reference('request_stack'));
if ($default_language_values = $this->getDefaultLanguageValues()) {
$container->setParameter('language.default_values', $default_language_values);
}
// For monolingual sites, we explicitly set the default language for the
// language config override service as there is no language negotiation.
if (!$this->isMultilingual()) {
$container->getDefinition('language.config_factory_override')->addMethodCall('setLanguageFromDefault', array(new Reference('language.default')));
}
}
示例3: alter
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container)
{
if ($container->has('file.usage')) {
// Override the class used for the file.usage service.
$definition = $container->getDefinition('file.usage');
$definition->setClass('Drupal\\service_provider_test\\TestFileUsage');
}
}
示例4: alter
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container)
{
$definition = $container->getDefinition('menu.active_trail');
$definition->setClass('Drupal\\menu_trail_by_path\\MenuTrailByPathActiveTrail');
$definition->addArgument(new Reference('language_manager'));
$definition->addArgument(new Reference('path.current'));
$definition->addArgument(new Reference('path.alias_manager'));
}
示例5: alter
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container)
{
$definition = $container->getDefinition('country_manager');
// Overrides country_manager class to add additional functionality.
$definition->setClass('Drupal\\uc_country\\CountryManager');
// Inject the entity_type.manager service, which is not available in
// the core country_manager.
$definition->addArgument(new Reference('entity_type.manager'));
}
示例6: alter
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container)
{
$definition = $container->getDefinition('menu.link_tree');
// Use custom CustomMenuLinkTree class instead of the
// default MenuLinkTree class.
$definition->setClass('Drupal\\custom\\CustomMenuLinkTree');
// Provide an additional argument to the service to add
// the current_route_match service.
$definition->addArgument(new Reference('current_route_match'));
}
示例7: alter
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container)
{
if ($container->has('file.usage')) {
// Override the class used for the file.usage service.
$definition = $container->getDefinition('file.usage');
$definition->setClass('Drupal\\service_provider_test\\TestFileUsage');
}
if ($indicator = Settings::get('deployment_identifier')) {
$container->setParameter('container_rebuild_indicator', $indicator);
}
}
示例8: alter
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container)
{
// Ensure that URLs generated for the home and admin pages don't have
// 'update.php' in them.
$request = Request::createFromGlobals();
$definition = $container->getDefinition('url_generator');
$definition->addMethodCall('setBasePath', array(str_replace('/core', '', $request->getBasePath()) . '/'));
// We need to set the script path to an empty string since the value
// determined by \Drupal\Core\Routing\UrlGenerator::setRequest() is invalid
// once '/core' has been removed from the base path.
$definition->addMethodCall('setScriptPath', array(''));
}
示例9: addLightbox
/**
* @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
* @param $id
* @param $title
*/
protected function addLightbox(ContainerBuilder $container, $id, $title)
{
$definition = $container->getDefinition($id);
$tags = $definition->getTags();
foreach ($tags as $delta => &$tag) {
if ($delta === 'render.main_content_renderer') {
foreach ($tag as &$attribute) {
$attribute['ng_lightbox'] = $title;
}
}
}
$definition->setTags($tags);
}
示例10: addRouteProvider
/**
* Add the on demand rebuild route provider service.
*
* @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
*/
public static function addRouteProvider(ContainerBuilder $container)
{
foreach (['router.route_provider' => 'RouteProvider'] as $original_id => $class) {
// While $container->get() does a recursive resolve, getDefinition() does
// not, so do it ourselves.
for ($id = $original_id; $container->hasAlias($id); $id = (string) $container->getAlias($id)) {
}
$definition = $container->getDefinition($id);
$definition->clearTag('needs_destruction');
$container->setDefinition("simpletest.{$original_id}", $definition);
$container->setDefinition($id, new Definition('Drupal\\simpletest\\' . $class));
}
}
示例11: testParseDefinitionsWithProvider
public function testParseDefinitionsWithProvider()
{
$yml = <<<YAML
services:
example_service:
class: \\Drupal\\Core\\ExampleClass
YAML;
vfsStream::setup('drupal', NULL, ['modules/example/example.yml' => $yml]);
$builder = new ContainerBuilder();
$yaml_file_loader = new YamlFileLoader($builder);
$yaml_file_loader->load('vfs://drupal/modules/example/example.yml');
$this->assertEquals(['_provider' => [['provider' => 'example']]], $builder->getDefinition('example_service')->getTags());
}
示例12: alter
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container)
{
if ($container->has('config.factory')) {
// The configuration factory depends on the cache factory, but that
// depends on the 'cache_default_bin_backends' parameter that has not yet
// been set by \Drupal\Core\Cache\ListCacheBinsPass::process() at this
// point.
$parameter_name = 'cache_default_bin_backends';
if (!$container->hasParameter($parameter_name)) {
$container->setParameter($parameter_name, []);
}
/** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */
$config_factory = $container->get('config.factory');
$config = $config_factory->get('libraries.settings');
if (!$config->isNew()) {
// Set the local definition path.
$container->getDefinition('libraries.definition.discovery.local')->replaceArgument(1, $config->get('definition.local.path'));
// Set the remote definition URL. Note that this is set even if
// the remote discovery is not enabled below in case the
// 'libraries.definition.discovery.remote' service is used explicitly.
$container->getDefinition('libraries.definition.discovery.remote')->replaceArgument(2, $config->get('definition.remote.url'));
// Because it is less convenient to remove a method call than to add
// one, the remote discovery is not registered in libraries.services.yml
// and instead added here, even though the 'definition.remote.enable'
// configuration value is TRUE by default.
if ($config->get('definition.remote.enable')) {
// Add the remote discovery to the list of chained discoveries.
$container->getDefinition('libraries.definition.discovery')->addMethodCall('addDiscovery', [new Reference('libraries.definition.discovery.remote')]);
}
}
// At this point the event dispatcher has not yet been populated with
// event subscribers by RegisterEventSubscribersPass::process() but has
// already bin injected in the configuration factory. Reset those services
// accordingly.
$container->set('event_dispatcher', NULL);
$container->set('config.factory', NULL);
}
}
示例13: alter
public function alter(ContainerBuilder $container)
{
// Override the password_migrate class with a new class.
try {
$definition = $container->getDefinition('password_migrate');
$definition->setClass('Drupal\\multiversion\\MigratePassword');
} catch (InvalidArgumentException $e) {
// Do nothing, migrate module is not installed.
}
$renderer_config = $container->getParameter('renderer.config');
$renderer_config['required_cache_contexts'][] = 'workspace';
$container->setParameter('renderer.config', $renderer_config);
// Switch the menu tree storage to our own that respect Workspace cache
// contexts.
$definition = $container->getDefinition('menu.tree_storage');
$definition->setClass('Drupal\\multiversion\\MenuTreeStorage');
// Override the comment.statistics class with a new class.
try {
$definition = $container->getDefinition('comment.statistics');
$definition->setClass('Drupal\\multiversion\\CommentStatistics');
} catch (InvalidArgumentException $e) {
// Do nothing, comment module is not installed.
}
}
示例14: alter
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container)
{
// Disable configuration overrides.
// ConfigFactory would to try to load language overrides and InstallStorage
// throws an exception upon trying to load a non-existing file.
$container->get('config.factory')->setOverrideState(FALSE);
// No service may persist when the early installer kernel is rebooted into
// the production environment.
// @todo The DrupalKernel reboot performed by drupal_install_system() is
// actually not a "regular" reboot (like ModuleHandler::install()), so
// services are not actually persisted.
foreach ($container->findTaggedServiceIds('persist') as $id => $tags) {
$definition = $container->getDefinition($id);
$definition->clearTag('persist');
}
}
示例15: alter
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container)
{
// Disable Twig cache (php storage does not exist yet).
$twig_config = $container->getParameter('twig.config');
$twig_config['cache'] = FALSE;
$container->setParameter('twig.config', $twig_config);
// No service may persist when the early installer kernel is rebooted into
// the production environment.
// @todo The DrupalKernel reboot performed by drupal_install_system() is
// actually not a "regular" reboot (like ModuleHandler::install()), so
// services are not actually persisted.
foreach ($container->findTaggedServiceIds('persist') as $id => $tags) {
$definition = $container->getDefinition($id);
$definition->clearTag('persist');
}
}