public function jireRest(Request $request)
 {
     try {
         //$jira_rest = \Drupal::service('jira_rest.jira_rest_service');
         $container = \Drupal::getContainer();
         $jira = JiraRestController::create($container);
         $author_name = $jira->config('jira_rest.settings')->get('jira_rest.username');
         $interval = "-2d";
         $res = $jira->jira_rest_searchissue("updated >= " . $interval . " AND assignee in (" . $author_name . ")");
     } catch (JiraRestException $e) {
         $responce['messages'][] = $e->getMessage();
     }
     $responce = array();
     $interval = abs(intval($interval));
     $sub_days = "{$interval} days";
     $date = date_create();
     $toDate = date_format($date, 'Y-m-d');
     date_sub($date, date_interval_create_from_date_string($sub_days));
     $fromDate = date_format($date, 'Y-m-d');
     foreach ($res->issues as $issue) {
         $worklog = $jira->jira_rest_get_worklog($issue->key);
         foreach ($worklog->worklogs as $entry) {
             $shortDate = substr($entry->started, 0, 10);
             # keep a worklog entry on $key item,
             # iff within the search time period
             if ($entry->author->name == $author_name && $shortDate >= $fromDate && $shortDate <= $toDate) {
                 $responce[$issue->key] += $entry->timeSpentSeconds;
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Test system_path_*() correctly clears caches.
  */
 public function testPathHooks()
 {
     $source = '/' . $this->randomMachineName();
     $alias = '/' . $this->randomMachineName();
     // Check system_path_insert();
     $alias_manager = $this->prophesize(AliasManagerInterface::class);
     $alias_manager->cacheClear(Argument::any())->shouldBeCalledTimes(1);
     $alias_manager->cacheClear($source)->shouldBeCalledTimes(1);
     \Drupal::getContainer()->set('path.alias_manager', $alias_manager->reveal());
     $alias_storage = \Drupal::service('path.alias_storage');
     $alias_storage->save($source, $alias);
     $new_source = '/' . $this->randomMachineName();
     $path = $alias_storage->load(['source' => $source]);
     // Check system_path_update();
     $alias_manager = $this->prophesize(AliasManagerInterface::class);
     $alias_manager->cacheClear(Argument::any())->shouldBeCalledTimes(2);
     $alias_manager->cacheClear($source)->shouldBeCalledTimes(1);
     $alias_manager->cacheClear($new_source)->shouldBeCalledTimes(1);
     \Drupal::getContainer()->set('path.alias_manager', $alias_manager->reveal());
     $alias_storage->save($new_source, $alias, LanguageInterface::LANGCODE_NOT_SPECIFIED, $path['pid']);
     // Check system_path_delete();
     $alias_manager = $this->prophesize(AliasManagerInterface::class);
     $alias_manager->cacheClear(Argument::any())->shouldBeCalledTimes(1);
     $alias_manager->cacheClear($new_source)->shouldBeCalledTimes(1);
     \Drupal::getContainer()->set('path.alias_manager', $alias_manager->reveal());
     $alias_storage->delete(['pid' => $path['pid']]);
 }
Ejemplo n.º 3
0
 /**
  * Asserts whether expected exceptions are thrown for invalid hook implementations.
  *
  * @param string $module
  *   The module whose invalid logic in its hooks to enable.
  * @param string $hook
  *   The page render hook to assert expected exceptions for.
  */
 function assertPageRenderHookExceptions($module, $hook)
 {
     $html_renderer = \Drupal::getContainer()->get('main_content_renderer.html');
     // Assert a valid hook implementation doesn't trigger an exception.
     $page = [];
     $html_renderer->invokePageAttachmentHooks($page);
     // Assert that hooks can set cache tags.
     $this->assertEqual($page['#cache']['tags'], ['example']);
     $this->assertEqual($page['#cache']['contexts'], ['user.permissions']);
     // Assert an invalid hook implementation doesn't trigger an exception.
     \Drupal::state()->set($module . '.' . $hook . '.descendant_attached', TRUE);
     $assertion = $hook . '() implementation that sets #attached on a descendant triggers an exception';
     $page = [];
     try {
         $html_renderer->invokePageAttachmentHooks($page);
         $this->error($assertion);
     } catch (\LogicException $e) {
         $this->pass($assertion);
         $this->assertEqual($e->getMessage(), 'Only #attached, #post_render_cache and #cache may be set in ' . $hook . '().');
     }
     \Drupal::state()->set('bc_test.' . $hook . '.descendant_attached', FALSE);
     // Assert an invalid hook implementation doesn't trigger an exception.
     \Drupal::state()->set('bc_test.' . $hook . '.render_array', TRUE);
     $assertion = $hook . '() implementation that sets a child render array triggers an exception';
     $page = [];
     try {
         $html_renderer->invokePageAttachmentHooks($page);
         $this->error($assertion);
     } catch (\LogicException $e) {
         $this->pass($assertion);
         $this->assertEqual($e->getMessage(), 'Only #attached, #post_render_cache and #cache may be set in ' . $hook . '().');
     }
     \Drupal::state()->set($module . '.' . $hook . '.render_array', FALSE);
 }
Ejemplo n.º 4
0
 /**
  * @implement route_alter_variants
  * @fast
  */
 static function route_alter_variants()
 {
     $alters = [];
     static::$container = \Drupal::getContainer();
     foreach (static::getFiles('/^.+\\.routing\\.yml/i') as $file) {
         $info = static::yamlDecode($file)['alter_variants'] ?? [];
         $alters = NestedArray::mergeDeep($alters, $info);
     }
     foreach ($alters as $name => $variants) {
         foreach ($variants as $k => $variant) {
             if (isset($variant['cache'])) {
                 $variant['controller'] = new CacheController($variant['cache'], $variant['controller']);
                 unset($variant['cache']);
             }
             if (isset($variant['redirect'])) {
                 $variant['controller'] = new RedirectController($variant['redirect']);
                 unset($variant['redirect']);
             }
             if (isset($variant['error'])) {
                 $variant['controller'] = new ErrorController($variant['error']);
                 unset($variant['error']);
             }
             if (is_string($variant)) {
                 $variant = ['controller' => $variant];
             }
             if (isset($variant['controller']) && is_string($variant['controller']) && strpos($variant['controller'], '::') !== FALSE) {
                 $variant['controller'] = explode('::', $variant['controller']);
             }
             static::appliesRuleDetect($variant);
             $variants[$k] = $variant;
         }
         $alters[$name] = static::sortByPriority($variants);
     }
     return $alters;
 }
Ejemplo n.º 5
0
 /**
  * Tests tablesort_init().
  */
 function testTableSortInit()
 {
     // Test simple table headers.
     $headers = array('foo', 'bar', 'baz');
     // Reset $request->query to prevent parameters from Simpletest and Batch API
     // ending up in $ts['query'].
     $expected_ts = array('name' => 'foo', 'sql' => '', 'sort' => 'asc', 'query' => array());
     $request = Request::createFromGlobals();
     $request->query->replace(array());
     \Drupal::getContainer()->get('request_stack')->push($request);
     $ts = tablesort_init($headers);
     $this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => Html::escape(var_export($ts, TRUE)))));
     $this->assertEqual($ts, $expected_ts, 'Simple table headers sorted correctly.');
     // Test with simple table headers plus $_GET parameters that should _not_
     // override the default.
     $request = Request::createFromGlobals();
     $request->query->replace(array('order' => 'bar'));
     \Drupal::getContainer()->get('request_stack')->push($request);
     $ts = tablesort_init($headers);
     $this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => Html::escape(var_export($ts, TRUE)))));
     $this->assertEqual($ts, $expected_ts, 'Simple table headers plus non-overriding $_GET parameters sorted correctly.');
     // Test with simple table headers plus $_GET parameters that _should_
     // override the default.
     $request = Request::createFromGlobals();
     $request->query->replace(array('sort' => 'DESC', 'alpha' => 'beta'));
     \Drupal::getContainer()->get('request_stack')->push($request);
     $expected_ts['sort'] = 'desc';
     $expected_ts['query'] = array('alpha' => 'beta');
     $ts = tablesort_init($headers);
     $this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => Html::escape(var_export($ts, TRUE)))));
     $this->assertEqual($ts, $expected_ts, 'Simple table headers plus $_GET parameters sorted correctly.');
     // Test complex table headers.
     $headers = array('foo', array('data' => '1', 'field' => 'one', 'sort' => 'asc', 'colspan' => 1), array('data' => '2', 'field' => 'two', 'sort' => 'desc'));
     // Reset $_GET from previous assertion.
     $request = Request::createFromGlobals();
     $request->query->replace(array('order' => '2'));
     \Drupal::getContainer()->get('request_stack')->push($request);
     $ts = tablesort_init($headers);
     $expected_ts = array('name' => '2', 'sql' => 'two', 'sort' => 'desc', 'query' => array());
     $this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => Html::escape(var_export($ts, TRUE)))));
     $this->assertEqual($ts, $expected_ts, 'Complex table headers sorted correctly.');
     // Test complex table headers plus $_GET parameters that should _not_
     // override the default.
     $request = Request::createFromGlobals();
     $request->query->replace(array('order' => 'bar'));
     \Drupal::getContainer()->get('request_stack')->push($request);
     $ts = tablesort_init($headers);
     $expected_ts = array('name' => '1', 'sql' => 'one', 'sort' => 'asc', 'query' => array());
     $this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => Html::escape(var_export($ts, TRUE)))));
     $this->assertEqual($ts, $expected_ts, 'Complex table headers plus non-overriding $_GET parameters sorted correctly.');
     // Test complex table headers plus $_GET parameters that _should_
     // override the default.
     $request = Request::createFromGlobals();
     $request->query->replace(array('order' => '1', 'sort' => 'ASC', 'alpha' => 'beta'));
     \Drupal::getContainer()->get('request_stack')->push($request);
     $expected_ts = array('name' => '1', 'sql' => 'one', 'sort' => 'asc', 'query' => array('alpha' => 'beta'));
     $ts = tablesort_init($headers);
     $this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => Html::escape(var_export($ts, TRUE)))));
     $this->assertEqual($ts, $expected_ts, 'Complex table headers plus $_GET parameters sorted correctly.');
 }
