You are here

public function FullcalendarLegendBase::build in FullCalendar 8.3

Same name and namespace in other branches
  1. 8.5 modules/fullcalendar_legend/src/Plugin/block/FullcalendarLegendBase.php \Drupal\fullcalendar_legend\Plugin\Block\FullcalendarLegendBase::build()
  2. 8 fullcalendar_legend/src/Plugin/block/FullcalendarLegendBase.php \Drupal\fullcalendar_legend\Plugin\Block\FullcalendarLegendBase::build()
  3. 8.2 modules/fullcalendar_legend/src/Plugin/block/FullcalendarLegendBase.php \Drupal\fullcalendar_legend\Plugin\Block\FullcalendarLegendBase::build()
  4. 8.4 modules/fullcalendar_legend/src/Plugin/block/FullcalendarLegendBase.php \Drupal\fullcalendar_legend\Plugin\Block\FullcalendarLegendBase::build()

Builds and returns the renderable array for this block plugin.

If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).

Return value

array A renderable array representing the content of the block.

Overrides BlockPluginInterface::build

See also

\Drupal\block\BlockViewBuilder

File

fullcalendar_legend/src/Plugin/block/FullcalendarLegendBase.php, line 21
Contains \Drupal\fullcalendar_legend\Plugin\Block\FullcalendarLegendBase.

Class

FullcalendarLegendBase
Provides a generic FullCalendar Legend block.

Namespace

Drupal\fullcalendar_legend\Plugin\Block

Code

public function build() {
  $view_id = \Drupal::routeMatch()
    ->getParameter('view_id');
  $view = Views::getView($view_id);
  if (empty($view)) {
    return NULL;
  }
  $style = $view->display_handler
    ->getOption('style');
  if ($style['type'] != 'fullcalendar') {
    return NULL;
  }
  $fields = [];
  $fieldManager = \Drupal::getContainer()
    ->get('entity_field.manager');

  /** @var \Drupal\views\Plugin\views\field\EntityField $field */
  foreach ($view->field as $field_name => $field) {
    if (fullcalendar_field_is_date($field)) {
      $field_storage_definitions = $fieldManager
        ->getFieldStorageDefinitions($field->definition['entity_type']);
      $field_definition = $field_storage_definitions[$field->definition['field_name']];
      $fields[$field_name] = $field_definition;
    }
  }
  return [
    '#theme' => 'fullcalendar_legend',
    '#types' => $this
      ->buildLegend($fields),
  ];
}