CalendarLegend.php in Calendar 8
File
src/Plugin/Block/CalendarLegend.php
View source
<?php
namespace Drupal\calendar\Plugin\Block;
use Drupal\calendar\CalendarHelper;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Form\FormStateInterface;
class CalendarLegend extends BlockBase implements BlockPluginInterface {
public function blockForm($form, FormStateInterface $form_state) {
$options = CalendarHelper::listCalendarViews();
$config = $this
->getConfiguration();
$form['calendar_legend_view'] = [
'#type' => 'select',
'#title' => $this
->t('Legend View'),
'#description' => $this
->t('Choose the view display that contains the settings for the stripes that should be displayed in a legend in this block. Note that if you change the stripe values in that view you will need to clear the cache to pick up the new values in this block.'),
'#default_value' => isset($config['calendar_legend_view_settings_view']) ? $config['calendar_legend_view_settings_view'] : '',
'#options' => $options,
];
return $form;
}
public function blockSubmit($form, FormStateInterface $form_state) {
$this
->setConfigurationValue('calendar_legend_view_settings_view', $form_state
->getValue('calendar_legend_view'));
$this
->messenger()
->addMessage($this
->t('The view for the calendar legend has been set.'));
}
public function build() {
$config = $this
->getConfiguration();
$view_and_display_id = $config['calendar_legend_view_settings_view'];
return [
'#theme' => 'calendar_stripe_legend',
'#view_and_display_id' => $view_and_display_id,
'#title' => $this
->t('Calendar Legend'),
];
}
}