Ejemplo n.º 6
0
 protected function urlGenerator()
 {
     if (!$this->urlGenerator) {
         $this->urlGenerator = \Drupal::getContainer()->get('purl.url_generator');
     }
     return $this->urlGenerator;
 }
 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     $contactForms = \Drupal::getContainer()->get('entity.query')->get('contact_form')->execute();
     $element = [];
     $element['value'] = array('#type' => 'select', '#title' => t('Contact Form that should be rendered'), '#options' => $contactForms, '#description' => t('Select the Contact Form that should be rendered.'), '#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL);
     return $element;
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $modules[] = 'service_container_annotation_discovery_test';
     $modules[] = 'service_container_annotation_discovery_subtest';
     parent::setUp($modules);
     $this->container = \Drupal::getContainer();
 }
Ejemplo n.º 9
0
 function add_logger()
 {
     // If we're running on Drupal 8 or later, we provide a logger which will send
     // output to drush_log(). This should catch every message logged through every
     // channel.
     \Drupal::getContainer()->get('logger.factory')->addLogger(new \Drush\Log\DrushLog());
 }
Ejemplo n.º 10
0
 /**
  * @param $values
  * @return string
  */
 private function replaceValues($values)
 {
     /** TODO inject renderer service */
     $renderer = \Drupal::getContainer()->get('renderer');
     $elements = ['#theme' => 'gist_embed_filter', '#gist_data' => $values];
     return $renderer->render($elements);
 }
