populateFromRouteMatch example


  protected function getMapperFromRouteMatch(RouteMatchInterface $route_match) {
    $mapper = $this->configMapperManager->createInstance($route_match->getRouteObject()
      ->getDefault('plugin_id'));
    $mapper->populateFromRouteMatch($route_match);
    return $mapper;
  }

  /** * Checks access given an account, configuration mapper, and source language. * * Grants access if the proper permission is granted to the account, the * configuration has translatable pieces, and the source language is not * locked given it is present. * * @param \Drupal\Core\Session\AccountInterface $account * The account to check access for. * @param \Drupal\config_translation\ConfigMapperInterface $mapper * The configuration mapper to check access for. * @param \Drupal\Core\Language\LanguageInterface|null $source_language * The source language to check for, if any. * * @return \Drupal\Core\Access\AccessResultInterface * The result of the access check. */
public function testAddingConfigNames() {
    // Get a config names mapper.     $mappers = \Drupal::service('plugin.manager.config_translation.mapper')->getMappers();
    $mapper = $mappers['system.site_information_settings'];

    // Test that it doesn't contain a config name from config_translation_test.     $config_names = $mapper->getConfigNames();
    $this->assertNotContains('config_translation_test.content', $config_names);

    // Call populateFromRouteMatch() to dispatch the "config mapper populate"     // event.     $mapper->populateFromRouteMatch(new RouteMatch('test', new Route('/')));

    // Test that it contains the new config name from config_translation_test.     $config_names = $mapper->getConfigNames();
    $this->assertContains('config_translation_test.content', $config_names);
  }

}

  public function itemPage(Request $request, RouteMatchInterface $route_match$plugin_id) {
    /** @var \Drupal\config_translation\ConfigMapperInterface $mapper */
    $mapper = $this->configMapperManager->createInstance($plugin_id);
    $mapper->populateFromRouteMatch($route_match);

    $page = [];
    $page['#title'] = $this->t('Translations for %label', ['%label' => $mapper->getTitle()]);

    $languages = $this->languageManager->getLanguages();
    if (count($languages) == 1) {
      $this->messenger()->addWarning($this->t('In order to translate configuration, the website must have at least two <a href=":url">languages</a>.', [':url' => Url::fromRoute('entity.configurable_language.collection')->toString()]));
    }

    try {
      $original_langcode = $mapper->getLangcode();
      
$container->get('language_manager'),
      $container->get('event_dispatcher')
    );
  }

  /** * {@inheritdoc} */
  public function populateFromRouteMatch(RouteMatchInterface $route_match) {
    $entity = $route_match->getParameter($this->entityType);
    $this->setEntity($entity);
    parent::populateFromRouteMatch($route_match);
  }

  /** * Gets the entity instance for this mapper. * * @return \Drupal\Core\Config\Entity\ConfigEntityInterface * The configuration entity. */
  public function getEntity() {
    return $this->entity;
  }

  
public function testGetAddRouteName() {
    $result = $this->configNamesMapper->getAddRouteName();
    $expected = 'config_translation.item.add.' . $this->pluginDefinition['base_route_name'];
    $this->assertSame($expected$result);
  }

  /** * Tests ConfigNamesMapper::getAddRouteParameters(). */
  public function testGetAddRouteParameters() {
    $route_match = new RouteMatch('example', new Route('/test/{langcode}')['langcode' => 'xx']);
    $this->configNamesMapper->populateFromRouteMatch($route_match);

    $expected = ['langcode' => 'xx'];
    $result = $this->configNamesMapper->getAddRouteParameters();
    $this->assertSame($expected$result);
  }

  /** * Tests ConfigNamesMapper::getAddRoute(). */
  public function testGetAddRoute() {
    $expected = new Route('/admin/config/system/site-information/translate/{langcode}/add',
      [

  public function getFormId() {
    return 'config_translation_delete_form';
  }

  /** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state, RouteMatchInterface $route_match = NULL, $plugin_id = NULL, $langcode = NULL) {
    /** @var \Drupal\config_translation\ConfigMapperInterface $mapper */
    $mapper = $this->configMapperManager->createInstance($plugin_id);
    $mapper->populateFromRouteMatch($route_match);

    $language = $this->languageManager->getLanguage($langcode);
    if (!$language) {
      throw new NotFoundHttpException();
    }

    $this->mapper = $mapper;
    $this->language = $language;
    return parent::buildForm($form$form_state);
  }

  

  public function buildForm(array $form, FormStateInterface $form_state, RouteMatchInterface $route_match = NULL, $plugin_id = NULL, $langcode = NULL) {
    /** @var \Drupal\config_translation\ConfigMapperInterface $mapper */
    $mapper = $this->configMapperManager->createInstance($plugin_id);
    $mapper->populateFromRouteMatch($route_match);

    $language = $this->languageManager->getLanguage($langcode);
    if (!$language) {
      throw new NotFoundHttpException();
    }

    $this->mapper = $mapper;
    $this->language = $language;

    // ConfigTranslationFormAccess will not grant access if this raises an     // exception, so we can call this without a try-catch block here.
Home | Imprint | This part of the site doesn't use cookies.