/**
  * {@inheritdoc}
  */
 public function createInstance($plugin_id, array $configuration = array())
 {
     // If this PluginManager has fallback capabilities catch
     // PluginNotFoundExceptions.
     if ($this instanceof FallbackPluginManagerInterface) {
         try {
             return $this->factory->createInstance($plugin_id, $configuration);
         } catch (PluginNotFoundException $e) {
             $fallback_id = $this->getFallbackPluginId($plugin_id, $configuration);
             return $this->factory->createInstance($fallback_id, $configuration);
         }
     } else {
         return $this->factory->createInstance($plugin_id, $configuration);
     }
 }
Example #2
0
 /**
  * @param string $id
  * @param array $definition
  *
  * @return \Drupal\libraries\ExternalLibrary\Type\LibraryTypeInterface
  */
 protected function getLibraryType($id, $definition)
 {
     // @todo Validate that the type is a string.
     if (!isset($definition['type'])) {
         throw new LibraryTypeNotFoundException($id);
     }
     return $this->libraryTypeFactory->createInstance($definition['type']);
 }
 /**
  * Returns the library type that is being tested.
  *
  * @return \Drupal\libraries\ExternalLibrary\Type\LibraryTypeInterface
  *   The test library type.
  */
 protected function getLibraryType()
 {
     try {
         $library_type = $this->libraryTypeFactory->createInstance($this->getLibraryTypeId());
     } catch (PluginException $exception) {
         $library_type = $this->prophesize(LibraryTypeInterface::class)->reveal();
     } finally {
         return $library_type;
     }
 }
 /**
  * @covers ::__construct
  * @covers ::createInstance
  *
  * @expectedException \Drupal\Component\Plugin\Exception\PluginNotFoundException
  */
 public function testCreateInstanceWithNonExistingPluginAndOverriddenDiscovery()
 {
     $plugin_manager = $this->getMock(PluginManagerInterface::class);
     $this->decoratedDiscovery = $this->getMock(DiscoveryInterface::class);
     $this->decoratedFactory = $plugin_manager;
     $this->sut = new PluginManagerDecorator($plugin_manager, $this->decoratedDiscovery);
     $plugin_id = $this->randomMachineName();
     $this->decoratedDiscovery->expects($this->once())->method('getDefinitions')->willReturn([]);
     $this->decoratedFactory->expects($this->never())->method('createInstance');
     $this->sut->createInstance($plugin_id);
 }
 /**
  * Tests getHandler() without an override.
  */
 public function testGetHandlerNoOverride()
 {
     $this->setupMockedFactory();
     $item = [];
     $item['table'] = 'test_table';
     $item['field'] = 'test_field';
     $views_data = [];
     $views_data['test_field']['test']['id'] = 'test_id';
     $this->viewsData->expects($this->once())->method('get')->with('test_table')->willReturn($views_data);
     $plugin = $this->getMock('Drupal\\views\\Plugin\\views\\ViewsHandlerInterface');
     $this->factory->expects($this->once())->method('createInstance')->with('test_id')->willReturn($plugin);
     $result = $this->handlerManager->getHandler($item);
     $this->assertSame($plugin, $result);
 }
 /**
  * @covers \Drupal\Core\Menu\LocalActionManager::getActionsForRoute()
  *
  * @dataProvider getActionsForRouteProvider
  */
 public function testGetActionsForRoute($route_appears, array $plugin_definitions, array $expected_actions)
 {
     $this->discovery->expects($this->any())->method('getDefinitions')->will($this->returnValue($plugin_definitions));
     $map = array();
     foreach ($plugin_definitions as $plugin_id => $plugin_definition) {
         $plugin = $this->getMock('Drupal\\Core\\Menu\\LocalActionInterface');
         $plugin->expects($this->any())->method('getRouteName')->will($this->returnValue($plugin_definition['route_name']));
         $plugin->expects($this->any())->method('getRouteParameters')->will($this->returnValue(isset($plugin_definition['route_parameters']) ? $plugin_definition['route_parameters'] : array()));
         $plugin->expects($this->any())->method('getTitle')->will($this->returnValue($plugin_definition['title']));
         $this->controllerResolver->expects($this->any())->method('getArguments')->with($this->request, array($plugin, 'getTitle'))->will($this->returnValue(array()));
         $plugin->expects($this->any())->method('getWeight')->will($this->returnValue($plugin_definition['weight']));
         $this->controllerResolver->expects($this->any())->method('getArguments')->with($this->request, array($plugin, 'getTitle'))->will($this->returnValue(array()));
         $map[] = array($plugin_id, array(), $plugin);
     }
     $this->factory->expects($this->any())->method('createInstance')->will($this->returnValueMap($map));
     $this->assertEquals($expected_actions, $this->localActionManager->getActionsForRoute($route_appears));
 }
 /**
  * Tests the access checking of the getContextualLinksArrayByGroup method.
  *
  * @see \Drupal\Core\Menu\ContextualLinkManager::getContextualLinksArrayByGroup()
  */
 public function testGetContextualLinksArrayByGroupAccessCheck()
 {
     $definitions = array('test_plugin1' => array('id' => 'test_plugin1', 'class' => '\\Drupal\\Core\\Menu\\ContextualLinkDefault', 'title' => 'Plugin 1', 'weight' => 0, 'group' => 'group1', 'route_name' => 'test_route', 'options' => array()), 'test_plugin2' => array('id' => 'test_plugin2', 'class' => '\\Drupal\\Core\\Menu\\ContextualLinkDefault', 'title' => 'Plugin 2', 'weight' => 2, 'group' => 'group1', 'route_name' => 'test_route2', 'options' => array('key' => 'value')));
     $this->pluginDiscovery->expects($this->once())->method('getDefinitions')->will($this->returnValue($definitions));
     $this->accessManager->expects($this->any())->method('checkNamedRoute')->will($this->returnValueMap(array(array('test_route', array('key' => 'value'), $this->account, FALSE, TRUE), array('test_route2', array('key' => 'value'), $this->account, FALSE, FALSE))));
     // Set up mocking of the plugin factory.
     $map = array();
     foreach ($definitions as $plugin_id => $definition) {
         $plugin = $this->getMock('Drupal\\Core\\Menu\\ContextualLinkInterface');
         $plugin->expects($this->any())->method('getRouteName')->will($this->returnValue($definition['route_name']));
         $plugin->expects($this->any())->method('getTitle')->will($this->returnValue($definition['title']));
         $plugin->expects($this->any())->method('getWeight')->will($this->returnValue($definition['weight']));
         $plugin->expects($this->any())->method('getOptions')->will($this->returnValue($definition['options']));
         $map[] = array($plugin_id, array(), $plugin);
     }
     $this->factory->expects($this->any())->method('createInstance')->will($this->returnValueMap($map));
     $result = $this->contextualLinkManager->getContextualLinksArrayByGroup('group1', array('key' => 'value'));
     // Ensure that access checking was respected.
     $this->assertTrue(isset($result['test_plugin1']));
     $this->assertFalse(isset($result['test_plugin2']));
 }