Ejemplo n.º 11
0
 /**
  * Converts an rdf entity id into its serialized rdf form.
  */
 protected function serializeRdfEntity($entity_id, $format = 'turtle')
 {
     $query = "DESCRIBE <{$entity_id}>";
     $sparql = \Drupal::getContainer()->get('sparql_endpoint');
     /** @var \EasyRdf\Graph $graph */
     $graph = $sparql->query($query);
     return $graph->serialise($format);
 }
Ejemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $build = [];
     $build['password_forgotten_block'] = \Drupal::getContainer()->get('form_builder')->getForm('Drupal\\user\\Form\\UserPasswordForm');
     $build['WTF'] = ['#markup' => '<div class="js-wtf"></div>'];
     $build['WTF']['#attached']['library'][] = 'user_blocks/userpopups_lapompa';
     return $build;
 }
Ejemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function __wakeup()
 {
     $container = \Drupal::getContainer();
     foreach ($this->_serviceIds as $key => $service_id) {
         $this->{$key} = $container->get($service_id);
     }
     $this->_serviceIds = array();
 }
Ejemplo n.º 14
0
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $this->setUpExampleStructure();
     \Drupal::getContainer()->get('search_api.index_task_manager')->addItemsAll(Index::load($this->indexId));
     $this->insertExampleContent();
     $this->indexItems($this->indexId);
 }
