OfficeHoursFormatterStatus.php in Office Hours 8
File
src/Plugin/Field/FieldFormatter/OfficeHoursFormatterStatus.php
View source
<?php
namespace Drupal\office_hours\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
class OfficeHoursFormatterStatus extends OfficeHoursFormatterBase {
public function settingsForm(array $form, FormStateInterface $form_state) {
$element = parent::settingsForm($form, $form_state);
$element_save = $element['current_status'];
$element = [];
$element['current_status'] = $element_save;
$element['current_status']['#type'] = 'fieldset';
$element['current_status']['position']['#type'] = 'hidden';
return $element;
}
public function settingsSummary() {
$summary[] = $this
->t("Display only 'Closed'/'Opened' text.");
return $summary;
}
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
$settings = $this
->getSettings();
$this
->setSetting('show_closed', 'next');
$elements += [
'#theme' => 'office_hours_status',
'#is_open' => $items
->isOpen(),
'#open_text' => (string) $this
->t($settings['current_status']['open_text']),
'#closed_text' => (string) $this
->t($settings['current_status']['closed_text']),
'#position' => $this->settings['current_status']['position'],
'#cache' => [
'max-age' => $this
->getStatusTimeLeft($items, $langcode),
'tags' => [
'office_hours:field.status',
],
],
];
return $elements;
}
}