Commit dfcde545 authored by dpi's avatar dpi

Changed access config type from integer to boolean.

Requires strict type checks as FALSE and NULL are both valid.
parent eedae2fd
......@@ -2,7 +2,7 @@ rng.event_type.*.*.third_party.rng_date_scheduler:
type: mapping
mapping:
default_access:
type: integer
type: boolean
label: 'Default'
fields:
type: sequence
......@@ -20,11 +20,11 @@ rng_date_scheduler.field:
type: mapping
mapping:
before:
type: integer
type: boolean
label: 'Before'
during:
type: integer
type: boolean
label: 'During'
after:
type: integer
type: boolean
label: 'After'
......@@ -165,7 +165,7 @@ class DateExplain extends ControllerBase {
else if (!count($dates)) {
$default_access = $this->eventDateProvider
->getDefaultAccess($rng_event->getEntityTypeId(), $rng_event->bundle());
if ($default_access == -1) {
if ($default_access === FALSE) {
$messages[] = $this->t('New registrations are forbidden because there are no dates.');
}
}
......
......@@ -66,11 +66,11 @@ class EventDateProvider implements EventDateProviderInterface {
$date
->setFieldName($field_name)
->setDate($value)
->setAccessBefore($field['access']['before'] != -1)
->setAccessAfter($field['access']['after'] != -1);
->setAccessBefore($field['access']['before'])
->setAccessAfter($field['access']['after']);
if ($field_item_list->getSetting('datetime_type') == 'date') {
$during = $field['access']['during'] != -1;
$during = $field['access']['during'];
$date2 = clone $date;
......@@ -111,7 +111,7 @@ class EventDateProvider implements EventDateProviderInterface {
$dates = $this->getDates($event);
if (!count($dates)) {
$default_access = $this->getDefaultAccess($event->getEntityTypeId(), $event->bundle());
return AccessResult::forbiddenIf($default_access == -1)
return AccessResult::forbiddenIf($default_access === FALSE)
->addCacheableDependency($event);
}
......
......@@ -42,8 +42,8 @@ interface EventDateProviderInterface {
* @param $bundle
* An event type' bundle.
*
* @return int
* @todo revise to bool|NULL
* @return boolean|NULL
* FALSE if forbidden. NULL if neutral.
*/
function getDefaultAccess($entity_type_id, $bundle);
......
......@@ -78,7 +78,7 @@ class EventTypeDateSchedulerForm extends EntityForm {
'#type' => 'checkbox',
'#title' => $this->t('Deny by default'),
'#description' => $this->t('Deny new registrations if no dates are set on the event.'),
'#default_value' => $default_access == -1,
'#default_value' => $default_access === FALSE,
];
$form['table'] = [
......@@ -123,7 +123,7 @@ class EventTypeDateSchedulerForm extends EntityForm {
$access = [];
foreach (['before', 'during', 'after'] as $time) {
$access[$time] = isset($fields[$field_name]['access'][$time]) && $fields[$field_name]['access'][$time] == -1;
$access[$time] = isset($fields[$field_name]['access'][$time]) && $fields[$field_name]['access'][$time] === FALSE;
}
$row = [];
......@@ -184,7 +184,7 @@ class EventTypeDateSchedulerForm extends EntityForm {
*/
public function save(array $form, FormStateInterface $form_state) {
$event_type = &$this->entity;
$default = $form_state->getValue('default') ? -1 : 0;
$default = $form_state->getValue('default') ? FALSE : NULL;
$fields = [];
foreach ($form_state->getValue('table') as $field_name => $row) {
......@@ -194,7 +194,7 @@ class EventTypeDateSchedulerForm extends EntityForm {
foreach (['before', 'during', 'after'] as $time) {
$deny_registrations = !empty($row[$time]);
$field['access'][$time] = $deny_registrations ? -1 : 0;
$field['access'][$time] = $deny_registrations ? FALSE : NULL;
}
$fields[] = $field;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment