Skip to content
Snippets Groups Projects
Commit 39fccae3 authored by jaapjansma's avatar jaapjansma
Browse files

Add type for weekdays

parent 6a0bde2d
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ Version 1.3
* Fix for converting Title into Name.
* Fixed issue with updating status with overridden.
* Added getoptions to the FormProcessor and FormProcessorDefaults API.
* Added a type with a list of weekdays
Version 1.2
===========
......
......@@ -35,6 +35,7 @@
$this->addType(new ParticipantStatusType('ParticipantStatusType', E::ts('Participant Status')));
$this->addType(new CampaignType('CampaignType', E::ts('Campaign')));
$this->addType(new FileType('file', E::ts('File')));
$this->addType(new WeekDays('WeekDays', E::ts('Week Days')));
}
/**
......
<?php
/**
* @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org>
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/
namespace Civi\FormProcessor\Type;
use \Civi\FormProcessor\Config\Specification;
use \Civi\FormProcessor\Config\SpecificationBag;
use \CRM_FormProcessor_ExtensionUtil as E;
class WeekDays extends AbstractType implements OptionListInterface {
/**
* Get the configuration specification
*
* @return SpecificationBag
*/
public function getConfigurationSpecification() {
return new SpecificationBag(array(
new Specification('multiple', 'Boolean', E::ts('Multiple'), false, 0, null, array(0=>E::ts('Single value'), 1=>E::ts('Multiple values'))),
));
}
public function validateValue($value, $allValues=array()) {
$multiple = $this->configuration->get('multiple') ? true : false;
$options = $this->getOptions();
if ($multiple && is_array($value)) {
foreach ($value as $valueItem) {
if (\CRM_Utils_Type::validate($valueItem, 'String', FALSE) === NULL) {
return FALSE;
}
if (!isset($options[$valueItem])) {
return FALSE;
}
}
} elseif (!is_array($value) && $value) {
if (\CRM_Utils_Type::validate($value, 'String', FALSE) === NULL) {
return FALSE;
}
if (!isset($options[$value])) {
return false;
}
} else {
return false;
}
return true;
}
/**
* Returns the type number from CRM_Utils_Type
*/
public function getCrmType() {
return \CRM_Utils_Type::T_STRING;
}
public function getOptions($params) {
$options = array(
'sunday' => E::ts('Sunday'),
'monday' => E::ts('Monday'),
'tuesday' => E::ts('Tuesday'),
'wednesday' => E::ts('Wednesday'),
'thursday' => E::ts('Thursday'),
'friday' => E::ts('Friday'),
'saturday' => E::ts('Saturday'),
);
return $options;
}
}
......@@ -6,7 +6,6 @@
$scope.locks = {name: true};
$scope.isNameValid = false;
$scope.validators = CRM.form_processor.validators;
if (!$scope.input.deletedValidators) {
$scope.input.deletedValidators = [];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment