diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 8f7318b..2542772 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -3194,24 +3194,33 @@ function _node_access_write_grants(Node $node, $grants, $realm = NULL, $delete = // Only perform work when node_access modules are active. if (!empty($grants) && count(module_implements('node_grants'))) { $query = db_insert('node_access')->fields(array('nid', 'langcode', 'fallback', 'realm', 'gid', 'grant_view', 'grant_update', 'grant_delete')); - foreach ($grants as $grant) { - if ($realm && $realm != $grant['realm']) { - continue; - } - // Only write grants; denies are implicit. - if ($grant['grant_view'] || $grant['grant_update'] || $grant['grant_delete']) { - $grant['nid'] = $node->nid; - if (!isset($grant['langcode'])) { - $grant['langcode'] = $node->langcode; - } - // The record with the original langcode is used as the fallback. - if ($grant['langcode'] == $node->langcode) { - $grant['fallback'] = 1; + // If we have defined a granted langcode, use it. + // But if not, check if we have translations enabled and add a grant for + // every language this node can be translated to. + if (isset($grant['langcode'])) { + $grant_languages = array($grant['langcode'] => language_load($grant['langcode'])); + } + else { + $grant_languages = $node->getTranslationLanguages(TRUE); + } + foreach ($grant_languages as $grant_langcode => $grant_language) { + foreach ($grants as $grant) { + if ($realm && $realm != $grant['realm']) { + continue; } - else { - $grant['fallback'] = 0; + // Only write grants; denies are implicit. + if ($grant['grant_view'] || $grant['grant_update'] || $grant['grant_delete']) { + $grant['nid'] = $node->nid; + $grant['langcode'] = $grant_language->langcode; + // The record with the original langcode is used as the fallback. + if ($grant['langcode'] == $node->langcode) { + $grant['fallback'] = 1; + } + else { + $grant['fallback'] = 0; + } + $query->values($grant); } - $query->values($grant); } } $query->execute();