Skip to content
Snippets Groups Projects
Verified Commit 91acedad authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2904899 by FeyP, idflood, smustgrave, alexpott: Invalid argument...

Issue #2904899 by FeyP, idflood, smustgrave, alexpott: Invalid argument exception when changing language of node with menu link to und or zxx

(cherry picked from commit ff109038)
parent f807ceda
No related branches found
No related tags found
20 merge requests!8376Drupal views: adding more granularity to the ‘use ajax’ functionality,!8300Issue #3443586 View area displays even when parent view has no results.,!7567Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7565Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7509Change label "Block description" to "Block type",!7344Issue #3292350 by O'Briat, KlemenDEV, hswong3i, smustgrave, quietone: Update...,!6922Issue #3412959 by quietone, smustgrave, longwave: Fix 12 'un' words,!6848Issue #3417553 by longwave: Remove withConsecutive() in CacheCollectorTest,!6720Revert "Issue #3358581 by pfrenssen, _tarik_, a.dmitriiev, smustgrave:...,!6560Update ClaroPreRender.php, confirming classes provided are in array format,!6528Issue #3414261 by catch: Add authenticated user umami performance tests,!6501Issue #3263668 by omkar-pd, Wim Leers, hooroomoo: Re-enable inline form errors...,!6354Draft: Issue #3380392 by phma: Updating language weight from the overview reverts label if translated,!6324Issue #3416723 by Ludo.R: Provide a "node type" views default argument,!6119Issue #3405704 by Spokje, longwave: symfony/psr-http-message-bridge major version bump,!5950Issue #3403653 by alexpott, longwave: Incorporate improvements to how contrib runs PHPStan to core,!5858Issue #3401971 by fjgarlin: Test-only job shouldn't require constant rebases...,!5716Draft: Issue #3401102 by Spokje, longwave, smustgrave: Nightwatch artifacts on GitLab not retained,!5674Transaction autocommit during shutdown relies on unreliable object destruction order,!5644Issue #3395563 by nireneko, marvil07, lauriii, borisson_, smustgrave, Wim...
Pipeline #50508 failed
Pipeline: drupal

#50518

    Pipeline: drupal

    #50517

      Pipeline: drupal

      #50516

        +1
        ......@@ -93,7 +93,7 @@ function _menu_ui_node_save(NodeInterface $node, array $values) {
        /** @var \Drupal\menu_link_content\MenuLinkContentInterface $entity */
        if (!empty($values['entity_id'])) {
        $entity = MenuLinkContent::load($values['entity_id']);
        if ($entity->isTranslatable()) {
        if ($entity->isTranslatable() && $node->isTranslatable()) {
        if (!$entity->hasTranslation($node->language()->getId())) {
        $entity = $entity->addTranslation($node->language()->getId(), $entity->toArray());
        }
        ......@@ -101,6 +101,11 @@ function _menu_ui_node_save(NodeInterface $node, array $values) {
        $entity = $entity->getTranslation($node->language()->getId());
        }
        }
        else {
        // Ensure the entity matches the node language.
        $entity = $entity->getUntranslated();
        $entity->set($entity->getEntityType()->getKey('langcode'), $node->language()->getId());
        }
        }
        else {
        // Create a new menu_link_content entity.
        ......
        <?php
        namespace Drupal\Tests\menu_ui\Functional;
        use Drupal\Core\Language\LanguageInterface;
        use Drupal\Tests\BrowserTestBase;
        use Drupal\language\Entity\ConfigurableLanguage;
        /**
        * Tests Menu UI and Content Translation integration for content entities.
        *
        * @group menu_ui
        */
        class MenuUiContentTranslationTest extends BrowserTestBase {
        /**
        * {@inheritdoc}
        */
        protected $defaultTheme = 'stark';
        /**
        * Modules to install.
        *
        * @var array
        */
        protected static $modules = [
        'block',
        'language',
        'content_translation',
        'menu_ui',
        'node',
        ];
        /**
        * {@inheritdoc}
        */
        protected function setUp(): void {
        parent::setUp();
        // Place menu block and local tasks block.
        $this->drupalPlaceBlock('system_menu_block:main');
        $this->drupalPlaceBlock('local_tasks_block');
        // Create a 'page' content type.
        $this->drupalCreateContentType([
        'type' => 'page',
        'name' => 'Basic page',
        'display_submitted' => FALSE,
        ]);
        // Add a second language.
        ConfigurableLanguage::createFromLangcode('de')->save();
        // Create an account and login.
        $user = $this->drupalCreateUser([
        'administer site configuration',
        'administer nodes',
        'create page content',
        'edit any page content',
        'delete any page content',
        'administer content translation',
        'translate any entity',
        'create content translations',
        'administer languages',
        'administer content types',
        'administer menu',
        ]);
        $this->drupalLogin($user);
        // Enable translation for page nodes and menu link content.
        $edit = [
        'entity_types[node]' => TRUE,
        'settings[node][page][translatable]' => TRUE,
        'settings[node][page][settings][language][language_alterable]' => TRUE,
        'entity_types[menu_link_content]' => TRUE,
        'settings[menu_link_content][menu_link_content][translatable]' => TRUE,
        'settings[menu_link_content][menu_link_content][settings][language][language_alterable]' => TRUE,
        ];
        $this->drupalGet('admin/config/regional/content-language');
        $this->assertSession()->statusCodeEquals(200);
        $this->submitForm($edit, 'Save configuration');
        $this->assertSession()->statusCodeEquals(200);
        }
        /**
        * Gets a content entity object by title.
        *
        * @param string $entity_type_id
        * Id of content entity type of content entity to load.
        * @param string $title
        * Title of content entity to load.
        *
        * @return \Drupal\Core\Entity\ContentEntityInterface
        * First found content entity with given title.
        */
        protected function getContentEntityByTitle($entity_type_id, $title) {
        $entity_type_manager = $this->container->get('entity_type.manager');
        $storage = $entity_type_manager->getStorage($entity_type_id);
        $storage->resetCache();
        $entities = $storage->loadByProperties([
        'title' => $title,
        ]);
        return reset($entities);
        }
        /**
        * Provides test data sets for testChangeContentToPseudoLanguage().
        *
        * @return array
        * Data sets to test keyed by data set label.
        */
        public function provideChangeContentToPseudoLanguageData() {
        return [
        'und' => ['langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED],
        'zxx' => ['langcode' => LanguageInterface::LANGCODE_NOT_APPLICABLE],
        ];
        }
        /**
        * Tests changing content with menu link from language to pseudo language.
        *
        * @param string $langcode
        * Language code of pseudo-language to change content language to.
        * Either \Drupal\Core\LanguageInterface::LANGCODE_NOT_SPECIFIED or
        * \Drupal\Core\LanguageInterface::LANGCODE_NOT_APPLICABLE.
        *
        * @dataProvider provideChangeContentToPseudoLanguageData
        */
        public function testChangeContentToPseudoLanguage($langcode) {
        $node_title = 'Test node';
        $menu_link_title_en = 'Test menu link EN';
        $menu_link_title_pseudo = 'Test menu link PSEUDO';
        // Create a page node in English.
        $this->drupalGet('node/add/page');
        $this->assertSession()->statusCodeEquals(200);
        $edit = [
        'title[0][value]' => $node_title,
        'menu[enabled]' => 1,
        'menu[title]' => $menu_link_title_en,
        ];
        $this->submitForm($edit, 'Save');
        $this->assertSession()->statusCodeEquals(200);
        // Assert that node exists and node language is English.
        $node = $this->getContentEntityByTitle('node', $node_title);
        $this->assertTrue(is_object($node));
        $this->assertTrue($node->language()->getId() == 'en');
        // Assert that menu link exists and menu link language is English.
        $menu_link = $this->getContentEntityByTitle('menu_link_content', $menu_link_title_en);
        $this->assertTrue(is_object($menu_link));
        $this->assertTrue($menu_link->language()->getId() == 'en');
        $this->assertTrue($menu_link->hasTranslation('en'));
        // Assert that menu link is visible with initial title.
        $this->assertSession()->linkExists($menu_link_title_en);
        // Change language of page node and title of its menu link.
        $this->clickLink('Edit');
        $edit = [
        'langcode[0][value]' => $langcode,
        'menu[title]' => $menu_link_title_pseudo,
        ];
        $this->submitForm($edit, 'Save');
        $this->assertSession()->statusCodeEquals(200);
        // Assert that node exists and node language is target language.
        $node = $this->getContentEntityByTitle('node', $node_title);
        $this->assertTrue(is_object($node));
        $this->assertTrue($node->language()->getId() == $langcode);
        // Assert that menu link exists and menu link language is target language.
        $menu_link = $this->getContentEntityByTitle('menu_link_content', $menu_link_title_pseudo);
        $this->assertTrue(is_object($menu_link));
        $this->assertTrue($menu_link->language()->getId() == $langcode);
        $this->assertFalse($menu_link->hasTranslation('en'));
        // Assert that menu link is visible with updated title.
        $this->assertSession()->linkExists($menu_link_title_pseudo);
        }
        }
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please register or to comment