/**
  * @todo Remove content_translation_edit_page().
  */
 public function edit(Request $request, $language)
 {
     $entity = $request->attributes->get($request->attributes->get('_entity_type_id'));
     module_load_include('pages.inc', 'content_translation');
     $language = language_load($language);
     return content_translation_edit_page($entity, $language);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function render(ResultRow $values)
 {
     $value = $this->getValue($values);
     $language = language_load($value);
     $value = $language ? $language->name : '';
     return $this->renderLink($this->sanitizeValue($value), $values);
 }
 /**
  * Overrides TypedData::getValue().
  *
  * @return \Drupal\Core\Language\LanguageInterface|null
  */
 public function getValue()
 {
     if (!isset($this->language) && $this->id) {
         $this->language = language_load($this->id);
     }
     return $this->language;
 }
 /**
  * {@inheritdoc}
  */
 public function render(ResultRow $values)
 {
     // @todo: Drupal Core dropped native language until config translation is
     // ready, see http://drupal.org/node/1616594.
     $value = $this->getValue($values);
     $language = language_load($value);
     return $language ? $language->name : '';
 }
 /**
  * Tests configuration context when rebuilding the menu router table.
  */
 public function testMenuRouterRebuildContext()
 {
     // Enter a language context before rebuilding the menu router tables.
     \Drupal::languageManager()->setConfigOverrideLanguage(language_load('nl'));
     \Drupal::service('router.builder')->rebuild();
     // Check that the language context was not used for building the menu item.
     $menu_items = \Drupal::entityManager()->getStorage('menu_link')->loadByProperties(array('route_name' => 'menu_test.context'));
     $menu_item = reset($menu_items);
     $this->assertTrue($menu_item['link_title'] == 'English', 'Config context overrides are ignored when rebuilding menu router items.');
 }
 public function setUp()
 {
     parent::setUp();
     // Create test languages.
     $this->langcodes = array(language_load('en'));
     for ($i = 1; $i < 3; ++$i) {
         $language = new Language(array('id' => 'l' . $i, 'name' => $this->randomString()));
         language_save($language);
         $this->langcodes[$i] = $language;
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm()
 {
     global $user;
     $output = array();
     // Show which users can access this node.
     $menu_item = menu_get_item();
     $map = $menu_item['original_map'];
     if ($map[0] != 'node' || !isset($map[1]) || !is_numeric($map[1]) || isset($map[2])) {
         // Ignore anything but node/%.
         return NULL;
     }
     if (isset($menu_item['map'][1]) && is_object($node = $menu_item['map'][1])) {
         // We have the node.
     } elseif (is_numeric($menu_item['original_map'][1])) {
         $node = node_load($menu_item['original_map'][1]);
     }
     if (isset($node)) {
         $nid = $node->id();
         $langcode = $node->langcode->value;
         $language = language_load($langcode);
         $node_type = node_type_load($node->bundle());
         $headers = array(t('username'), '<span title="' . t("Create '@langname'-language nodes of the '@Node_type' type.", array('@langname' => $language->name, '@Node_type' => $node_type->name)) . '">' . t('create') . '</span>', t('view'), t('update'), t('delete'));
         $rows = array();
         // Determine whether to use Ajax or pre-populate the tables.
         if ($ajax = \Drupal::config('devel_node_access.settings')->get('user_ajax')) {
             $output['#attached']['library'][] = 'devel_node_access/node_access';
         }
         // Find all users. The following operations are very inefficient, so we
         // limit the number of users returned.  It would be better to make a
         // pager query, or at least make the number of users configurable.  If
         // anyone is up for that please submit a patch.
         $query = db_select('users', 'u')->fields('u', array('uid'))->orderBy('u.access', 'DESC')->range(0, 9);
         $uids = $query->execute()->fetchCol();
         array_unshift($uids, 0);
         $accounts = user_load_multiple($uids);
         foreach ($accounts as $account) {
             $username = theme('username', array('account' => $account));
             $uid = $account->id();
             if ($uid == $user->id()) {
                 $username = '******' . $username . '</strong>';
             }
             $rows[] = array($username, array('id' => 'create-' . $nid . '-' . $uid, 'class' => 'dna-permission', 'data' => $ajax ? NULL : theme('dna_permission', array('permission' => self::explain_access('create', $node, $account, $langcode)))), array('id' => 'view-' . $nid . '-' . $uid, 'class' => 'dna-permission', 'data' => $ajax ? NULL : theme('dna_permission', array('permission' => self::explain_access('view', $node, $account, $langcode)))), array('id' => 'update-' . $nid . '-' . $uid, 'class' => 'dna-permission', 'data' => $ajax ? NULL : theme('dna_permission', array('permission' => self::explain_access('update', $node, $account, $langcode)))), array('id' => 'delete-' . $nid . '-' . $uid, 'class' => 'dna-permission', 'data' => $ajax ? NULL : theme('dna_permission', array('permission' => self::explain_access('delete', $node, $account, $langcode)))));
         }
         if (count($rows)) {
             $output['title'] = array('#prefix' => '<h2>', '#markup' => t('Access permissions by user for the %langname language', array('%langname' => $language->name)), '#postfix' => '</h2>');
             $output[] = array('#theme' => 'table', '#header' => $headers, '#rows' => $rows, '#attributes' => array('style' => 'text-align: left'));
             $output[] = array('#theme' => 'form_element', '#description' => t('(This table lists the most-recently active users. Hover your mouse over each result for more details.)'));
         }
     }
     return $output;
 }
 /**
  * {@inheritdoc}
  */
 public function access(Route $route, Request $request, AccountInterface $account)
 {
     // For the translation forms we have a target language, so we need some
     // checks in addition to the checks performed for the translation overview.
     $base_access = parent::access($route, $request, $account);
     if ($base_access === static::ALLOW) {
         $target_language = language_load($request->attributes->get('langcode'));
         // Make sure that the target language is not locked, and that the target
         // language is not the original submission language. Although technically
         // configuration can be overlaid with translations in the same language,
         // that is logically not a good idea.
         $access = !empty($target_language) && !$target_language->locked && $target_language->id != $this->sourceLanguage->id;
         return $access ? static::ALLOW : static::DENY;
     }
     return static::DENY;
 }
 /**
  * Checks translation access for the entity and operation on the given route.
  *
  * @param \Symfony\Component\Routing\Route $route
  *   The route to check against.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  * @param string $source
  *   (optional) For a create operation, the language code of the source.
  * @param string $target
  *   (optional) For a create operation, the language code of the translation.
  * @param string $language
  *   (optional) For an update or delete operation, the language code of the
  *   translation being updated or deleted.
  *
  * @return string
  *   A \Drupal\Core\Access\AccessInterface constant value.
  */
 public function access(Route $route, Request $request, AccountInterface $account, $source = NULL, $target = NULL, $language = NULL)
 {
     $entity_type = $request->attributes->get('_entity_type_id');
     /** @var $entity \Drupal\Core\Entity\EntityInterface */
     if ($entity = $request->attributes->get($entity_type)) {
         $operation = $route->getRequirement('_access_content_translation_manage');
         $controller = content_translation_controller($entity_type, $account);
         // Load translation.
         $translations = $entity->getTranslationLanguages();
         $languages = language_list();
         switch ($operation) {
             case 'create':
                 $source = language_load($source) ?: $entity->language();
                 $target = language_load($target) ?: \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT);
                 return $source->id != $target->id && isset($languages[$source->id]) && isset($languages[$target->id]) && !isset($translations[$target->id]) && $controller->getTranslationAccess($entity, $operation) ? static::ALLOW : static::DENY;
             case 'update':
             case 'delete':
                 $language = language_load($language) ?: \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT);
                 return isset($languages[$language->id]) && $language->id != $entity->getUntranslated()->language()->id && isset($translations[$language->id]) && $controller->getTranslationAccess($entity, $operation) ? static::ALLOW : static::DENY;
         }
     }
     return static::DENY;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, array &$form_state, Request $request = NULL, $plugin_id = NULL, $langcode = NULL)
 {
     /** @var \Drupal\config_translation\ConfigMapperInterface $mapper */
     $mapper = $this->configMapperManager->createInstance($plugin_id);
     $mapper->populateFromRequest($request);
     $language = language_load($langcode);
     if (!$language) {
         throw new NotFoundHttpException();
     }
     $this->mapper = $mapper;
     $this->language = $language;
     return parent::buildForm($form, $form_state);
 }
 /**
  * Tests the contact category translation.
  */
 public function testContactConfigEntityTranslation()
 {
     $this->drupalLogin($this->admin_user);
     $this->drupalGet('admin/structure/contact');
     // Check for default contact form configuration entity from Contact module.
     $this->assertLinkByHref('admin/structure/contact/manage/feedback');
     // Save default language configuration.
     $label = 'Send your feedback';
     $edit = array('label' => $label, 'recipients' => 'sales@example.com,support@example.com', 'reply' => 'Thank you for your mail');
     $this->drupalPostForm('admin/structure/contact/manage/feedback', $edit, t('Save'));
     // Ensure translation link is present.
     $translation_base_url = 'admin/structure/contact/manage/feedback/translate';
     $this->assertLinkByHref($translation_base_url);
     // Visit the form to confirm the changes.
     $this->drupalGet('contact/feedback');
     $this->assertText($label);
     foreach ($this->langcodes as $langcode) {
         $this->drupalGet($translation_base_url);
         // 'Add' link should be present for $langcode translation.
         $translation_page_url = "{$translation_base_url}/{$langcode}/add";
         $this->assertLinkByHref($translation_page_url);
         // Make sure original text is present on this page.
         $this->drupalGet($translation_page_url);
         $this->assertText($label);
         // Update translatable fields.
         $edit = array('config_names[contact.category.feedback][label][translation]' => 'Website feedback - ' . $langcode, 'config_names[contact.category.feedback][reply][translation]' => 'Thank you for your mail - ' . $langcode);
         // Save language specific version of form.
         $this->drupalPostForm($translation_page_url, $edit, t('Save translation'));
         // Expect translated values in language specific file.
         $override = \Drupal::languageManager()->getLanguageConfigOverride($langcode, 'contact.category.feedback');
         $expected = array('label' => 'Website feedback - ' . $langcode, 'reply' => 'Thank you for your mail - ' . $langcode);
         $this->assertEqual($expected, $override->get());
         // Check for edit, delete links (and no 'add' link) for $langcode.
         $this->assertNoLinkByHref("{$translation_base_url}/{$langcode}/add");
         $this->assertLinkByHref("{$translation_base_url}/{$langcode}/edit");
         $this->assertLinkByHref("{$translation_base_url}/{$langcode}/delete");
         // Visit language specific version of form to check label.
         $this->drupalGet($langcode . '/contact/feedback');
         $this->assertText('Website feedback - ' . $langcode);
         // Submit feedback.
         $edit = array('subject[0][value]' => 'Test subject', 'message[0][value]' => 'Test message');
         $this->drupalPostForm(NULL, $edit, t('Send message'));
     }
     // Now that all language translations are present, check translation and
     // original text all appear in any translated page on the translation
     // forms.
     foreach ($this->langcodes as $langcode) {
         $langcode_prefixes = array_merge(array(''), $this->langcodes);
         foreach ($langcode_prefixes as $langcode_prefix) {
             $this->drupalGet(ltrim("{$langcode_prefix}/{$translation_base_url}/{$langcode}/edit"));
             $this->assertFieldByName('config_names[contact.category.feedback][label][translation]', 'Website feedback - ' . $langcode);
             $this->assertText($label);
         }
     }
     // We get all emails so no need to check inside the loop.
     $captured_emails = $this->drupalGetMails();
     // Check language specific auto reply text in email body.
     foreach ($captured_emails as $email) {
         if ($email['id'] == 'contact_page_autoreply') {
             // Trim because we get an added newline for the body.
             $this->assertEqual(trim($email['body']), 'Thank you for your mail - ' . $email['langcode']);
         }
     }
     // Test that delete links work and operations perform properly.
     foreach ($this->langcodes as $langcode) {
         $replacements = array('%label' => t('!label !entity_type', array('!label' => $label, '!entity_type' => Unicode::strtolower(t('Contact category')))), '@language' => language_load($langcode)->name);
         $this->drupalGet("{$translation_base_url}/{$langcode}/delete");
         $this->assertRaw(t('Are you sure you want to delete the @language translation of %label?', $replacements));
         // Assert link back to list page to cancel delete is present.
         $this->assertLinkByHref($translation_base_url);
         $this->drupalPostForm(NULL, array(), t('Delete'));
         $this->assertRaw(t('@language translation of %label was deleted', $replacements));
         $this->assertLinkByHref("{$translation_base_url}/{$langcode}/add");
         $this->assertNoLinkByHref("translation_base_url/{$langcode}/edit");
         $this->assertNoLinkByHref("{$translation_base_url}/{$langcode}/delete");
         // Expect no language specific file present anymore.
         $override = \Drupal::languageManager()->getLanguageConfigOverride($langcode, 'contact.category.feedback');
         $this->assertTrue($override->isNew());
     }
     // Check configuration page with translator user. Should have no access.
     $this->drupalLogout();
     $this->drupalLogin($this->translator_user);
     $this->drupalGet('admin/structure/contact/manage/feedback');
     $this->assertResponse(403);
     // While translator can access the translation page, the edit link is not
     // present due to lack of permissions.
     $this->drupalGet($translation_base_url);
     $this->assertNoLink(t('Edit'));
     // Check 'Add' link for French.
     $this->assertLinkByHref("{$translation_base_url}/fr/add");
 }
Example #12
0
 /**
  * Tests menu configuration is still English after English has been deleted.
  */
 function testMenuLanguageRemovedEnglish()
 {
     // Create a test menu to test language settings.
     // Machine name has to be lowercase.
     $menu_name = Unicode::strtolower($this->randomMachineName(16));
     $edit = array('id' => $menu_name, 'description' => '', 'label' => $this->randomString(), 'langcode' => 'en');
     $this->drupalPostForm('admin/structure/menu/add', $edit, t('Save'));
     // Check that the language settings were saved.
     $menu = Menu::load($menu_name);
     $this->assertEqual($menu->language()->getId(), 'en');
     // Remove English language. To do that another language has to be set as
     // default.
     $language = language_load('cs');
     $language->default = TRUE;
     language_save($language);
     language_delete('en');
     // Save the menu again and check if the language is still the same.
     $this->drupalPostForm("admin/structure/menu/manage/{$menu_name}", array(), t('Save'));
     $menu = Menu::load($menu_name);
     $this->assertEqual($menu->language()->getId(), 'en');
 }
 /**
  * {@inheritdoc}
  */
 public function write(NodeInterface $node, array $grants, $realm = NULL, $delete = TRUE)
 {
     if ($delete) {
         $query = $this->database->delete('node_access')->condition('nid', $node->id());
         if ($realm) {
             $query->condition('realm', array($realm, 'all'), 'IN');
         }
         $query->execute();
     }
     // Only perform work when node_access modules are active.
     if (!empty($grants) && count($this->moduleHandler->getImplementations('node_grants'))) {
         $query = $this->database->insert('node_access')->fields(array('nid', 'langcode', 'fallback', 'realm', 'gid', 'grant_view', 'grant_update', 'grant_delete'));
         // If we have defined a granted langcode, use it. But if not, add a grant
         // for every language this node is translated to.
         foreach ($grants as $grant) {
             if ($realm && $realm != $grant['realm']) {
                 continue;
             }
             if (isset($grant['langcode'])) {
                 $grant_languages = array($grant['langcode'] => language_load($grant['langcode']));
             } else {
                 $grant_languages = $node->getTranslationLanguages(TRUE);
             }
             foreach ($grant_languages as $grant_langcode => $grant_language) {
                 // Only write grants; denies are implicit.
                 if ($grant['grant_view'] || $grant['grant_update'] || $grant['grant_delete']) {
                     $grant['nid'] = $node->id();
                     $grant['langcode'] = $grant_langcode;
                     // The record with the original langcode is used as the fallback.
                     if ($grant['langcode'] == $node->language()->getId()) {
                         $grant['fallback'] = 1;
                     } else {
                         $grant['fallback'] = 0;
                     }
                     $query->values($grant);
                 }
             }
         }
         $query->execute();
     }
 }
 /**
  * {@inheritdoc}
  */
 public function language()
 {
     return language_load($this->langcode);
 }
 /**
  * Tests locale override based on language.
  */
 function testConfigLanguageOverride()
 {
     // The language module implements a config factory override object that
     // overrides configuration when the Language module is enabled. This test ensures that
     // English overrides work.
     \Drupal::languageManager()->setConfigOverrideLanguage(language_load('en'));
     $config = \Drupal::config('config_test.system');
     $this->assertIdentical($config->get('foo'), 'en bar');
     // Ensure that the raw data is not translated.
     $raw = $config->getRawData();
     $this->assertIdentical($raw['foo'], 'bar');
     ConfigurableLanguage::createFromLangcode('fr')->save();
     ConfigurableLanguage::createFromLangcode('de')->save();
     \Drupal::languageManager()->setConfigOverrideLanguage(language_load('fr'));
     $config = \Drupal::config('config_test.system');
     $this->assertIdentical($config->get('foo'), 'fr bar');
     \Drupal::languageManager()->setConfigOverrideLanguage(language_load('de'));
     $config = \Drupal::config('config_test.system');
     $this->assertIdentical($config->get('foo'), 'de bar');
     // Test overrides of completely new configuration objects. In normal runtime
     // this should only happen for configuration entities as we should not be
     // creating simple configuration objects on the fly.
     \Drupal::languageManager()->getLanguageConfigOverride('de', 'config_test.new')->set('language', 'override')->save();
     $config = \Drupal::config('config_test.new');
     $this->assertTrue($config->isNew(), 'The configuration object config_test.new is new');
     $this->assertIdentical($config->get('language'), 'override');
     $old_state = \Drupal::configFactory()->getOverrideState();
     \Drupal::configFactory()->setOverrideState(FALSE);
     $config = \Drupal::config('config_test.new');
     $this->assertIdentical($config->get('language'), NULL);
     \Drupal::configFactory()->setOverrideState($old_state);
     // Test how overrides react to base configuration changes. Set up some base
     // values.
     \Drupal::config('config_test.foo')->set('value', array('key' => 'original'))->set('label', 'Original')->save();
     \Drupal::languageManager()->getLanguageConfigOverride('de', 'config_test.foo')->set('value', array('key' => 'override'))->set('label', 'Override')->save();
     \Drupal::languageManager()->getLanguageConfigOverride('fr', 'config_test.foo')->set('value', array('key' => 'override'))->save();
     \Drupal::configFactory()->clearStaticCache();
     $config = \Drupal::config('config_test.foo');
     $this->assertIdentical($config->get('value'), array('key' => 'override'));
     // Ensure renaming the config will rename the override.
     \Drupal::configFactory()->rename('config_test.foo', 'config_test.bar');
     $config = \Drupal::config('config_test.bar');
     $this->assertEqual($config->get('value'), array('key' => 'original'));
     $override = \Drupal::languageManager()->getLanguageConfigOverride('de', 'config_test.foo');
     $this->assertTrue($override->isNew());
     $this->assertEqual($override->get('value'), NULL);
     $override = \Drupal::languageManager()->getLanguageConfigOverride('de', 'config_test.bar');
     $this->assertFalse($override->isNew());
     $this->assertEqual($override->get('value'), array('key' => 'override'));
     $override = \Drupal::languageManager()->getLanguageConfigOverride('fr', 'config_test.bar');
     $this->assertFalse($override->isNew());
     $this->assertEqual($override->get('value'), array('key' => 'override'));
     // Ensure changing data in the config will update the overrides.
     $config = \Drupal::config('config_test.bar')->clear('value.key')->save();
     $this->assertEqual($config->get('value'), array());
     $override = \Drupal::languageManager()->getLanguageConfigOverride('de', 'config_test.bar');
     $this->assertFalse($override->isNew());
     $this->assertEqual($override->get('value'), NULL);
     // The French override will become empty and therefore removed.
     $override = \Drupal::languageManager()->getLanguageConfigOverride('fr', 'config_test.bar');
     $this->assertTrue($override->isNew());
     $this->assertEqual($override->get('value'), NULL);
     // Ensure deleting the config will delete the override.
     \Drupal::configFactory()->get('config_test.bar')->delete();
     $override = \Drupal::languageManager()->getLanguageConfigOverride('de', 'config_test.bar');
     $this->assertTrue($override->isNew());
     $this->assertEqual($override->get('value'), NULL);
 }
Example #16
0
 /**
  * Element specific validator for the Add language button.
  */
 public function validatePredefined($form, &$form_state)
 {
     $langcode = $form_state['values']['predefined_langcode'];
     if ($langcode == 'custom') {
         $this->setFormError('predefined_langcode', $form_state, $this->t('Fill in the language details and save the language with <em>Add custom language</em>.'));
     } else {
         if ($language = language_load($langcode)) {
             $this->setFormError('predefined_langcode', $form_state, $this->t('The language %language (%langcode) already exists.', array('%language' => $language->name, '%langcode' => $langcode)));
         }
     }
 }
Example #17
0
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     $results = array();
     if (!$this->isSearchExecutable()) {
         return $results;
     }
     $keys = $this->keywords;
     // Build matching conditions.
     $query = $this->database->select('search_index', 'i', array('target' => 'replica'))->extend('Drupal\\search\\SearchQuery')->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender');
     $query->join('node_field_data', 'n', 'n.nid = i.sid');
     $query->condition('n.status', 1)->addTag('node_access')->searchExpression($keys, $this->getPluginId());
     // Handle advanced search filters in the f query string.
     // \Drupal::request()->query->get('f') is an array that looks like this in
     // the URL: ?f[]=type:page&f[]=term:27&f[]=term:13&f[]=langcode:en
     // So $parameters['f'] looks like:
     // array('type:page', 'term:27', 'term:13', 'langcode:en');
     // We need to parse this out into query conditions, some of which go into
     // the keywords string, and some of which are separate conditions.
     $parameters = $this->getParameters();
     if (!empty($parameters['f']) && is_array($parameters['f'])) {
         $filters = array();
         // Match any query value that is an expected option and a value
         // separated by ':' like 'term:27'.
         $pattern = '/^(' . implode('|', array_keys($this->advanced)) . '):([^ ]*)/i';
         foreach ($parameters['f'] as $item) {
             if (preg_match($pattern, $item, $m)) {
                 // Use the matched value as the array key to eliminate duplicates.
                 $filters[$m[1]][$m[2]] = $m[2];
             }
         }
         // Now turn these into query conditions. This assumes that everything in
         // $filters is a known type of advanced search.
         foreach ($filters as $option => $matched) {
             $info = $this->advanced[$option];
             // Insert additional conditions. By default, all use the OR operator.
             $operator = empty($info['operator']) ? 'OR' : $info['operator'];
             $where = new Condition($operator);
             foreach ($matched as $value) {
                 $where->condition($info['column'], $value);
             }
             $query->condition($where);
             if (!empty($info['join'])) {
                 $query->join($info['join']['table'], $info['join']['alias'], $info['join']['condition']);
             }
         }
     }
     // Add the ranking expressions.
     $this->addNodeRankings($query);
     // Run the query and load results.
     $find = $query->fields('i', array('langcode'))->groupBy('i.langcode')->limit(10)->execute();
     // Check query status and set messages if needed.
     $status = $query->getStatus();
     if ($status & SearchQuery::EXPRESSIONS_IGNORED) {
         drupal_set_message($this->t('Your search used too many AND/OR expressions. Only the first @count terms were included in this search.', array('@count' => $this->searchSettings->get('and_or_limit'))), 'warning');
     }
     if ($status & SearchQuery::LOWER_CASE_OR) {
         drupal_set_message($this->t('Search for either of the two terms with uppercase <strong>OR</strong>. For example, <strong>cats OR dogs</strong>.'), 'warning');
     }
     if ($status & SearchQuery::NO_POSITIVE_KEYWORDS) {
         drupal_set_message(\Drupal::translation()->formatPlural($this->searchSettings->get('index.minimum_word_size'), 'You must include at least one positive keyword with 1 character or more.', 'You must include at least one positive keyword with @count characters or more.'), 'warning');
     }
     $node_storage = $this->entityManager->getStorage('node');
     $node_render = $this->entityManager->getViewBuilder('node');
     foreach ($find as $item) {
         // Render the node.
         /** @var \Drupal\node\NodeInterface $node */
         $node = $node_storage->load($item->sid)->getTranslation($item->langcode);
         $build = $node_render->view($node, 'search_result', $item->langcode);
         unset($build['#theme']);
         // Fetch comment count for snippet.
         $node->rendered = SafeMarkup::set(drupal_render($build) . ' ' . SafeMarkup::escape($this->moduleHandler->invoke('comment', 'node_update_index', array($node, $item->langcode))));
         $extra = $this->moduleHandler->invokeAll('node_search_result', array($node, $item->langcode));
         $language = language_load($item->langcode);
         $username = array('#theme' => 'username', '#account' => $node->getOwner());
         $results[] = array('link' => $node->url('canonical', array('absolute' => TRUE, 'language' => $language)), 'type' => String::checkPlain($this->entityManager->getStorage('node_type')->load($node->bundle())->label()), 'title' => $node->label(), 'user' => drupal_render($username), 'date' => $node->getChangedTime(), 'node' => $node, 'extra' => $extra, 'score' => $item->calculated_score, 'snippet' => search_excerpt($keys, $node->rendered, $item->langcode), 'langcode' => $node->language()->getId());
     }
     return $results;
 }