Ejemplo n.º 15
0
 /**
  * @return Drupal\taxonomy\Entity\Term|null
  */
 private static function getTempStoreCarburant()
 {
     $temp_store = \Drupal::getContainer()->get('user.private_tempstore')->get();
     $id = $temp_store->get('tip_carburant');
     if ($id) {
         return Term::load($id);
     }
 }
Ejemplo n.º 16
0
 /**
  * Gets all cache bin services.
  *
  * @return array
  *  An array of cache backend objects keyed by cache bins.
  */
 public static function getBins()
 {
     $bins = array();
     $container = \Drupal::getContainer();
     foreach ($container->getParameter('cache_bins') as $service_id => $bin) {
         $bins[$bin] = $container->get($service_id);
     }
     return $bins;
 }
Ejemplo n.º 17
0
 /**
  * Loads the real route provider from the container and rebuilds the router.
  *
  * @return \Drupal\Core\Routing\PreloadableRouteProviderInterface|\Symfony\Cmf\Component\Routing\PagedRouteProviderInterface|\Symfony\Component\EventDispatcher\EventSubscriberInterface
  *   The route provider.
  */
 protected function lazyLoadItself()
 {
     if (!isset($this->service)) {
         $container = \Drupal::getContainer();
         $this->service = $container->get('simpletest.router.route_provider');
         $container->get('router.builder')->rebuild();
     }
     return $this->service;
 }
 protected function setUp()
 {
     $this->directoryList = array('content_translation' => 'core/modules/content_translation', 'node' => 'core/modules/node');
     parent::setUp();
     $entity_type = $this->getMock('Drupal\\Core\\Entity\\EntityTypeInterface');
     $entity_type->expects($this->any())->method('getLinkTemplate')->will($this->returnValueMap(array(array('canonical', 'entity.node.canonical'), array('drupal:content-translation-overview', 'entity.node.content_translation_overview'))));
     $content_translation_manager = $this->getMock('Drupal\\content_translation\\ContentTranslationManagerInterface');
     $content_translation_manager->expects($this->any())->method('getSupportedEntityTypes')->will($this->returnValue(array('node' => $entity_type)));
     \Drupal::getContainer()->set('content_translation.manager', $content_translation_manager);
 }
