/**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, LanguageInterface $language = NULL)
 {
     if ($language) {
         $form_state->set('langcode', $language->getId());
     }
     return parent::buildForm($form, $form_state);
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function getFormElement(DataDefinitionInterface $definition, LanguageInterface $language, $value)
 {
     // Estimate a comfortable size of the input textarea.
     $rows_words = ceil(str_word_count($value) / 5);
     $rows_newlines = substr_count($value, "\n") + 1;
     $rows = max($rows_words, $rows_newlines);
     return array('#type' => 'textarea', '#default_value' => $value, '#title' => $this->t($definition->getLabel()) . '<span class="visually-hidden"> (' . $language->getName() . ')</span>', '#rows' => $rows, '#attributes' => array('lang' => $language->getId()));
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Remove the translated values.
     $this->entity = $this->entity->getUntranslated();
     $this->entity->removeTranslation($this->language->getId());
     $this->entity->save();
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
 /**
  * {@inheritdoc}
  */
 public function loadOverrides($names)
 {
     if ($this->language) {
         $storage = $this->getStorage($this->language->getId());
         return $storage->readMultiple($names);
     }
     return array();
 }
예제 #5
0
 /**
  * {@inheritdoc}
  */
 public function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config)
 {
     /** @var \Drupal\Core\Datetime\DateFormatter $date_formatter */
     $date_formatter = \Drupal::service('date.formatter');
     $description = $this->t('A user-defined date format. See the <a href="@url">PHP manual</a> for available options.', array('@url' => 'http://php.net/manual/function.date.php'));
     $format = $this->t('Displayed as %date_format', array('%date_format' => $date_formatter->format(REQUEST_TIME, 'custom', $translation_config)));
     return ['#type' => 'textfield', '#description' => $description, '#field_suffix' => ' <small data-drupal-date-formatter="preview">' . $format . '</small>', '#attributes' => ['data-drupal-date-formatter' => 'source'], '#attached' => ['drupalSettings' => ['dateFormats' => $date_formatter->getSampleDateFormats($translation_language->getId())], 'library' => ['system/drupal.system.date']]] + parent::getTranslationElement($translation_language, $source_config, $translation_config);
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 protected function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config)
 {
     $plurals = $this->getNumberOfPlurals($translation_language->getId());
     $values = explode(LOCALE_PLURAL_DELIMITER, $translation_config);
     $element = array('#type' => 'fieldset', '#title' => SafeMarkup::format('@label <span class="visually-hidden">(@translation_language)</span>', array('@label' => $this->t($this->definition->getLabel()), '@translation_language' => $translation_language->getName())), '#tree' => TRUE);
     for ($i = 0; $i < $plurals; $i++) {
         $element[$i] = array('#type' => 'textfield', '#title' => $i == 0 ? $this->t('Singular form') : $this->formatPlural($i, 'First plural form', '@count. plural form'), '#default_value' => isset($values[$i]) ? $values[$i] : '', '#attributes' => array('lang' => $translation_language->getId()));
     }
     return $element;
 }
예제 #7
0
 /**
  * Tests evaluating the condition for an alias that can not be resolved.
  *
  * @covers ::evaluate
  */
 public function testConditionEvaluationAliasWithoutPath()
 {
     $this->aliasManager->getPathByAlias('alias-for-path-that-does-not-exist', NULL)->willReturn('alias-for-path-that-does-not-exist')->shouldBeCalledTimes(1);
     $this->aliasManager->getPathByAlias('alias-for-path-that-does-not-exist', 'en')->willReturn('alias-for-path-that-does-not-exist')->shouldBeCalledTimes(1);
     // First, only set the path context.
     $this->condition->setContextValue('alias', 'alias-for-path-that-does-not-exist');
     // Test without language context set.
     $this->assertFalse($this->condition->evaluate());
     // Test with language context set.
     $this->condition->setContextValue('language', $this->englishLanguage->reveal());
     $this->assertFalse($this->condition->evaluate());
 }
