3336994 StringFormatter access
3 unresolved threads
3 unresolved threads
Co-authored-by: Dezső BICZÓ mxr576@gmail.com
Closes #3336994
Merge request reports
Activity
added 18 commits
-
3ce751e2...9fc1bc9a - 10 commits from branch
project:11.x
- 33e26852 - 3336994 StringFormatter access
- a628b554 - fix cs
- 274f0fc7 - fix test: needs table installed for access check
- ad13f561 - added combined coverage for both link template and access result
- 2d4eb1d3 - cspell doesnt link this
- 7483389d - Fix cs again
- 46b6de07 - Fix issues reported by PHPStan
- d0714b0f - Fix failing test
Toggle commit list-
3ce751e2...9fc1bc9a - 10 commits from branch
added 40 commits
-
d0714b0f...62f9af40 - 32 commits from branch
project:11.x
- fec06085 - 3336994 StringFormatter access
- 85828e24 - fix cs
- 34890dd4 - fix test: needs table installed for access check
- 0fb05cdf - added combined coverage for both link template and access result
- ce3cfb92 - cspell doesnt link this
- 46242e85 - Fix cs again
- b99766d5 - Fix issues reported by PHPStan
- f39d1de1 - Fix failing test
Toggle commit list-
d0714b0f...62f9af40 - 32 commits from branch
45 48 $this->installConfig(['filter']); 46 49 $this->installEntitySchema('node'); 47 50 $this->installEntitySchema('user'); 51 $this->setUpCurrentUser(['uid' => 0]); changed this line in version 4 of the diff
- Resolved by quietone
- Resolved by Dezső Biczó
22 23 */ 23 24 class FieldGroupRowsTest extends ViewsKernelTestBase { 24 25 26 use UserCreationTrait; changed this line in version 6 of the diff
mentioned in commit issue/drupal-3336994@5d0e6409
mentioned in commit issue/drupal-3336994@0390b8ab
139 ? [ 137 140 '#type' => 'link', 138 141 '#title' => $view_value, 139 142 '#url' => $url, 140 ]; 141 } 142 else { 143 $elements[$delta] = $view_value; 144 } 143 ] 144 : $view_value; 145 145 } 146 147 (new CacheableMetadata()) 148 ->addCacheableDependency($access) 149 ->applyTo($elements); - Comment on lines 125 to +149
I find it easier to be more consistent to avoid creating a meaningless
AccessResult::forbidden()
object and callingisAllowed()
in a loop.127 $url = NULL; 128 $entity = $items->getEntity(); 129 $entity_type = $entity->getEntityType(); 130 131 if ($this->getSetting('link_to_entity') && !$entity->isNew() && $entity_type->hasLinkTemplate('canonical')) { 132 $url = $this->getEntityUrl($entity); 133 } 134 135 $access = $url?->access(return_as_object: TRUE) ?? AccessResultForbidden::forbidden(); 136 foreach ($items as $delta => $item) { 137 $view_value = $this->viewValue($item); 138 $elements[$delta] = $access->isAllowed() 139 ? [ 140 '#type' => 'link', 141 '#title' => $view_value, 142 '#url' => $url, 143 ] 144 : $view_value; 145 } 146 147 (new CacheableMetadata()) 148 ->addCacheableDependency($access) 149 ->applyTo($elements); 127 $entity = $items->getEntity(); 128 $entity_type = $entity->getEntityType(); 129 130 $cacheability = new CacheableMetadata(); 131 if ($this->getSetting('link_to_entity') && !$entity->isNew() && $entity_type->hasLinkTemplate('canonical')) { 132 $url = $this->getEntityUrl($entity); 133 $access = $url->access(return_as_object: TRUE); 134 $cacheability->addCacheableDependency($access); 135 if (!$access->isAllowed()) { 136 $url = NULL; 137 } 138 } 139 else { 140 $url = NULL; 141 } 142 143 foreach ($items as $delta => $item) { 144 $view_value = $this->viewValue($item); 145 $elements[$delta] = $url 146 ? [ 147 '#type' => 'link', 148 '#title' => $view_value, 149 '#url' => $url, 150 ] 151 : $view_value; 152 } 153 154 $cacheability->applyTo($elements); changed this line in version 8 of the diff
@kksandr thx for your suggestion regarding code readability, you made a valid point on that. Please check my counter offer for improving that.
What I did not like in your solution is unsetting
$url
and making decisions based on that.@mxr576 it looks great.
Please register or sign in to reply