Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SilverStripe4 upgrade #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/composer.lock
/resources
/vendor
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Our primary use case for this module was for use in a ModelAdmin within the CMS

Use composer:

composer require 'deptinternalaffairsnz/silverstripe-date-range-field' '1.0.0'
composer require 'deptinternalaffairsnz/silverstripe-date-range-field'

## Usage

Expand All @@ -17,7 +17,7 @@ When configuring `searchable_fields` for a `DataObject` you can make use of the
private static $searchable_fields = array(
'Created' => array(
'title' => 'created date',
'field' => 'DeptInternalAffairsNZ\SilverStripe\DateRangeField',
'filter' => 'DeptInternalAffairsNZ\SilverStripe\DateRangeFilter'
'field' => \DeptInternalAffairsNZ\SilverStripe\Forms\DateRangeField::class,
'filter' => \DeptInternalAffairsNZ\SilverStripe\Forms\DateRangeFilter::class,
)
);
69 changes: 0 additions & 69 deletions code/DateRangeField.php

This file was deleted.

102 changes: 0 additions & 102 deletions code/DateRangeFilter.php

This file was deleted.

12 changes: 8 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
{
"name": "deptinternalaffairsnz/silverstripe-date-range-field",
"description": "A date range field and filter for SilverStripe",
"type": "silverstripe-module",
"type": "silverstripe-vendormodule",
"license": "BSD-3-Clause",
"authors": [
{
"name": "James Goodman",
"email": "[email protected]"
}
],
"require": {},
"extra": {
"installer-name": "date-range-field"
"require": {
"silverstripe/framework": "^4@dev"
},
"autoload": {
"psr-4": {
"DeptInternalAffairsNZ\\SilverStripe\\": "src/"
}
}
}
87 changes: 87 additions & 0 deletions src/Forms/DateRangeField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

namespace DeptInternalAffairsNZ\SilverStripe\Forms;

use SilverStripe\Forms\CompositeField;
use SilverStripe\Forms\DateField;

class DateRangeField extends CompositeField
{

/**
* @var DateField
*/
protected $from;

/**
* @var DateField
*/
protected $to;

/**
* @var string
*/
public $dateFormat = 'yyyy-MM-dd';

public function __construct($name, $title = null, $value = null)
{
$this->name = $name;
$this->setTitle($title);

$this->from = new DateField($this->name . '[From]', $title, null);
$this->to = new DateField($this->name . '[To]', $title, null);

parent::__construct(array(
$this->from,
$this->to
));

$this->setConfig('showcalendar', true);

$this->from->setDateFormat($this->dateFormat);
$this->to->setDateFormat($this->dateFormat);

$this->setValue($value);
}

public function setConfig($key, $value)
{
$this->from->setAttribute($key, $value);
$this->to->setAttribute($key, $value);
}

public function hasData()
{
return true;
}

public function getValue()
{
return $this->value;
}

/**
* Set the field name
*/
public function setName($name)
{
$this->name = $name;
$this->from->setName($name . '[From]');
$this->to->setName($name . '[To]');
return $this;
}

public function setTitle($title)
{
parent::setTitle($title);

if ($this->from instanceof DateField) {
$this->from->setTitle('From ' . $title);
}

if ($this->to instanceof DateField) {
$this->to->setTitle('To ' . $title);
}
}

}
Loading