Ejemplo n.º 19
0
 public function setUp()
 {
     parent::setUp();
     // Create a simple customer user account.
     $this->cart = Cart::create(\Drupal::getContainer());
     // Create a simple customer user account.
     $this->customer = $this->drupalCreateUser();
     // Ensure test mails are logged.
     \Drupal::configFactory()->getEditable('system.mail')->set('interface.uc_order', 'test_mail_collector')->save();
 }
 /**
  * {@inheritdoc}
  */
 public function createInstance($plugin_id, array $configuration = array())
 {
     $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')) {
         return $plugin_class::create(\Drupal::getContainer(), $configuration, $plugin_id, $plugin_definition);
     }
     return new $plugin_class($plugin_id, $plugin_definition, $configuration['group'], $configuration['settings'], $configuration['label']);
 }
 /**
  * Tests that services provided by module service providers get registered to the DIC.
  */
 function testServiceProviderRegistration()
 {
     $this->assertTrue(\Drupal::getContainer()->getDefinition('file.usage')->getClass() == 'Drupal\\service_provider_test\\TestFileUsage', 'Class has been changed');
     $this->assertTrue(\Drupal::hasService('service_provider_test_class'), 'The service_provider_test_class service has been registered to the DIC');
     // The event subscriber method in the test class calls drupal_set_message with
     // a message saying it has fired. This will fire on every page request so it
     // should show up on the front page.
     $this->drupalGet('');
     $this->assertText(t('The service_provider_test event subscriber fired!'), 'The service_provider_test event subscriber fired');
 }
Ejemplo n.º 22
0
 /**
  * {@inheritdoc}
  */
 public function createInstance($plugin_id, array $configuration = array())
 {
     $plugin_definition = $this->discovery->getDefinition($plugin_id);
     $plugin_class = static::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')) {
         return $plugin_class::create(\Drupal::getContainer(), $configuration, $plugin_id, $plugin_definition);
     }
     // Otherwise, create the plugin directly.
     return new $plugin_class($configuration, $plugin_id, $plugin_definition);
 }
Ejemplo n.º 23
0
 /**
  * Tests the exception handling for HTML and 404 status code.
  */
 public function testHtml404()
 {
     $request = Request::create('/not-found');
     $request->headers->set('Accept', 'text/html');
     $request->setFormat('html', ['text/html']);
     /** @var \Symfony\Component\HttpKernel\HttpKernelInterface $kernel */
     $kernel = \Drupal::getContainer()->get('http_kernel');
     $response = $kernel->handle($request)->prepare($request);
     $this->assertEqual($response->getStatusCode(), Response::HTTP_NOT_FOUND);
     $this->assertEqual($response->headers->get('Content-type'), 'text/html; charset=UTF-8');
 }
Ejemplo n.º 24
0
 function add_logger()
 {
     // If we're running on Drupal 8 or later, we provide a logger which will send
     // output to drush_log(). This should catch every message logged through every
     // channel.
     $container = \Drupal::getContainer();
     $parser = $container->get('logger.log_message_parser');
     $drushLogger = drush_get_context('DRUSH_LOG_CALLBACK');
     $logger = new \Drush\Log\DrushLog($parser, $drushLogger);
     $container->get('logger.factory')->addLogger($logger);
 }
Ejemplo n.º 25
0
 /**
  * {@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;
 }
 /**
  * {@inheritdoc}
  */
 public function __wakeup()
 {
     // Tests in isolation potentially unserialize in the parent process.
     if (isset($GLOBALS['__PHPUNIT_BOOTSTRAP']) && !\Drupal::hasContainer()) {
         return;
     }
     $container = \Drupal::getContainer();
     foreach ($this->_serviceIds as $key => $service_id) {
         $this->{$key} = $container->get($service_id);
     }
     $this->_serviceIds = array();
 }
