public function HideDateTime::access in Field Formatter Condition 8
Access control function.
Parameters
array $build: The current build array.
string $field: The current field name.
array $settings: The current settings array.
Overrides FieldFormatterConditionBase::access
File
- src/
Plugin/ Field/ FieldFormatter/ Condition/ HideDateTime.php, line 49
Class
- HideDateTime
- The plugin for check empty fields.
Namespace
Drupal\fico\Plugin\Field\FieldFormatter\ConditionCode
public function access(&$build, $field, $settings) {
$custom_date = strtotime($settings['settings']['cutom_date']);
if (!empty($build[$field]['#items'])) {
foreach ($build[$field]['#items'] as $item) {
$info = $item
->getValue($field);
switch ($settings['settings']['orientation']) {
case 'smaller':
if (strtotime($info['value']) < REQUEST_TIME) {
$build[$field]['#access'] = FALSE;
}
break;
case 'greater':
if (strtotime($info['value']) > REQUEST_TIME) {
$build[$field]['#access'] = FALSE;
}
break;
case 'custom_small':
if (strtotime($info['value']) < $custom_date) {
$build[$field]['#access'] = FALSE;
}
break;
case 'greater_small':
if (strtotime($info['value']) > $custom_date) {
$build[$field]['#access'] = FALSE;
}
break;
default:
$build[$field]['#access'] = FALSE;
}
}
}
if (empty($build[$field]['#items'])) {
$build[$field]['#access'] = FALSE;
}
}