Compare commits

...

5 Commits

Author SHA1 Message Date
Guy Sartorelli 56625081b4
ENH Use allowed view button for readonly GridField (#11228) 2024-05-17 10:28:47 +12:00
Guy Sartorelli cd77301de1
Merge pull request #11236 from creative-commoners/pulls/5/deprecate-non-array
API Deprecate passing non-arrays to FieldList methods
2024-05-17 09:52:29 +12:00
Guy Sartorelli 7625b29937
Merge pull request #11239 from creative-commoners/pulls/5/module-standardiser-1715811311
MNT Run module-standardiser
2024-05-17 09:47:13 +12:00
Steve Boyd 264dfac902 MNT Run module-standardiser 2024-05-16 14:43:48 +12:00
Steve Boyd 0ba85bc1d0 API Deprecate passing non-arrays to FieldList methods 2024-05-14 12:43:59 +12:00
9 changed files with 83 additions and 63 deletions

View File

@ -1,9 +1,11 @@
name: Dispatch CI
on:
# At 2:20 PM UTC, only on Tuesday and Wednesday
# At 4:20 PM UTC, only on Friday and Saturday
schedule:
- cron: '20 14 * * 2,3'
- cron: '20 16 * * 5,6'
permissions: {}
jobs:
dispatch-ci:
@ -11,6 +13,9 @@ jobs:
# Only run cron on the silverstripe account
if: (github.event_name == 'schedule' && github.repository_owner == 'silverstripe') || (github.event_name != 'schedule')
runs-on: ubuntu-latest
permissions:
contents: read
actions: write
steps:
- name: Dispatch CI
uses: silverstripe/gha-dispatch-ci@v1

View File

@ -1,17 +1,21 @@
name: Keepalive
on:
# At 1:05 PM UTC, on day 22 of the month
# At 4:20 PM UTC, on day 13 of the month
schedule:
- cron: '5 13 22 * *'
- cron: '20 16 13 * *'
workflow_dispatch:
permissions: {}
jobs:
keepalive:
name: Keepalive
# Only run cron on the silverstripe account
if: (github.event_name == 'schedule' && github.repository_owner == 'silverstripe') || (github.event_name != 'schedule')
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- name: Keepalive
uses: silverstripe/gha-keepalive@v1

View File

@ -1,17 +1,22 @@
name: Merge-up
on:
# At 2:20 PM UTC, only on Saturday
# At 4:20 PM UTC, only on Tuesday
schedule:
- cron: '20 14 * * 6'
- cron: '20 16 * * 2'
workflow_dispatch:
permissions: {}
jobs:
merge-up:
name: Merge-up
# Only run cron on the silverstripe account
if: (github.event_name == 'schedule' && github.repository_owner == 'silverstripe') || (github.event_name != 'schedule')
runs-on: ubuntu-latest
permissions:
contents: write
actions: write
steps:
- name: Merge-up
uses: silverstripe/gha-merge-up@v1

View File

@ -1,15 +0,0 @@
# Contributing
Any open source product is only as good as the community behind it. You can participate by sharing code, ideas, or simply helping others. No matter what your skill level is, every contribution counts.
See our [high level overview](http://silverstripe.org/contributing-to-silverstripe) on silverstripe.org on how you can help out.
## Copyright
**IMPORTANT: By supplying code to the SilverStripe core team in patches, tickets and pull requests, you agree to assign copyright of that code to SilverStripe Limited, on the condition that SilverStripe Limited releases that code under the BSD license.**
We ask for this so that the ownership in the license is clear and unambiguous, and so that community involvement doesn't stop us from being able to continue supporting these projects. By releasing this code under a permissive license, this copyright assignment won't prevent you from using the code in any way you see fit.
## Contributing code
See [contributing code](https://docs.silverstripe.org/en/4/contributing/code/)

View File

@ -1,39 +0,0 @@
# Support
The issue tracker is reserved for reporting bugs and we don't provide support through it. Support tickets opened via the issue tracker will be closed.
If you require support there are two types of support available: community support and commercial support.
## Community support
Community support is provided by members of our open source community and is provided out of their good will. Please be kind, polite and corteous to those that try to help you; you may wish to refer to our [code of conduct](https://docs.silverstripe.org/en/4/contributing/code_of_conduct/).
You can find support via:
- [Stack Overflow (remember to tag as silverstripe)](http://stackoverflow.com/questions/tagged/silverstripe)
- [Slack](https://silverstripe.org/slack)
- [Forum](https://forum.silverstripe.org)
We recommend choosing the support forum based on the nature of your question:
### Do you have some code you've tried that isn't working?
Your question will likely be best on Stack Overflow. You can add some detail about what you're trying to achieve and include some code that you have tried. Stack Overflow is a good forum for answers to be detailed and become available in the future for other developers in your position. Remember to [follow the guidance on Stack Overflow](https://stackoverflow.com/help/how-to-ask) for asking good questions!
### Are you looking for an answer to a quick question or a recommendation for an approach or suitable SilverStripe module?
The SilverStripe community Slack has a wealth of active SilverStripe developers active daily. Remember that those who contribute usually do so in their free time so be considerate when messaging people directly. Consider if your issue might benefit another developer before choosing Slack. An alternate forum like StackOverflow may help other developers that are experiencing the same issue find a resolution.
### Are you looking for detailed feedback on a suggestion or module you have developed?
Try starting a discussion in the community forum. Developers and users alike use the forum to keep up to date with the SilverStripe community and contributions that people are making or discussing.
### More information
For more information please see our [community page](http://www.silverstripe.org/community/#introduction).
## Commercial support
If you require a higher level of support with an SLA, you may want to consider commercial support provided by SilverStripe Ltd, a Professional Partner or another SilverStripe agency.
Please see the [SilverStripe Developer Directory](https://www.silverstripe.org/community/developer-and-partner-directory/) for more information.

View File

@ -3,6 +3,7 @@
namespace SilverStripe\Forms;
use SilverStripe\ORM\ArrayList;
use SilverStripe\Dev\Deprecation;
/**
* A list designed to hold form field instances.
@ -218,6 +219,10 @@ class FieldList extends ArrayList
*/
public function addFieldsToTab($tabName, $fields, $insertBefore = null)
{
if (!is_array($fields)) {
Deprecation::notice('5.3.0', '$fields will need to be passed as an array in CMS 6', Deprecation::SCOPE_METHOD);
}
$this->flushFieldsCache();
// Find the tab
@ -270,6 +275,10 @@ class FieldList extends ArrayList
*/
public function removeFieldsFromTab($tabName, $fields)
{
if (!is_array($fields)) {
Deprecation::notice('5.3.0', '$fields will need to be passed as an array in CMS 6', Deprecation::SCOPE_METHOD);
}
$this->flushFieldsCache();
// Find the tab

View File

@ -276,9 +276,18 @@ class GridField extends FormField
}
}
// If the edit button has been removed, replace it with a view button
// If the edit button has been removed, replace it with a view button if one is allowed
if ($hadEditButton && !$copyConfig->getComponentByType(GridFieldViewButton::class)) {
$copyConfig->addComponent(GridFieldViewButton::create());
$viewButtonClass = null;
foreach ($allowedComponents as $componentClass) {
if (is_a($componentClass, GridFieldViewButton::class, true)) {
$viewButtonClass = $componentClass;
break;
}
}
if ($viewButtonClass) {
$copyConfig->addComponent($viewButtonClass::create());
}
}
$copy->extend('afterPerformReadonlyTransformation', $this);

View File

@ -20,6 +20,8 @@ use SilverStripe\Forms\Tests\GridField\GridFieldTest\Cheerleader;
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Team;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldViewButton;
use SilverStripe\Forms\Tests\GridField\GridFieldReadonlyTest\GridFieldViewButtonReplacement;
use SilverStripe\Versioned\VersionedGridFieldState\VersionedGridFieldState;
class GridFieldReadonlyTest extends SapphireTest
@ -31,11 +33,28 @@ class GridFieldReadonlyTest extends SapphireTest
Cheerleader::class,
];
public function provideReadOnlyTransformation(): array
{
return [
[
'viewButtonClass' => null,
],
[
'viewButtonClass' => GridFieldViewButton::class,
],
[
'viewButtonClass' => GridFieldViewButtonReplacement::class,
],
];
}
/**
* The CMS can set the value of a GridField to be a hasMany relation, which needs a readonly state.
* This test ensures GridField has a readonly transformation.
*
* @dataProvider provideReadOnlyTransformation
*/
public function testReadOnlyTransformation()
public function testReadOnlyTransformation(?string $viewButtonClass)
{
// Build a hasMany Relation via getComponents like ModelAdmin does.
$components = Team::get_one(Team::class)
@ -67,6 +86,18 @@ class GridFieldReadonlyTest extends SapphireTest
$gridConfig
);
if ($viewButtonClass !== GridFieldViewButton::class) {
$allowedComponents = $gridField->getReadonlyComponents();
$viewButtonIndex = array_search(GridFieldViewButton::class, $allowedComponents);
if ($viewButtonIndex !== false) {
unset($allowedComponents[$viewButtonIndex]);
}
if ($viewButtonClass !== null) {
$allowedComponents[] = $viewButtonClass;
}
$gridField->setReadonlyComponents($allowedComponents);
}
// Model Admin sets the value of the GridField directly to the relation, which doesn't have a forTemplate()
// function, if we rely on FormField to render into a ReadonlyField we'll get an error as HasManyRelation
// doesn't have a forTemplate() function.

View File

@ -0,0 +1,11 @@
<?php
namespace SilverStripe\Forms\Tests\GridField\GridFieldReadonlyTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\Forms\GridField\GridFieldViewButton;
class GridFieldViewButtonReplacement extends GridFieldViewButton implements TestOnly
{
}