예제 #8
0
 /**
  * Tests evaluating the condition for path without an alias.
  *
  * @covers ::evaluate
  */
 public function testConditionEvaluationPathWithoutAlias()
 {
     $this->aliasManager->getAliasByPath('path-without-alias', NULL)->willReturn('path-without-alias')->shouldBeCalledTimes(1);
     $this->aliasManager->getAliasByPath('path-without-alias', 'en')->willReturn('path-without-alias')->shouldBeCalledTimes(1);
     // First, only set the path context.
     $this->condition->setContextValue('path', 'path-without-alias');
     // Test without language context set.
     $this->assertFalse($this->condition->evaluate());
     // Test with language context set.
     $this->condition->setContextValue('language', $this->englishLanguage->reveal());
     $this->assertFalse($this->condition->evaluate());
 }
 /**
  * Checks access to the overview based on permissions and translatability.
  *
  * @param \Symfony\Component\Routing\Route $route
  *   The route to check against.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(Route $route, AccountInterface $account)
 {
     /** @var \Drupal\config_translation\ConfigMapperInterface $mapper */
     $mapper = $this->configMapperManager->createInstance($route->getDefault('plugin_id'));
     $this->sourceLanguage = $this->languageManager->getLanguage($mapper->getLangcode());
     // Allow access to the translation overview if the proper permission is
     // granted, the configuration has translatable pieces, and the source
     // language is not locked if it is present.
     $source_language_access = is_null($this->sourceLanguage) || !$this->sourceLanguage->isLocked();
     $access = $account->hasPermission('translate configuration') && $mapper->hasSchema() && $mapper->hasTranslatable() && $source_language_access;
     return AccessResult::allowedIf($access)->cachePerRole();
 }
