/**
  * Renders a list with all custom links.
  *
  * @return array
  *   The list to be rendered.
  */
 public function render()
 {
     $build['xmlsitemap_add_custom'] = array('#type' => 'link', '#title' => t('Add custom link'), '#href' => 'admin/config/search/xmlsitemap/custom/add');
     $header = array('loc' => array('data' => t('Location'), 'field' => 'loc', 'sort' => 'asc'), 'priority' => array('data' => t('Priority'), 'field' => 'priority'), 'changefreq' => array('data' => t('Change frequency'), 'field' => 'changefreq'), 'language' => array('data' => t('Language'), 'field' => 'language'), 'operations' => array('data' => t('Operations')));
     $rows = array();
     $destination = drupal_get_destination();
     $query = db_select('xmlsitemap');
     $query->fields('xmlsitemap');
     $query->condition('type', 'custom');
     $query->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')->limit(50);
     $query->extend('Drupal\\Core\\Database\\Query\\TableSortExtender')->orderByHeader($header);
     $result = $query->execute();
     foreach ($result as $link) {
         $language = $this->languageManager->getLanguage($link->language);
         $row = array();
         $row['loc'] = $this->l($link->loc, Url::fromUri($link->loc));
         $row['priority'] = number_format($link->priority, 1);
         $row['changefreq'] = $link->changefreq ? drupal_ucfirst(xmlsitemap_get_changefreq($link->changefreq)) : t('None');
         if (isset($header['language'])) {
             $row['language'] = t($language->name);
         }
         $operations['edit'] = array('title' => t('Edit'), 'route_name' => 'xmlsitemap_custom.edit', 'route_parameters' => array('link' => $link->id));
         $operations['delete'] = array('title' => t('Delete'), 'route_name' => 'xmlsitemap_custom.delete', 'route_parameters' => array('link' => $link->id));
         $row['operations'] = array('data' => array('#type' => 'operations', '#theme' => 'links', '#links' => $operations, '#attributes' => array('class' => array('links', 'inline'))));
         $rows[] = $row;
     }
     // @todo Convert to tableselect
     $build['xmlsitemap_custom_table'] = array('#type' => 'tableselect', '#theme' => 'table', '#header' => $header, '#rows' => $rows, '#empty' => $this->t('No custom links available. <a href="@custom_link">Add custom link</a>', array('@custom_link' => Url::fromRoute('xmlsitemap_custom.add', [], array('query' => $destination)))));
     $build['xmlsitemap_custom_pager'] = array('#theme' => 'pager');
     return $build;
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $row['label'] = $this->getLabel($entity);
     if ($this->moduleHandler->moduleExists('language')) {
         if (isset($entity->context['language'])) {
             $language = $this->languageManager->getLanguage($entity->context['language']);
             $row['language'] = $language->getName();
         } else {
             $row['language'] = $this->t('Undefined');
         }
     }
     $row['id'] = $entity->id();
     // You probably want a few more properties here...
     return $row + parent::buildRow($entity);
 }
 /**
  * {@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);
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Add language, if not yet supported.
     $language = $this->languageManager->getLanguage($form_state->getValue('langcode'));
     if (empty($language)) {
         $language = ConfigurableLanguage::createFromLangcode($form_state->getValue('langcode'));
         $language->save();
         drupal_set_message($this->t('The language %language has been created.', array('%language' => $this->t($language->label()))));
     }
     $options = array('langcode' => $form_state->getValue('langcode'), 'overwrite_options' => $form_state->getValue('overwrite_options'), 'customized' => $form_state->getValue('customized') ? LOCALE_CUSTOMIZED : LOCALE_NOT_CUSTOMIZED);
     $this->moduleHandler->loadInclude('locale', 'bulk.inc');
     $file = locale_translate_file_attach_properties($this->file, $options);
     $batch = locale_translate_batch_build(array($file->uri => $file), $options);
     batch_set($batch);
     $form_state->setRedirect('locale.translate_page');
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, array &$form_state)
 {
     // Add language, if not yet supported.
     $language = $this->languageManager->getLanguage($form_state['values']['langcode']);
     if (empty($language)) {
         $language = new Language(array('id' => $form_state['values']['langcode']));
         $language = language_save($language);
         drupal_set_message($this->t('The language %language has been created.', array('%language' => $this->t($language->name))));
     }
     $options = array('langcode' => $form_state['values']['langcode'], 'overwrite_options' => $form_state['values']['overwrite_options'], 'customized' => $form_state['values']['customized'] ? LOCALE_CUSTOMIZED : LOCALE_NOT_CUSTOMIZED);
     $this->moduleHandler->loadInclude('locale', 'bulk.inc');
     $file = locale_translate_file_attach_properties($this->file, $options);
     $batch = locale_translate_batch_build(array($file->uri => $file), $options);
     batch_set($batch);
     $form_state['redirect_route']['route_name'] = 'locale.translate_page';
 }
 /**
  * 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 \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   (optional) The route match.
  * @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, 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.
     $langcode = $this->mapper->getLangcode();
     $this->sourceLanguage = $this->languageManager->getLanguage($langcode);
     // 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.
     $this->baseConfigData = $this->mapper->getConfigData();
     // 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->set('config_translation_mapper', $this->mapper);
     $form_state->set('config_translation_language', $this->language);
     $form_state->set('config_translation_source_language', $this->sourceLanguage);
     $form['#attached']['library'][] = 'config_translation/drupal.config_translation.admin';
     // Even though this is a nested form, we do not set #tree to TRUE because
     // the form value structure is generated by using #parents for each element.
     // @see \Drupal\config_translation\FormElement\FormElementBase::getElements()
     $form['config_names'] = array('#type' => 'container');
     foreach ($this->mapper->getConfigNames() as $name) {
         $form['config_names'][$name] = array('#type' => 'container');
         $schema = $this->typedConfigManager->get($name);
         $source_config = $this->baseConfigData[$name];
         $translation_config = $this->configFactory()->get($name)->get();
         if ($form_element = $this->createFormElement($schema)) {
             $parents = array('config_names', $name);
             $form['config_names'][$name] += $form_element->getTranslationBuild($this->sourceLanguage, $this->language, $source_config, $translation_config, $parents);
         }
     }
     $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;
 }