Ejemplo n.º 27
0
 public function preRender($element)
 {
     $element['addthis_basic_toolbox'] = array('#type' => 'addthis_wrapper', '#tag' => 'div', '#attributes' => array('class' => array('addthis_toolbox', 'addthis_default_style')));
     // Add Script.
     $element['#attached']['library'][] = 'addthis/addthis.widget';
     $script_manager = \Drupal::getContainer()->get('addthis.script_manager');
     $addThisConfig = $script_manager->getAddThisConfig();
     $addThisShareConfig = $script_manager->getAddThisShareConfig();
     $element['#attached']['drupalSettings']['addThisWidget'] = ['widgetScript' => 'http://example.dev/thing.js', 'config' => $addThisConfig, 'share' => $addThisShareConfig];
     $services = trim($element['#services']);
     $services = str_replace(' ', '', $services);
     $services = explode(',', $services);
     // All service elements
     $items = array();
     foreach ($services as $service) {
         $items[$service] = array('#type' => 'addthis_element', '#tag' => 'a', 'value' => '', '#attributes' => array('class' => array('addthis_button_' . $service)), '#addthis_service' => $service);
         // Add individual counters.
         if (strpos($service, 'counter_') === 0) {
             $items[$service]['#attributes']['class'] = array("addthis_{$service}");
         }
         // Basic implementations of bubble counter orientation.
         // @todo Figure all the bubbles out and add them.
         //   Still missing: tweetme, hyves and stubleupon, google_plusone_badge.
         //
         $orientation = '';
         //($settings['counter_orientation'] == 'horizontal' ? TRUE : FALSE);
         switch ($service) {
             case 'linkedin_counter':
                 $items[$service]['#attributes'] += array('li:counter' => $orientation ? '' : 'top');
                 break;
             case 'facebook_like':
                 $items[$service]['#attributes'] += array('fb:like:layout' => $orientation ? 'button_count' : 'box_count');
                 break;
             case 'facebook_share':
                 $items[$service]['#attributes'] += array('fb:share:layout' => $orientation ? 'button_count' : 'box_count');
                 break;
             case 'google_plusone':
                 $items[$service]['#attributes'] += array('g:plusone:size' => $orientation ? 'standard' : 'tall');
                 break;
             case 'tweet':
                 $items[$service]['#attributes'] += array('tw:count' => $orientation ? 'horizontal' : 'vertical', 'tw:via' => $script_manager->getTwitterVia());
                 break;
             case 'bubble_style':
                 $items[$service]['#attributes']['class'] = array('addthis_counter', 'addthis_bubble_style');
                 break;
             case 'pill_style':
                 $items[$service]['#attributes']['class'] = array('addthis_counter', 'addthis_pill_style');
                 break;
         }
     }
     $element['addthis_basic_toolbox'] += $items;
     return $element;
 }
Ejemplo n.º 28
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     if (!$form_state->getRedirect()) {
         $data = \Drupal::moduleHandler()->invokeAll('uc_add_to_cart_data', array($form_state->getValues()));
         $msg = $this->config('uc_cart.settings')->get('add_item_msg');
         $cart = Cart::create(\Drupal::getContainer());
         $redirect = $cart->addItem($form_state->getValue('nid'), $form_state->getValue('qty'), $data, NULL, $msg);
         if (isset($redirect)) {
             $form_state->setRedirectUrl($redirect);
         }
     }
 }
Ejemplo n.º 29
0
 /**
  * @param string $plugin_id
  * @param array $configuration
  *
  * @return object
  * @throws \Exception
  */
 public function createInstance($plugin_id, array $configuration = array()) {
   if (empty($configuration['route_name'])) {
     // @todo Also check for parameters?
     throw new \Exception('Route name is require configuration for GroupCreatorManager');
   }
   $route_name = $configuration['route_name'];
   /** @var \Drupal\Core\Routing\RouteProvider $route_provider */
   $route_provider = \Drupal::getContainer()->get('router.route_provider');
   $configuration['route'] = new RouteMatch($route_name, $route_provider->getRouteByName($route_name));
   unset($configuration['route_name']);
   return parent::createInstance($plugin_id, $configuration);
 }
 /**
  * Generate the output appropriate for one field item.
  *
  * @param \Drupal\Core\Field\FieldItemInterface $item
  *   One field item.
  *
  * @return string
  *   The textual output generated.
  */
 protected function viewValue(FieldItemInterface $item)
 {
     $em = \Drupal::getContainer()->get('entity.manager');
     $storage = $em->getStorage('contact_message');
     $params = ['contact_form' => $item->value];
     $form = $storage->create($params);
     if (!$form) {
         return '';
     }
     $form = \Drupal::getContainer()->get('entity.form_builder')->getForm($form);
     return $form;
 }