Example #8
0
 /**
  * Returns a pre-configured menu link plugin instance.
  *
  * @param string $plugin_id
  *   The ID of the plugin being instantiated.
  * @param array $configuration
  *   An array of configuration relevant to the plugin instance.
  *
  * @return \Drupal\Core\Menu\MenuLinkInterface
  *   A menu link instance.
  *
  * @throws \Drupal\Component\Plugin\Exception\PluginException
  *   If the instance cannot be created, such as if the ID is invalid.
  */
 public function createInstance($plugin_id, array $configuration = array())
 {
     return $this->factory->createInstance($plugin_id, $configuration);
 }
Example #9
0
 /**
  * Gets the locator of this library using the locator factory.
  *
  * @param \Drupal\Component\Plugin\Factory\FactoryInterface $locator_factory
  *
  * @return \Drupal\libraries\ExternalLibrary\Local\LocatorInterface
  *
  * @see \Drupal\libraries\ExternalLibrary\Local\LocalLibraryInterface::getLocator()
  */
 public function getLocator(FactoryInterface $locator_factory)
 {
     return $locator_factory->createInstance('stream', ['scheme' => 'asset']);
 }
Example #10
0
 /**
  * Constructs a \Drupal\cas\Form\CasSettings object.
  *
  * @param ConfigFactoryInterface $config_factory
  *   The factory for configuration objects.
  * @param FactoryInterface $plugin_factory
  *   The condition plugin factory.
  */
 public function __construct(ConfigFactoryInterface $config_factory, FactoryInterface $plugin_factory)
 {
     parent::__construct($config_factory);
     $this->gatewayPaths = $plugin_factory->createInstance('request_path');
     $this->forcedLoginPaths = $plugin_factory->createInstance('request_path');
 }
 /**
  * Gets the version detector of this library using the detector factory.
  *
  * Because determining the installation version of a library is not specific
  * to any library or even any library type, this logic is offloaded to
  * separate detector objects.
  *
  * @param \Drupal\Component\Plugin\Factory\FactoryInterface $detector_factory
  *
  * @return \Drupal\libraries\ExternalLibrary\Version\VersionDetectorInterface
  *
  * @see \Drupal\libraries\ExternalLibrary\Version\VersionDetectorInterface
  */
 public function getVersionDetector(FactoryInterface $detector_factory)
 {
     return $detector_factory->createInstance($this->versionDetector['id'], $this->versionDetector['configuration']);
 }