/**
  * {@inheritdoc}
  */
 public function getDefaultInstanceSettings($type)
 {
     $plugin_definition = $this->getDefinition($type, FALSE);
     if (!empty($plugin_definition['class'])) {
         $plugin_class = DefaultFactory::getPluginClass($type, $plugin_definition);
         return $plugin_class::defaultInstanceSettings();
     }
     return array();
 }
 /**
  * {@inheritdoc}
  *
  * A specific createInstance method is necessary to pass the migration on.
  */
 public function createInstance($plugin_id, array $configuration = array(), MigrationInterface $migration = NULL)
 {
     $plugin_definition = $this->getDefinition($plugin_id);
     $plugin_class = DefaultFactory::getPluginClass($plugin_id, $plugin_definition);
     // If the plugin provides a factory method, pass the container to it.
     if (is_subclass_of($plugin_class, 'Drupal\\Core\\Plugin\\ContainerFactoryPluginInterface')) {
         $plugin = $plugin_class::create(\Drupal::getContainer(), $configuration, $plugin_id, $plugin_definition, $migration);
     } else {
         $plugin = new $plugin_class($configuration, $plugin_id, $plugin_definition, $migration);
     }
     return $plugin;
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  *
  * Passes the $parentZone along to the instantiated plugin.
  */
 public function createInstance($pluginId, array $configuration = [], ZoneInterface $parentZone = NULL)
 {
     $pluginDefinition = $this->getDefinition($pluginId);
     $pluginDefinition['parent_zone'] = $parentZone;
     $plugin_class = DefaultFactory::getPluginClass($pluginId, $pluginDefinition);
     // Generate an id for the plugin instance, if it wasn't provided.
     if (empty($configuration['id'])) {
         $configuration['id'] = $this->uuidService->generate();
     }
     // If the plugin provides a factory method, pass the container to it.
     if (is_subclass_of($plugin_class, 'Drupal\\Core\\Plugin\\ContainerFactoryPluginInterface')) {
         $plugin = $plugin_class::create(\Drupal::getContainer(), $configuration, $pluginId, $pluginDefinition, $parentZone);
     } else {
         $plugin = new $plugin_class($configuration, $pluginId, $pluginDefinition, $parentZone);
     }
     return $plugin;
 }
 /**
  * Returns an array of applicable widget or formatter options for a field.
  *
  * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
  *   The field definition.
  *
  * @return array
  *   An array of applicable widget or formatter options.
  */
 protected function getApplicablePluginOptions(FieldDefinitionInterface $field_definition)
 {
     $options = $this->pluginManager->getOptions($field_definition->getType());
     $applicable_options = array();
     foreach ($options as $option => $label) {
         $plugin_class = DefaultFactory::getPluginClass($option, $this->pluginManager->getDefinition($option));
         if ($plugin_class::isApplicable($field_definition)) {
             $applicable_options[$option] = $label;
         }
     }
     return $applicable_options;
 }
 /**
  * {@inheritdoc}
  */
 public function createInstance($plugin_id, array $configuration = array(), ImageToolkitInterface $toolkit = NULL)
 {
     $plugin_definition = $this->getDefinition($plugin_id);
     $plugin_class = DefaultFactory::getPluginClass($plugin_id, $plugin_definition);
     return new $plugin_class($configuration, $plugin_id, $plugin_definition, $toolkit, $this->logger);
 }
 /**
  * Overrides \Drupal\Component\Plugin\PluginManagerBase::createInstance().
  */
 public function createInstance($plugin_id, array $configuration = array())
 {
     $plugin_definition = $this->getDefinition($plugin_id);
     $plugin_class = DefaultFactory::getPluginClass($plugin_id, $plugin_definition);
     return new $plugin_class($configuration['filepath']);
 }
 /**
  * Tests getPluginClass() with a required interface but no implementation.
  *
  * @expectedException \Drupal\Component\Plugin\Exception\PluginException
  * @expectedExceptionMessage Plugin "cherry" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) in core should implement interface \Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface.
  */
 public function testGetPluginClassWithInterfaceAndInvalidClass()
 {
     $plugin_class = 'Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\Kale';
     DefaultFactory::getPluginClass('cherry', ['class' => $plugin_class, 'provider' => 'core'], '\\Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\FruitInterface');
 }
 /**
  * Tests getPluginClass() with a required interface but no implementation.
  *
  * @covers ::getPluginClass
  *
  * @expectedException \Drupal\Component\Plugin\Exception\PluginException
  */
 public function testGetPluginClassWithInterfaceAndInvalidClassWithObjectPluginDefinition()
 {
     $plugin_class = Kale::class;
     $plugin_definition = $this->getMock(PluginDefinitionInterface::class);
     $plugin_definition->expects($this->atLeastOnce())->method('getClass')->willReturn($plugin_class);
     DefaultFactory::getPluginClass('cherry', $plugin_definition, FruitInterface::class);
 }
 /**
  * Overrides \Drupal\Component\Plugin\PluginManagerBase::createInstance().
  *
  * Pass the TipsBag to the plugin constructor.
  */
 public function createInstance($plugin_id, array $configuration = array(), $style = NULL)
 {
     $plugin_definition = $this->discovery->getDefinition($plugin_id);
     $plugin_class = DefaultFactory::getPluginClass($plugin_id, $plugin_definition);
     return new $plugin_class($configuration, $plugin_id, $plugin_definition, $style);
 }
 /**
  * {@inheritdoc}
  */
 public function createInstance($plugin_id, array $configuration = array())
 {
     $plugin_definition = $this->getDefinition($plugin_id);
     $plugin_class = DefaultFactory::getPluginClass($plugin_id, $plugin_definition, 'Drupal\\Core\\Archiver\\ArchiverInterface');
     return new $plugin_class($configuration['filepath']);
 }