Example #18
0
    $_SCONFIG['language'] = $_SC['language'];
    // Default Language
}
if ($_SCOOKIE['mylanguage']) {
    $_SCOOKIE['mylanguage'] = str_replace('.', '', trim($_SCOOKIE['mylanguage']));
    if (is_dir(S_ROOT . './language/' . $_SCOOKIE['mylanguage'])) {
        $_SCONFIG['language'] = $_SCOOKIE['mylanguage'];
    } else {
        ssetcookie('mylanguage', '', 365000);
        //		ssetcookie('mylanguage', $_SCONFIG['language'], 365000);
    }
} else {
    ssetcookie('mylanguage', $_SCONFIG['language'], 365000);
}
$_TPL['default_language'] = $_TPL['languages'][$_SCONFIG['language']];
language_load('lang_source');
language_append('sourcelang', 'lang_source2');
language_append('sourcelang', 'lang_template');
//----------------------------------------------------------------------
//Handle REQUEST_URI
if (!isset($_SERVER['REQUEST_URI'])) {
    $_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
        $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
    }
}
if ($_SERVER['REQUEST_URI']) {
    $temp = urldecode($_SERVER['REQUEST_URI']);
    if (strexists($temp, '<') || strexists($temp, '"')) {
        $_GET = shtmlspecialchars($_GET);
        //XSS
Example #19
0
/**
 * Alter replacement values for placeholder tokens.
 *
 * @param $replacements
 *   An associative array of replacements returned by hook_tokens().
 * @param $context
 *   The context in which hook_tokens() was called. An associative array with
 *   the following keys, which have the same meaning as the corresponding
 *   parameters of hook_tokens():
 *   - 'type'
 *   - 'tokens'
 *   - 'data'
 *   - 'options'
 *
 * @see hook_tokens()
 */
function hook_tokens_alter(array &$replacements, array $context)
{
    $options = $context['options'];
    if (isset($options['langcode'])) {
        $url_options['language'] = language_load($options['langcode']);
        $langcode = $options['langcode'];
    } else {
        $langcode = NULL;
    }
    if ($context['type'] == 'node' && !empty($context['data']['node'])) {
        $node = $context['data']['node'];
        // Alter the [node:title] token, and replace it with the rendered content
        // of a field (field_title).
        if (isset($context['tokens']['title'])) {
            $title = $node->field_title->view('default');
            $replacements[$context['tokens']['title']] = drupal_render($title);
        }
    }
}
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $_entity_type_id = NULL, $language = NULL)
 {
     $this->entity = $this->getRequest()->attributes->get($_entity_type_id);
     $this->language = language_load($language);
     return parent::buildForm($form, $form_state);
 }
 /**
  * Implements \Drupal\Core\Form\FormInterface::buildForm().
  *
  * Builds configuration form with metadata and values from the source
  * language.
  *
  * @param array $form
  *   An associative array containing the structure of the form.
  * @param array $form_state
  *   An associative array containing the current state of the form.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   (optional) Page request object.
  * @param string $plugin_id
  *   (optional) The plugin ID of the mapper.
  * @param string $langcode
  *   (optional) The language code of the language the form is adding or
  *   editing.
  *
  * @return array
  *   The form structure.
  *
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  *   Throws an exception if the language code provided as a query parameter in
  *   the request does not match an active language.
  */
 public function buildForm(array $form, array &$form_state, Request $request = NULL, $plugin_id = NULL, $langcode = NULL)
 {
     /** @var \Drupal\config_translation\ConfigMapperInterface $mapper */
     $mapper = $this->configMapperManager->createInstance($plugin_id);
     $mapper->populateFromRequest($request);
     $language = language_load($langcode);
     if (!$language) {
         throw new NotFoundHttpException();
     }
     $this->mapper = $mapper;
     $this->language = $language;
     $this->sourceLanguage = $this->mapper->getLanguageWithFallback();
     // Get base language configuration to display in the form before setting the
     // language to use for the form. This avoids repetitively settings and
     // resetting the language to get original values later.
     $config_factory = $this->configFactory();
     $old_state = $config_factory->getOverrideState();
     $config_factory->setOverrideState(FALSE);
     $this->baseConfigData = $this->mapper->getConfigData();
     $config_factory->setOverrideState($old_state);
     // Set the translation target language on the configuration factory.
     $original_language = $this->languageManager->getConfigOverrideLanguage();
     $this->languageManager->setConfigOverrideLanguage($this->language);
     // Add some information to the form state for easier form altering.
     $form_state['config_translation_mapper'] = $this->mapper;
     $form_state['config_translation_language'] = $this->language;
     $form_state['config_translation_source_language'] = $this->sourceLanguage;
     $form['#attached']['library'][] = 'config_translation/drupal.config_translation.admin';
     $form['config_names'] = array('#type' => 'container', '#tree' => TRUE);
     foreach ($this->mapper->getConfigNames() as $name) {
         $form['config_names'][$name] = array('#type' => 'container');
         $form['config_names'][$name] += $this->buildConfigForm($this->typedConfigManager->get($name), $config_factory->get($name)->get(), $this->baseConfigData[$name]);
     }
     $form['actions']['#type'] = 'actions';
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save translation'), '#button_type' => 'primary');
     // Set the configuration language back.
     $this->languageManager->setConfigOverrideLanguage($original_language);
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function getLanguageWithFallback()
 {
     $langcode = $this->getLangcode();
     $language = language_load($langcode);
     // If the language of the file is English but English is not a configured
     // language on the site, create a mock language object to represent this
     // language run-time. In this case, the title of the language is
     // 'Built-in English' because we assume such configuration is shipped with
     // core and the modules and not custom created. (In the later case an
     // English language configured on the site is assumed.)
     if (empty($language) && $langcode == 'en') {
         $language = new Language(array('id' => 'en', 'name' => $this->t('Built-in English')));
     }
     return $language;
 }
Example #23
0
 /**
  * Element specific validator for the Add language button.
  */
 public function validatePredefined($form, FormStateInterface $form_state)
 {
     $langcode = $form_state->getValue('predefined_langcode');
     if ($langcode == 'custom') {
         $form_state->setErrorByName('predefined_langcode', $this->t('Fill in the language details and save the language with <em>Add custom language</em>.'));
     } else {
         if ($language = language_load($langcode)) {
             $form_state->setErrorByName('predefined_langcode', $this->t('The language %language (%langcode) already exists.', array('%language' => $language->getName(), '%langcode' => $langcode)));
         }
     }
 }