Skip to content
Snippets Groups Projects
Commit be8a77d8 authored by catch's avatar catch
Browse files

Issue #3360445 by Lendude, sboden, smustgrave, quietone: Duplicating a view...

Issue #3360445 by Lendude, sboden, smustgrave, quietone: Duplicating a view does not duplicate the translation
parent cbe1d286
No related branches found
No related tags found
27 merge requests!12227Issue #3181946 by jonmcl, mglaman,!8528Issue #3456871 by Tim Bozeman: Support NULL services,!3878Removed unused condition head title for views,!38582585169-10.1.x,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3668Resolve #3347842 "Deprecate the trusted",!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3478Issue #3337882: Deleted menus are not removed from content type config,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #82690 passed with warnings
Pipeline: drupal

#82701

    Pipeline: drupal

    #82698

      Pipeline: drupal

      #82695

        +1
        ......@@ -2,7 +2,10 @@
        namespace Drupal\views_ui;
        use Drupal\Core\Extension\ModuleHandlerInterface;
        use Drupal\Core\Form\FormStateInterface;
        use Drupal\Core\Language\LanguageManagerInterface;
        use Symfony\Component\DependencyInjection\ContainerInterface;
        /**
        * Form controller for the Views duplicate form.
        ......@@ -11,6 +14,36 @@
        */
        class ViewDuplicateForm extends ViewFormBase {
        /**
        * The language manager.
        *
        * @var \Drupal\Core\Language\LanguageManagerInterface
        */
        protected LanguageManagerInterface $languageManager;
        /**
        * {@inheritdoc}
        */
        public static function create(ContainerInterface $container) {
        return new static(
        $container->get('module_handler'),
        $container->get('language_manager')
        );
        }
        /**
        * Constructs a ViewDuplicateForm.
        *
        * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
        * Drupal's module handler.
        * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
        * The language manager.
        */
        public function __construct(ModuleHandlerInterface $moduleHandler, LanguageManagerInterface $language_manager) {
        $this->setModuleHandler($moduleHandler);
        $this->languageManager = $language_manager;
        }
        /**
        * {@inheritdoc}
        */
        ......@@ -68,13 +101,46 @@ protected function actions(array $form, FormStateInterface $form_state) {
        * A reference to a keyed array containing the current state of the form.
        */
        public function submitForm(array &$form, FormStateInterface $form_state) {
        // The original ID gets set to NULL when duplicating, so we need to store it
        // here.
        $original_id = $this->entity->id();
        $this->entity = $this->entity->createDuplicate();
        $this->entity->set('label', $form_state->getValue('label'));
        $this->entity->set('id', $form_state->getValue('id'));
        $this->entity->save();
        $this->copyTranslations($original_id);
        // Redirect the user to the view admin form.
        $form_state->setRedirectUrl($this->entity->toUrl('edit-form'));
        }
        /**
        * Copies all translations that existed on the original View.
        *
        * @param string $original_id
        * The original View ID.
        */
        private function copyTranslations(string $original_id): void {
        if (!$this->moduleHandler->moduleExists('config_translation')) {
        return;
        }
        $current_langcode = $this->languageManager->getConfigOverrideLanguage()
        ->getId();
        $languages = $this->languageManager->getLanguages();
        $original_name = 'views.view.' . $original_id;
        $duplicate_name = 'views.view.' . $this->entity->id();
        foreach ($languages as $language) {
        $langcode = $language->getId();
        if ($langcode !== $current_langcode) {
        $original_translation = $this->languageManager->getLanguageConfigOverride($langcode, $original_name)
        ->get();
        if ($original_translation) {
        $duplicate_translation = $this->languageManager->getLanguageConfigOverride($langcode, $duplicate_name);
        $duplicate_translation->setData($original_translation);
        $duplicate_translation->save();
        }
        }
        }
        }
        }
        ......@@ -2,6 +2,8 @@
        namespace Drupal\Tests\views_ui\Functional;
        use Drupal\language\Entity\ConfigurableLanguage;
        /**
        * Tests the UI for view duplicate tool.
        *
        ......@@ -9,6 +11,11 @@
        */
        class DuplicateTest extends UITestBase {
        /**
        * {@inheritdoc}
        */
        protected static $modules = ['config_translation', 'locale', 'language'];
        /**
        * {@inheritdoc}
        */
        ......@@ -27,10 +34,17 @@ protected function setUp($import_test_views = TRUE, $modules = ['views_test_conf
        * Checks if duplicated view exists and has correct label.
        */
        public function testDuplicateView() {
        $language_manager = $this->container->get('language_manager');
        ConfigurableLanguage::createFromLangcode('nl')->save();
        // Create random view.
        $random_view = $this->randomView();
        // Add a translation to the View.
        $translation = $language_manager->getLanguageConfigOverride('nl', 'views.view.' . $random_view['id']);
        $translation->setData(['label' => 'NL label']);
        $translation->save();
        // Initialize array for duplicated view.
        $view = [];
        ......@@ -47,6 +61,9 @@ public function testDuplicateView() {
        // Assert that the page title is correctly displayed.
        $this->assertSession()->pageTextContains($view['label']);
        $copy_translation = $language_manager->getLanguageConfigOverride('nl', 'views.view.' . $view['id']);
        $this->assertEquals(['label' => 'NL label'], $copy_translation->get());
        }
        }
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please register or to comment