Download tasks/1cad399a2f9eae99/source/patch.diff from FuCY/php: direct link, hf CLI and curl.
- Browser
- Download file 3.45 kB
-
https://huggingface.co/datasets/FuCY/php/resolve/main/tasks/1cad399a2f9eae99/source/patch.diff
- Command line
-
hf download hf://datasets/FuCY/php/tasks/1cad399a2f9eae99/source/patch.diff
-
curl -L -o patch.diff https://huggingface.co/datasets/FuCY/php/resolve/main/tasks/1cad399a2f9eae99/source/patch.diff
3.45 kB
| diff --git a/src/Forms/GridField/GridFieldPrintButton.php b/src/Forms/GridField/GridFieldPrintButton.php | |
| index 1ec2be669f6..1fc965808e1 100644 | |
| --- a/src/Forms/GridField/GridFieldPrintButton.php | |
| +++ b/src/Forms/GridField/GridFieldPrintButton.php | |
| public function generatePrintData(GridField $gridField) | |
| /** @var DataObject $item */ | |
| foreach ($items->limit(null) as $item) { | |
| - $itemRow = new ArrayList(); | |
| + if (!$item->hasMethod('canView') || $item->canView()) { | |
| + $itemRow = new ArrayList(); | |
| - foreach ($printColumns as $field => $label) { | |
| - $value = $gridFieldColumnsComponent | |
| - ? strip_tags($gridFieldColumnsComponent->getColumnContent($gridField, $item, $field)) | |
| - : $gridField->getDataFieldValue($item, $field); | |
| + foreach ($printColumns as $field => $label) { | |
| + $value = $gridFieldColumnsComponent | |
| + ? strip_tags($gridFieldColumnsComponent->getColumnContent($gridField, $item, $field)) | |
| + : $gridField->getDataFieldValue($item, $field); | |
| + | |
| + $itemRow->push(new ArrayData([ | |
| + "CellString" => $value, | |
| + ])); | |
| + } | |
| - $itemRow->push(new ArrayData([ | |
| - "CellString" => $value, | |
| + $itemRows->push(new ArrayData([ | |
| + "ItemRow" => $itemRow | |
| ])); | |
| } | |
| - | |
| - $itemRows->push(new ArrayData([ | |
| - "ItemRow" => $itemRow | |
| - ])); | |
| if ($item->hasMethod('destroy')) { | |
| $item->destroy(); | |
| } | |
| diff --git a/tests/php/Forms/GridField/GridFieldPrintButtonTest.php b/tests/php/Forms/GridField/GridFieldPrintButtonTest.php | |
| index 59e73a494ca..f78c305bab8 100644 | |
| --- a/tests/php/Forms/GridField/GridFieldPrintButtonTest.php | |
| +++ b/tests/php/Forms/GridField/GridFieldPrintButtonTest.php | |
| protected function setUp(): void | |
| } | |
| public function testLimit() | |
| + { | |
| + $this->assertEquals(42, $this->getTestableRows()->count()); | |
| + } | |
| + | |
| + public function testCanViewIsRespected() | |
| + { | |
| + $orig = TestObject::$canView; | |
| + TestObject::$canView = false; | |
| + $this->assertEquals(0, $this->getTestableRows()->count()); | |
| + TestObject::$canView = $orig; | |
| + } | |
| + | |
| + private function getTestableRows() | |
| { | |
| $list = TestObject::get(); | |
| public function testLimit() | |
| // Printed data should ignore pagination limit | |
| $printData = $button->generatePrintData($gridField); | |
| - $rows = $printData->ItemRows; | |
| - $this->assertEquals(42, $rows->count()); | |
| + return $printData->ItemRows; | |
| } | |
| } | |
| diff --git a/tests/php/Forms/GridField/GridFieldPrintButtonTest/TestObject.php b/tests/php/Forms/GridField/GridFieldPrintButtonTest/TestObject.php | |
| index 2e8f80cc9d6..dd5638d0926 100644 | |
| --- a/tests/php/Forms/GridField/GridFieldPrintButtonTest/TestObject.php | |
| +++ b/tests/php/Forms/GridField/GridFieldPrintButtonTest/TestObject.php | |
| class TestObject extends DataObject implements TestOnly | |
| private static $db = [ | |
| 'Name' => 'Varchar' | |
| ]; | |
| + | |
| + public static bool $canView = true; | |
| + | |
| + public function canView($member = null) | |
| + { | |
| + return static::$canView; | |
| + } | |
| } | |