public function FullCalendar::getExposedDates in FullCalendar 8.4
Same name and namespace in other branches
- 8.5 src/Plugin/views/style/FullCalendar.php \Drupal\fullcalendar\Plugin\views\style\FullCalendar::getExposedDates()
- 8 src/Plugin/views/style/FullCalendar.php \Drupal\fullcalendar\Plugin\views\style\FullCalendar::getExposedDates()
- 8.2 src/Plugin/views/style/FullCalendar.php \Drupal\fullcalendar\Plugin\views\style\FullCalendar::getExposedDates()
- 8.3 src/Plugin/views/style/FullCalendar.php \Drupal\fullcalendar\Plugin\views\style\FullCalendar::getExposedDates()
Get 'min' and 'max' dates appear in the calendar.
Parameters
string $field_name: Field machine name.
Return value
mixed
Throws
\Exception
1 call to FullCalendar::getExposedDates()
- FullCalendar::prepareEvents in src/
Plugin/ views/ style/ FullCalendar.php - Prepare events for calendar.
File
- src/
Plugin/ views/ style/ FullCalendar.php, line 489
Class
- FullCalendar
- Plugin annotation @ViewsStyle( id = "fullcalendar", title = @Translation("FullCalendar"), help = @Translation("Displays items on a calendar."), theme = "views_view--fullcalendar", display_types = {"normal"} )
Namespace
Drupal\fullcalendar\Plugin\views\styleCode
public function getExposedDates($field_name) {
$dates =& drupal_static(__METHOD__, []);
if (empty($dates[$field_name])) {
$entity_type = $this->view
->getBaseEntityType();
$entity_type_id = $entity_type
->id();
$settings = $this->view->style_plugin->options;
/** @var \Drupal\Core\Entity\EntityFieldManagerInterface $field_manager */
$field_manager = \Drupal::getContainer()
->get('entity_field.manager');
/** @var \Drupal\Core\Field\FieldStorageDefinitionInterface[] $field_storages */
$field_storages = $field_manager
->getFieldStorageDefinitions($entity_type_id);
/** @var \Drupal\Core\Field\FieldStorageDefinitionInterface $field_storage */
$field_storage = $field_storages[$field_name];
$field_value = $field_storage
->getName() . '_value';
$exposed_input = $this->view
->getExposedInput();
// Min and Max dates for exposed filter.
$dateMin = new DateTime();
$dateMax = new DateTime();
// First, we try to set initial Min and Max date values based on the
// exposed form values.
if (isset($exposed_input[$field_value])) {
$dateMin
->setTimestamp(strtotime($exposed_input[$field_value]['min']));
$dateMax
->setTimestamp(strtotime($exposed_input[$field_value]['max']));
}
elseif (!empty($settings['date']['month']) && !empty($settings['date']['year'])) {
$ts = mktime(0, 0, 0, $settings['date']['month'] + 1, 1, $settings['date']['year']);
$dateMin
->setTimestamp($ts);
$dateMax
->setTimestamp($ts);
$dateMin
->modify('first day of this month');
$dateMax
->modify('first day of next month');
}
else {
$dateMin
->modify('first day of this month');
$dateMax
->modify('first day of next month');
}
$dates[$field_name] = [
'min' => $dateMin,
'max' => $dateMax,
];
}
return $dates[$field_name];
}