예제 #10
0
 /**
  * {@inheritdoc}
  */
 public function persist(LanguageInterface $language)
 {
     // We need to update the session parameter with the request value only if we
     // have an authenticated user.
     $langcode = $language->getId();
     if ($langcode && $this->languageManager) {
         $languages = $this->languageManager->getLanguages();
         if ($this->currentUser->isAuthenticated() && isset($languages[$langcode])) {
             $config = $this->config->get('language.negotiation')->get('session');
             $_SESSION[$config['parameter']] = $langcode;
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Remove the translated values.
     $this->entity = $this->entity->getUntranslated();
     $this->entity->removeTranslation($this->language->getId());
     $this->entity->save();
     // Remove any existing path alias for the removed translation.
     // @todo This should be taken care of by the Path module.
     if (\Drupal::moduleHandler()->moduleExists('path')) {
         $path = $this->entity->getSystemPath();
         $conditions = array('source' => $path, 'langcode' => $this->language->getId());
         \Drupal::service('path.alias_storage')->delete($conditions);
     }
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
 /**
  * Check URL rewriting for the given language.
  *
  * The test is performed with a fixed URL (the default front page) to simply
  * check that language prefixes are not added to it and that the prefixed URL
  * is actually not working.
  *
  * @param \Drupal\Core\Language\LanguageInterface $language
  *   The language object.
  * @param string $message1
  *   Message to display in assertion that language prefixes are not added.
  * @param string $message2
  *   The message to display confirming prefixed URL is not working.
  */
 private function checkUrl(LanguageInterface $language, $message1, $message2)
 {
     $options = array('language' => $language, 'script' => '');
     $base_path = trim(base_path(), '/');
     $rewritten_path = trim(str_replace($base_path, '', \Drupal::url('<front>', array(), $options)), '/');
     $segments = explode('/', $rewritten_path, 2);
     $prefix = $segments[0];
     $path = isset($segments[1]) ? $segments[1] : $prefix;
     // If the rewritten URL has not a language prefix we pick a random prefix so
     // we can always check the prefixed URL.
     $prefixes = language_negotiation_url_prefixes();
     $stored_prefix = isset($prefixes[$language->getId()]) ? $prefixes[$language->getId()] : $this->randomMachineName();
     if ($this->assertNotEqual($stored_prefix, $prefix, $message1)) {
         $prefix = $stored_prefix;
     }
     $this->drupalGet("{$prefix}/{$path}");
     $this->assertResponse(404, $message2);
 }
예제 #13
0
 /**
  * @covers ::getInfo
  */
 public function testGetInfo()
 {
     $token_info = array('types' => array('foo' => array('name' => $this->randomMachineName())));
     $this->language->expects($this->atLeastOnce())->method('getId')->will($this->returnValue($this->randomMachineName()));
     $this->languageManager->expects($this->once())->method('getCurrentLanguage')->with(LanguageInterface::TYPE_CONTENT)->will($this->returnValue($this->language));
     // The persistent cache must only be hit once, after which the info is
     // cached statically.
     $this->cache->expects($this->once())->method('get');
     $this->cache->expects($this->once())->method('set')->with('token_info:' . $this->language->getId(), $token_info);
     $this->moduleHandler->expects($this->once())->method('invokeAll')->with('token_info')->will($this->returnValue($token_info));
     $this->moduleHandler->expects($this->once())->method('alter')->with('token_info', $token_info);
     // Get the information for the first time. The cache should be checked, the
     // hooks invoked, and the info should be set to the cache should.
     $this->token->getInfo();
     // Get the information for the second time. The data must be returned from
     // the static cache, so the persistent cache must not be accessed and the
     // hooks must not be invoked.
     $this->token->getInfo();
 }
 /**
  * Formats configuration schema as a form tree.
  *
  * @param \Drupal\Core\Config\Schema\Element $schema
  *   Schema definition of configuration.
  * @param array|string $config_data
  *   Configuration object of requested language, a string when done traversing
  *   the data building each sub-structure for the form.
  * @param array|string $base_config_data
  *   Configuration object of base language, a string when done traversing
  *   the data building each sub-structure for the form.
  * @param bool $open
  *   (optional) Whether or not the details element of the form should be open.
  *   Defaults to TRUE.
  * @param string|null $base_key
  *   (optional) Base configuration key. Defaults to an empty string.
  *
  * @return array
  *   An associative array containing the structure of the form.
  */
 protected function buildConfigForm(Element $schema, $config_data, $base_config_data, $open = TRUE, $base_key = '')
 {
     $build = array();
     foreach ($schema as $key => $element) {
         // Make the specific element key, "$base_key.$key".
         $element_key = implode('.', array_filter(array($base_key, $key)));
         $definition = $element->getDataDefinition();
         if (!$definition->getLabel()) {
             $definition->setLabel($this->t('N/A'));
         }
         if ($element instanceof Element) {
             // Build sub-structure and include it with a wrapper in the form
             // if there are any translatable elements there.
             $sub_build = $this->buildConfigForm($element, $config_data[$key], $base_config_data[$key], FALSE, $element_key);
             if (!empty($sub_build)) {
                 // For some configuration elements the same element structure can
                 // repeat multiple times, (like views displays, filters, etc.).
                 // So try to find a more usable title for the details summary. First
                 // check if there is an element which is called title or label, then
                 // check if there is an element which contains these words.
                 $title = '';
                 if (isset($sub_build['title']['source'])) {
                     $title = $sub_build['title']['source']['#markup'];
                 } elseif (isset($sub_build['label']['source'])) {
                     $title = $sub_build['label']['source']['#markup'];
                 } else {
                     foreach (array_keys($sub_build) as $title_key) {
                         if (isset($sub_build[$title_key]['source']) && (strpos($title_key, 'title') !== FALSE || strpos($title_key, 'label') !== FALSE)) {
                             $title = $sub_build[$title_key]['source']['#markup'];
                             break;
                         }
                     }
                 }
                 $build[$key] = array('#type' => 'details', '#title' => (!empty($title) ? strip_tags($title) . ' ' : '') . $this->t($definition['label']), '#open' => $open) + $sub_build;
             }
         } else {
             $definition = $element->getDataDefinition();
             // Create form element only for translatable items.
             if (!isset($definition['translatable']) || !isset($definition['type'])) {
                 continue;
             }
             $value = $config_data[$key];
             $build[$element_key] = array('#theme' => 'config_translation_manage_form_element');
             $build[$element_key]['source'] = array('#markup' => $base_config_data[$key] ? '<span lang="' . $this->sourceLanguage->getId() . '">' . nl2br($base_config_data[$key] . '</span>') : t('(Empty)'), '#title' => $this->t('!label <span class="visually-hidden">(!source_language)</span>', array('!label' => $this->t($definition['label']), '!source_language' => $this->sourceLanguage->name)), '#type' => 'item');
             if (!isset($definition['form_element_class'])) {
                 $definition['form_element_class'] = '\\Drupal\\config_translation\\FormElement\\Textfield';
             }
             /** @var \Drupal\config_translation\FormElement\ElementInterface $form_element */
             $form_element = new $definition['form_element_class']();
             $build[$element_key]['translation'] = $form_element->getFormElement($definition, $this->language, $value);
         }
     }
     return $build;
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     foreach ($this->mapper->getConfigNames() as $name) {
         $this->languageManager->getLanguageConfigOverride($this->language->getId(), $name)->delete();
     }
     // Flush all persistent caches.
     $this->moduleHandler->invokeAll('cache_flush');
     foreach (Cache::getBins() as $service_id => $cache_backend) {
         $cache_backend->deleteAll();
     }
     drupal_set_message($this->t('@language translation of %label was deleted', array('%label' => $this->mapper->getTitle(), '@language' => $this->language->name)));
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $form_values = $form_state->getValue(array('translation', 'config_names'));
     foreach ($this->mapper->getConfigNames() as $name) {
         $schema = $this->typedConfigManager->get($name);
         // Set configuration values based on form submission and source values.
         $base_config = $this->configFactory()->getEditable($name);
         $config_translation = $this->languageManager->getLanguageConfigOverride($this->language->getId(), $name);
         $element = $this->createFormElement($schema);
         $element->setConfig($base_config, $config_translation, $form_values[$name]);
         // If no overrides, delete language specific configuration file.
         $saved_config = $config_translation->get();
         if (empty($saved_config)) {
             $config_translation->delete();
         } else {
             $config_translation->save();
         }
     }
     $form_state->setRedirect($this->mapper->getOverviewRoute(), $this->mapper->getOverviewRouteParameters());
 }
예제 #17
0
 /**
  * Returns the translation form element for a given configuration definition.
  *
  * For complex data structures (such as mappings) that are translatable
  * wholesale but contain non-translatable properties, the form element is
  * responsible for checking access to the source value of those properties. In
  * case of formatted text, for example, access to the source text format must
  * be checked. If the translator does not have access to the text format, the
  * textarea must be disabled and the translator may not be able to translate
  * this particular configuration element. If the translator does have access
  * to the text format, the element must be locked down to that particular text
  * format; in other words, the format may not be changed by the translator
  * (because the text format property is not itself translatable).
  *
  * In addition, the form element is responsible for checking whether the
  * value of such non-translatable properties in the translated configuration
  * is equal to the corresponding source values. If not, that means that the
  * source value has changed after the translation was added. In this case -
  * again - the translation of this element must be disabled if the translator
  * does not have access to the source value of the non-translatable property.
  * For example, if a formatted text element, whose source format was plain
  * text when it was first translated, gets changed to the Full HTML format,
  * simply changing the format of the translation would lead to an XSS
  * vulnerability as the translated text, that was intended to be escaped,
  * would now be displayed unescaped. Thus, if the translator does not have
  * access to the Full HTML format, the translation for this particular element
  * may not be updated at all (the textarea must be disabled). Only if access
  * to the Full HTML format is granted, an explicit translation taking into
  * account the updated source value(s) may be submitted.
  *
  * In the specific case of formatted text this logic is implemented by
  * utilizing a form element of type 'text_format' and its #format and
  * #allowed_formats properties. The access logic explained above is then
  * handled by the 'text_format' element itself, specifically by
  * filter_process_format(). In case such a rich element is not available for
  * translation of complex data, similar access logic must be implemented
  * manually.
  *
  * @param \Drupal\Core\Language\LanguageInterface $translation_language
  *   The language to display the translation form for.
  * @param mixed $source_config
  *   The configuration value of the element in the source language.
  * @param mixed $translation_config
  *   The configuration value of the element in the language to translate to.
  *
  * @return array
  *   Form API array to represent the form element.
  *
  * @see \Drupal\config_translation\FormElement\TextFormat
  * @see filter_process_format()
  */
 protected function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config)
 {
     // Add basic properties that apply to all form elements.
     // @todo Should support singular+plurals https://www.drupal.org/node/2454829
     return array('#title' => $this->t('!label <span class="visually-hidden">(!source_language)</span>', array('!label' => $this->t($this->definition['label']), '!source_language' => $translation_language->getName())), '#default_value' => $translation_config, '#attributes' => array('lang' => $translation_language->getId()));
 }
예제 #18
0
 /**
  * {@inheritdoc}
  */
 public function hasTranslation(LanguageInterface $language)
 {
     foreach ($this->getConfigNames() as $name) {
         if ($this->localeConfigManager->hasTranslation($name, $language->getId())) {
             return TRUE;
         }
     }
     return FALSE;
 }
예제 #19
0
 /**
  * Send a system email.
  *
  * @param string[] $to
  *   Email addresses of the recipients.
  * @param string $subject
  *   Subject of the email.
  * @param string $message
  *   Email message text.
  * @param string|null $reply
  *   (optional) Reply to email address.
  * @param \Drupal\Core\Language\LanguageInterface|null $language
  *   (optional) Language code.
  */
 protected function doExecute($to, $subject, $message, $reply = NULL, LanguageInterface $language = NULL)
 {
     $langcode = isset($language) ? $language->getId() : LanguageInterface::LANGCODE_SITE_DEFAULT;
     $params = ['subject' => $subject, 'message' => $message];
     // Set a unique key for this mail.
     $key = 'rules_action_mail_' . $this->getPluginId();
     $recipients = implode(', ', $to);
     $message = $this->mailManager->mail('rules', $key, $recipients, $langcode, $params, $reply);
     if ($message['result']) {
         $this->logger->notice('Successfully sent email to %recipient', ['%recipient' => $recipients]);
     }
 }
예제 #20
0
 /**
  * Returns the translation form element for a given configuration definition.
  *
  * For complex data structures (such as mappings) that are translatable
  * wholesale but contain non-translatable properties, the form element is
  * responsible for checking access to the source value of those properties. In
  * case of formatted text, for example, access to the source text format must
  * be checked. If the translator does not have access to the text format, the
  * textarea must be disabled and the translator may not be able to translate
  * this particular configuration element. If the translator does have access
  * to the text format, the element must be locked down to that particular text
  * format; in other words, the format may not be changed by the translator
  * (because the text format property is not itself translatable).
  *
  * In addition, the form element is responsible for checking whether the
  * value of such non-translatable properties in the translated configuration
  * is equal to the corresponding source values. If not, that means that the
  * source value has changed after the translation was added. In this case -
  * again - the translation of this element must be disabled if the translator
  * does not have access to the source value of the non-translatable property.
  * For example, if a formatted text element, whose source format was plain
  * text when it was first translated, gets changed to the Full HTML format,
  * simply changing the format of the translation would lead to an XSS
  * vulnerability as the translated text, that was intended to be escaped,
  * would now be displayed unescaped. Thus, if the translator does not have
  * access to the Full HTML format, the translation for this particular element
  * may not be updated at all (the textarea must be disabled). Only if access
  * to the Full HTML format is granted, an explicit translation taking into
  * account the updated source value(s) may be submitted.
  *
  * In the specific case of formatted text this logic is implemented by
  * utilizing a form element of type 'text_format' and its #format and
  * #allowed_formats properties. The access logic explained above is then
  * handled by the 'text_format' element itself, specifically by
  * filter_process_format(). In case such a rich element is not available for
  * translation of complex data, similar access logic must be implemented
  * manually.
  *
  * @param \Drupal\Core\Language\LanguageInterface $translation_language
  *   The language to display the translation form for.
  * @param mixed $source_config
  *   The configuration value of the element in the source language.
  * @param mixed $translation_config
  *   The configuration value of the element in the language to translate to.
  *
  * @return array
  *   Form API array to represent the form element.
  *
  * @see \Drupal\config_translation\FormElement\TextFormat
  * @see filter_process_format()
  */
 protected function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config)
 {
     // Add basic properties that apply to all form elements.
     return array('#title' => $this->t('@label <span class="visually-hidden">(@source_language)</span>', array('@label' => $this->definition['label'], '@source_language' => $translation_language->getName())), '#default_value' => $translation_config, '#attributes' => array('lang' => $translation_language->getId()));
 }
예제 #21
0
 /**
  * Checks whether a language has configuration translation.
  *
  * @param string $name
  *   Configuration name.
  * @param \Drupal\Core\Language\LanguageInterface $language
  *   A language object.
  *
  * @return bool
  *   A boolean indicating if a language has configuration translations.
  */
 public function hasTranslation($name, LanguageInterface $language)
 {
     $translation = $this->languageManager->getLanguageConfigOverride($language->getId(), $name);
     return !$translation->isNew();
 }
 /**
  * Checks access given an account, configuration mapper, and source language.
  *
  * In addition to the checks performed by
  * ConfigTranslationOverviewAccess::doCheckAccess() this makes sure the target
  * language is not locked and the target language is not the source language.
  *
  * Although technically configuration can be overlaid with translations in the
  * same language, that is logically not a good idea.
  *
  * @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.
  * @param \Drupal\Core\Language\LanguageInterface|null $target_language
  *   The target language to check for, if any.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The result of the access check.
  *
  * @see \Drupal\config_translation\Access\ConfigTranslationOverviewAccess::doCheckAccess()
  */
 protected function doCheckAccess(AccountInterface $account, ConfigMapperInterface $mapper, $source_language = NULL, $target_language = NULL)
 {
     $base_access_result = parent::doCheckAccess($account, $mapper, $source_language);
     $access = $target_language && !$target_language->isLocked() && (!$source_language || $target_language->getId() !== $source_language->getId());
     return $base_access_result->andIf(AccessResult::allowedIf($access));
 }
예제 #23
0
 private function save_sitemap()
 {
     $this->db->upsert('custom_sitemap')->key(array('language_code', $this->language->getId()))->fields(array('language_code' => $this->language->getId(), 'sitemap_string' => $this->sitemap))->execute();
 }
예제 #24
0
 /**
  * {@inheritdoc}
  */
 public function getFormElement(DataDefinitionInterface $definition, LanguageInterface $language, $value)
 {
     $description = $this->t('A user-defined date format. See the <a href="@url">PHP manual</a> for available options.', array('@url' => 'http://php.net/manual/function.date.php'));
     $format = $this->t('Displayed as %date_format', array('%date_format' => \Drupal::service('date.formatter')->format(REQUEST_TIME, 'custom', $value)));
     return array('#type' => 'textfield', '#title' => $this->t($definition->getLabel()) . '<span class="visually-hidden"> (' . $language->name . ')</span>', '#description' => $description, '#default_value' => $value, '#attributes' => array('lang' => $language->getId()), '#field_suffix' => ' <div class="edit-date-format-suffix"><small id="edit-date-format-suffix">' . $format . '</small></div>', '#ajax' => array('callback' => 'Drupal\\config_translation\\FormElement\\DateFormat::ajaxSample', 'event' => 'keyup', 'progress' => array('type' => 'throbber', 'message' => NULL)));
 }
 /**
  * Builds the edit translation page.
  *
  * @param \Drupal\Core\Language\LanguageInterface $language
  *   The language of the translated values. Defaults to the current content
  *   language.
  * @param \Drupal\Core\Routing\RouteMatchInterface
  *   The route match object from which to extract the entity type.
  * @param string $entity_type_id
  *   (optional) The entity type ID.
  *
  * @return array
  *   A processed form array ready to be rendered.
  */
 public function edit(LanguageInterface $language, RouteMatchInterface $route_match, $entity_type_id = NULL)
 {
     /*
      * @Previent user to direct access the url that languages are not valid for user
      * @return  to front page
      */
     $tagget_language = $language->getId();
     $user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
     foreach ($user->get('field_language') as $lang) {
         $access_lang[] = $lang->value;
     }
     foreach ($user->get('roles') as $roles) {
         $current_user_roles[] = $roles->target_id;
     }
     $isaplied = 0;
     $nolang = 0;
     if (in_array('translator', $current_user_roles) && !in_array('administrator', $current_user_roles)) {
         $isaplied = 1;
     }
     if (!in_array($tagget_language, $access_lang)) {
         $nolang = 1;
     }
     if ($isaplied == 1 && $nolang == 1) {
         drupal_set_message(t('You are not authorized to access this page.'), 'error');
         //return $this->redirect('entity.node.content_translation_overview');
         return $this->redirect('<front>');
     }
     /*
      * end here
      */
     $entity = $route_match->getParameter($entity_type_id);
     // @todo Provide a way to figure out the default form operation. Maybe like
     //   $operation = isset($info['default_operation']) ? $info['default_operation'] : 'default';
     //   See https://www.drupal.org/node/2006348.
     $operation = 'default';
     $form_state_additions = array();
     $form_state_additions['langcode'] = $language->getId();
     $form_state_additions['content_translation']['translation_form'] = TRUE;
     return $this->entityFormBuilder()->getForm($entity, $operation, $form_state_additions);
 }
예제 #26
0
 /**
  * Get a form key.
  *
  * @param string $key
  *   The key.
  * @param LanguageInterface $language
  *   The optional language.
  *
  * @return string
  *   The form key.
  */
 private function getKey($key, LanguageInterface $language = NULL)
 {
     return 'itk_cookie_message' . ($language ? '_' . $language->getId() : '') . '_' . $key;
 }
 /**
  * {@inheritdoc}
  */
 public function getCacheSuffix()
 {
     return $this->language ? $this->language->getId() : NULL;
 }
 /**
  * Builds the edit translation page.
  *
  * @param \Drupal\Core\Language\LanguageInterface $language
  *   The language of the translated values. Defaults to the current content
  *   language.
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The route match object from which to extract the entity type.
  * @param string $entity_type_id
  *   (optional) The entity type ID.
  *
  * @return array
  *   A processed form array ready to be rendered.
  */
 public function edit(LanguageInterface $language, RouteMatchInterface $route_match, $entity_type_id = NULL)
 {
     $entity = $route_match->getParameter($entity_type_id);
     // @todo Provide a way to figure out the default form operation. Maybe like
     //   $operation = isset($info['default_operation']) ? $info['default_operation'] : 'default';
     //   See https://www.drupal.org/node/2006348.
     $operation = 'default';
     $form_state_additions = array();
     $form_state_additions['langcode'] = $language->getId();
     $form_state_additions['content_translation']['translation_form'] = TRUE;
     return $this->entityFormBuilder()->getForm($entity, $operation, $form_state_additions);
 }
예제 #29
0
 /**
  * {@inheritdoc}
  */
 public function clearRevisionsLanguage(LanguageInterface $language)
 {
     return $this->database->update('node_revision')->fields(array('langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED))->condition('langcode', $language->getId())->execute();
 }
예제 #30
0
 /**
  * {@inheritdoc}
  */
 public function getFormElement(DataDefinitionInterface $definition, LanguageInterface $language, $value)
 {
     return array('#type' => 'textfield', '#default_value' => $value, '#title' => $this->t($definition->getLabel()) . '<span class="visually-hidden"> (' . $language->getName() . ')</span>', '#attributes' => array('lang' => $language->getId()));
 }