Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
colintucker committed Nov 3, 2017
2 parents 7eefb2d + fe42c14 commit 1a511d4
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"silverware/colorpicker": "^1.0",
"silverware/font-icons": "^1.0",
"silverware/select2": "^1.0",
"silverware/theme": "^1.0"
"silverware/theme": "^1.0",
"symbiote/silverstripe-gridfieldextensions": "3.0.x-dev"
},
"autoload": {
"psr-4": {
Expand Down
103 changes: 103 additions & 0 deletions src/Forms/GridField/GridFieldConfig_MultiClassEditor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

/**
* This file is part of SilverWare.
*
* PHP version >=5.6.0
*
* For full copyright and license information, please view the
* LICENSE.md file that was distributed with this source code.
*
* @package SilverWare\Forms\GridField
* @author Colin Tucker <colin@praxis.net.au>
* @copyright 2017 Praxis Interactive
* @license https://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
* @link https://github.com/praxisnetau/silverware
*/

namespace SilverWare\Forms\GridField;

use SilverStripe\Core\ClassInfo;
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverWare\Tools\ClassTools;
use Symbiote\GridFieldExtensions\GridFieldAddNewMultiClass;
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;

/**
* An extension of the grid field config record editor class for a multi-class editor config.
*
* @package SilverWare\Forms\GridField
* @author Colin Tucker <colin@praxis.net.au>
* @copyright 2017 Praxis Interactive
* @license https://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
* @link https://github.com/praxisnetau/silverware
*/
class GridFieldConfig_MultiClassEditor extends GridFieldConfig_RecordEditor
{
/**
* Constructs the object upon instantiation.
*
* @param integer $itemsPerPage
*/
public function __construct($itemsPerPage = null)
{
// Construct Parent:

parent::__construct($itemsPerPage);

// Construct Object:

$this->addComponents(
new GridFieldOrderableRows(),
new GridFieldAddNewMultiClass()
)->removeComponentsByType(GridFieldAddNewButton::class);

// Apply Extensions:

$this->extend('updateConfig');
}

/**
* Defines the classes that can be created using the grid field.
*
* @param array $classes Class names optionally mapped to titles.
* @param string $default Optional default class name.
*
* @return $this
*/
public function setClasses($classes, $default = null)
{
if ($component = $this->getComponentByType(GridFieldAddNewMultiClass::class)) {
$component->setClasses($classes, $default);
}

return $this;
}

/**
* Defines the creatable classes as descendants of the specified class (does not include the specified class).
*
* @param string $class Parent class name.
* @param string $default Optional default class name.
*
* @return $this
*/
public function useDescendantsOf($class, $default = null)
{
return $this->setClasses(array_keys(ClassTools::singleton()->getDescendantsOf($class)), $default);
}

/**
* Defines the creatable classes as subclasses of the specified class (includes the specified class).
*
* @param string $class Parent class name.
* @param string $default Optional default class name.
*
* @return $this
*/
public function useSubclassesOf($class, $default = null)
{
return $this->setClasses(array_keys(ClassInfo::subclassesFor($class)), $default);
}
}
53 changes: 53 additions & 0 deletions src/Forms/GridField/GridFieldConfig_OrderableEditor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/**
* This file is part of SilverWare.
*
* PHP version >=5.6.0
*
* For full copyright and license information, please view the
* LICENSE.md file that was distributed with this source code.
*
* @package SilverWare\Forms\GridField
* @author Colin Tucker <colin@praxis.net.au>
* @copyright 2017 Praxis Interactive
* @license https://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
* @link https://github.com/praxisnetau/silverware
*/

namespace SilverWare\Forms\GridField;

use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;

/**
* An extension of the grid field config record editor class for an orderable editor config.
*
* @package SilverWare\Forms\GridField
* @author Colin Tucker <colin@praxis.net.au>
* @copyright 2017 Praxis Interactive
* @license https://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
* @link https://github.com/praxisnetau/silverware
*/
class GridFieldConfig_OrderableEditor extends GridFieldConfig_RecordEditor
{
/**
* Constructs the object upon instantiation.
*
* @param integer $itemsPerPage
*/
public function __construct($itemsPerPage = null)
{
// Construct Parent:

parent::__construct($itemsPerPage);

// Construct Object:

$this->addComponent(new GridFieldOrderableRows());

// Apply Extensions:

$this->extend('updateConfig');
}
}
13 changes: 13 additions & 0 deletions src/Tools/ClassTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use SilverStripe\Core\Convert;
use SilverStripe\Core\Injector\Injectable;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Manifest\ClassLoader;
use SilverStripe\ORM\HiddenClass;
use ReflectionException;

Expand Down Expand Up @@ -80,6 +81,18 @@ public function getReverseAncestry($nameOrObject)
return array_reverse(ClassInfo::ancestry($nameOrObject));
}

/**
* Answers an array containing the descendants of the specified class name.
*
* @param string $name Name of parent class.
*
* @return array
*/
public function getDescendantsOf($name)
{
return ClassLoader::inst()->getManifest()->getDescendantsOf($name);
}

/**
* Answers the visible subclasses of the specified class name.
*
Expand Down

0 comments on commit 1a511d4

Please sign in to comment.