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

Issue #3101344 by Akhil Babu, Alex Bukach, ravi.shankar, quietone,...

Issue #3101344 by Akhil Babu, Alex Bukach, ravi.shankar, quietone, agentrickard, kriboogh, allaprishchepa, flyke, Mschudders, rgpublic, smustgrave, borisson_: hook_node_grants implementations lead to a 'URL Alias' validation error when saving translated nodes

(cherry picked from commit f665483c)
parent 51cd1878
No related branches found
No related tags found
12 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...
Pipeline #88099 canceled
Pipeline: drupal

#88100

    ...@@ -82,10 +82,16 @@ public function access(NodeInterface $node, $operation, AccountInterface $accoun ...@@ -82,10 +82,16 @@ public function access(NodeInterface $node, $operation, AccountInterface $accoun
    $query->addExpression('1'); $query->addExpression('1');
    // Only interested for granting in the current operation. // Only interested for granting in the current operation.
    $query->condition('grant_' . $operation, 1, '>='); $query->condition('grant_' . $operation, 1, '>=');
    // Check for grants for this node and the correct langcode. // Check for grants for this node and the correct langcode. New translations
    // do not yet have a langcode and must check the fallback node record.
    $nids = $query->andConditionGroup() $nids = $query->andConditionGroup()
    ->condition('nid', $node->id()) ->condition('nid', $node->id());
    ->condition('langcode', $node->language()->getId()); if (!$node->isNewTranslation()) {
    $nids->condition('langcode', $node->language()->getId());
    }
    else {
    $nids->condition('fallback', 1);
    }
    // If the node is published, also take the default grant into account. The // If the node is published, also take the default grant into account. The
    // default is saved with a node ID of 0. // default is saved with a node ID of 0.
    $status = $node->isPublished(); $status = $node->isPublished();
    ......
    name: 'Path test with node grants'
    type: module
    description: 'Tests URL alias with hook_node_grants implementation'
    package: Testing
    version: VERSION
    <?php
    /**
    * @file
    * Contains hook implementations for the Path test with node grants module.
    */
    use Drupal\Core\Session\AccountInterface;
    /**
    * Implements hook_node_grants().
    */
    function path_test_node_grants_node_grants(AccountInterface $account, $operation): array {
    $grants = [];
    return $grants;
    }
    <?php
    namespace Drupal\Tests\path\Functional;
    use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
    use Drupal\Tests\content_translation\Traits\ContentTranslationTestTrait;
    /**
    * Confirm that paths work with node access grants implementations.
    *
    * @group path
    */
    class PathWithNodeAccessGrantsTest extends PathTestBase {
    use ContentTranslationTestTrait;
    use ContentModerationTestTrait;
    /**
    * Modules to enable.
    *
    * @var array
    */
    protected static $modules = [
    'path',
    'locale',
    'locale_test',
    'content_translation',
    'content_moderation',
    'path_test_node_grants',
    ];
    /**
    * {@inheritdoc}
    */
    protected $defaultTheme = 'stark';
    /**
    * {@inheritdoc}
    */
    protected function setUp(): void {
    parent::setUp();
    // Create a workflow for basic page.
    $workflow = $this->createEditorialWorkflow();
    $this->addEntityTypeAndBundleToWorkflow($workflow, 'node', 'page');
    // Login as admin user to configure language detection and selection.
    $admin_user = $this->drupalCreateUser([
    'edit any page content',
    'create page content',
    'administer url aliases',
    'create url aliases',
    'administer languages',
    'access administration pages',
    ]);
    $this->drupalLogin($admin_user);
    // Enable French language.
    static::createLanguageFromLangcode('fr');
    // Enable URL language detection and selection.
    $edit = ['language_interface[enabled][language-url]' => 1];
    $this->drupalGet('admin/config/regional/language/detection');
    $this->submitForm($edit, 'Save settings');
    // Enable translation for page node.
    static::enableContentTranslation('node', 'page');
    static::setFieldTranslatable('node', 'page', 'body', TRUE);
    $definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('node', 'page');
    $this->assertTrue($definitions['path']->isTranslatable(), 'Node path is translatable.');
    $this->assertTrue($definitions['body']->isTranslatable(), 'Node body is translatable.');
    }
    /**
    * Tests alias functionality through the admin interfaces.
    */
    public function testAliasTranslation() : void {
    // Rebuild the permissions to update 'node_access' table.
    node_access_rebuild();
    $alias = $this->randomMachineName();
    $permissions = [
    'access administration pages',
    'view any unpublished content',
    'use editorial transition create_new_draft',
    'use editorial transition publish',
    'create content translations',
    'create page content',
    'create url aliases',
    'edit any page content',
    'translate any entity',
    ];
    $this->drupalLogin($this->drupalCreateUser($permissions));
    // Create a node, add URL alias and publish it.
    $this->drupalGet('node/add/page');
    $edit['title[0][value]'] = 'test';
    $edit['path[0][alias]'] = '/' . $alias;
    $edit['moderation_state[0][state]'] = 'published';
    $this->submitForm($edit, 'Save');
    // Add french translation.
    $this->drupalGet('node/1/translations');
    $this->clickLink('Add');
    $this->submitForm(['moderation_state[0][state]' => 'published'], 'Save (this translation)');
    // Translation should be saved.
    $this->assertSession()->pageTextContains('Basic page test has been updated.');
    // There shouldn't be any validation errors.
    $this->assertSession()->pageTextNotContains("Either the path '/node/1' is invalid or you do not have access to it.");
    // Translation should be saved with the given alias.
    $this->container->get('path_alias.manager')->cacheClear();
    $translation_alias = $this->container->get('path_alias.manager')->getAliasByPath('/node/1', 'fr');
    $this->assertSame('/' . $alias, $translation_alias);
    }
    }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment