Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, array &$form_state)
 {
     foreach ($this->mapper->getConfigNames() as $name) {
         $this->languageManager->getLanguageConfigOverride($this->language->id, $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['redirect_route'] = $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());
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, array &$form_state)
 {
     $form_values = $form_state['values']['config_names'];
     // For the form submission handling, use the raw data.
     $config_factory = $this->configFactory();
     $old_state = $config_factory->getOverrideState();
     $config_factory->setOverrideState(FALSE);
     foreach ($this->mapper->getConfigNames() as $name) {
         // Set configuration values based on form submission and source values.
         $base_config = $config_factory->get($name);
         $config_translation = $this->languageManager->getLanguageConfigOverride($this->language->id, $name);
         $locations = $this->localeStorage->getLocations(array('type' => 'configuration', 'name' => $name));
         $this->setConfig($this->language, $base_config, $config_translation, $form_values[$name], !empty($locations));
         // If no overrides, delete language specific configuration file.
         $saved_config = $config_translation->get();
         if (empty($saved_config)) {
             $config_translation->delete();
         } else {
             $config_translation->save();
         }
     }
     $config_factory->setOverrideState($old_state);
     $form_state['redirect_route'] = array('route_name' => $this->mapper->getOverviewRoute(), 'route_parameters' => $this->mapper->getOverviewRouteParameters());
 }
 /**
  * Builds a renderable list of operation links for the entity.
  *
  * @param \Drupal\config_translation\ConfigMapperInterface $mapper
  *   The mapper.
  *
  * @return array
  *   A renderable array of operation links.
  *
  * @see \Drupal\Core\Entity\EntityList::buildOperations()
  */
 protected function buildOperations(ConfigMapperInterface $mapper)
 {
     // Retrieve and sort operations.
     $operations = $mapper->getOperations();
     uasort($operations, 'Drupal\\Component\\Utility\\SortArray::sortByWeightElement');
     $build = array('#type' => 'operations', '#links' => $operations);
     return $build;
 }
 /**
  * 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.
  */
 protected function doCheckAccess(AccountInterface $account, ConfigMapperInterface $mapper, $source_language = NULL)
 {
     $access = $account->hasPermission('translate configuration') && $mapper->hasSchema() && $mapper->hasTranslatable() && (!$source_language || !$source_language->isLocked());
     return AccessResult::allowedIf($access)->cachePerPermissions();
 }