// Setup #states for all possible date_formats on the custom_date_format form element.
foreach (['custom', 'raw time ago', 'time ago', 'raw time hence', 'time hence', 'raw time span', 'time span', 'raw time span', 'inverse time span', 'time span'
] as $custom_date_possible) { $form['custom_date_format'
]['#states'
]['visible'
][] =
[ ':input[name="options[date_format]"]' =>
['value' =>
$custom_date_possible],
];
} $form['timezone'
] =
[ '#type' => 'select',
'#title' =>
$this->
t('Timezone'
),
'#description' =>
$this->
t('Timezone to be used for date output.'
),
'#options' =>
['' =>
$this->
t('- Default site/user timezone -'
)] + TimeZoneFormHelper::
getOptionsListByRegion(),
'#default_value' =>
$this->options
['timezone'
],
];
foreach (array_merge(['custom'
],
array_keys($date_formats)) as $timezone_date_formats) { $form['timezone'
]['#states'
]['visible'
][] =
[ ':input[name="options[date_format]"]' =>
['value' =>
$timezone_date_formats],
];
} parent::
buildOptionsForm($form,
$form_state);
}